mirror of
https://github.com/containers/podman.git
synced 2025-05-17 06:59:07 +08:00
libpod/events: refactor to eliminate unused code
Shuffle the code around to eliminate "unused" warnings when linting with various GOOS and build tags. The only change in functionality should be that now NewEventer returns ErrNoJournaldLogging (rather than "unknown event logger type") on freebsd when journald is requested. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
6
libpod/events/default_journal.go
Normal file
6
libpod/events/default_journal.go
Normal file
@ -0,0 +1,6 @@
|
||||
//go:build systemd && linux
|
||||
|
||||
package events
|
||||
|
||||
// DefaultEventerType is journald when systemd is available.
|
||||
const DefaultEventerType = Journald
|
7
libpod/events/default_logfile.go
Normal file
7
libpod/events/default_logfile.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build !systemd || !linux
|
||||
|
||||
package events
|
||||
|
||||
// DefaultEventerType is logfile when systemd is not present
|
||||
// or not supported.
|
||||
const DefaultEventerType = LogFile
|
@ -98,16 +98,6 @@ func (e *Event) ToHumanReadable(truncate bool) string {
|
||||
return humanFormat
|
||||
}
|
||||
|
||||
// newEventFromJSONString takes stringified json and converts
|
||||
// it to an event
|
||||
func newEventFromJSONString(event string) (*Event, error) {
|
||||
e := new(Event)
|
||||
if err := json.Unmarshal([]byte(event), e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// String converts a Type to a string
|
||||
func (t Type) String() string {
|
||||
return string(t)
|
||||
|
@ -1,21 +0,0 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NewEventer creates an eventer based on the eventer type
|
||||
func NewEventer(options EventerOptions) (Eventer, error) {
|
||||
logrus.Debugf("Initializing event backend %s", options.EventerType)
|
||||
switch EventerType(strings.ToLower(options.EventerType)) {
|
||||
case LogFile:
|
||||
return EventLogFile{options}, nil
|
||||
case Null:
|
||||
return newNullEventer(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown event logger type: %s", strings.ToLower(options.EventerType))
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
//go:build linux || freebsd
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -21,3 +24,19 @@ func NewEventer(options EventerOptions) (Eventer, error) {
|
||||
return nil, fmt.Errorf("unknown event logger type: %s", strings.ToLower(options.EventerType))
|
||||
}
|
||||
}
|
||||
|
||||
// newEventFromJSONString takes stringified json and converts
|
||||
// it to an event
|
||||
func newEventFromJSONString(event string) (*Event, error) {
|
||||
e := new(Event)
|
||||
if err := json.Unmarshal([]byte(event), e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// newNullEventer returns a new null eventer. You should only do this for
|
||||
// the purposes of internal libpod testing.
|
||||
func newNullEventer() Eventer {
|
||||
return EventToNull{}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
//go:build linux || freebsd
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
@ -17,9 +17,6 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// DefaultEventerType is journald when systemd is available
|
||||
const DefaultEventerType = Journald
|
||||
|
||||
// EventJournalD is the journald implementation of an eventer
|
||||
type EventJournalD struct {
|
||||
options EventerOptions
|
||||
|
@ -1,10 +1,7 @@
|
||||
//go:build !systemd
|
||||
//go:build (linux && !systemd) || freebsd
|
||||
|
||||
package events
|
||||
|
||||
// DefaultEventerType is logfile when systemd is not present
|
||||
const DefaultEventerType = LogFile
|
||||
|
||||
// newJournalDEventer always returns an error if libsystemd not found
|
||||
func newJournalDEventer(options EventerOptions) (Eventer, error) {
|
||||
return nil, ErrNoJournaldLogging
|
||||
|
@ -19,12 +19,6 @@ func (e EventToNull) Read(ctx context.Context, options ReadOptions) error {
|
||||
return errors.New("cannot read events with the \"none\" backend")
|
||||
}
|
||||
|
||||
// newNullEventer returns a new null eventer. You should only do this for
|
||||
// the purposes of internal libpod testing.
|
||||
func newNullEventer() Eventer {
|
||||
return EventToNull{}
|
||||
}
|
||||
|
||||
// String returns a string representation of the logger
|
||||
func (e EventToNull) String() string {
|
||||
return "none"
|
||||
|
Reference in New Issue
Block a user