mirror of https://github.com/containers/podman.git
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:
parent
91113c46ef
commit
6b1033eaa0
|
@ -0,0 +1,6 @@
|
||||||
|
//go:build systemd && linux
|
||||||
|
|
||||||
|
package events
|
||||||
|
|
||||||
|
// DefaultEventerType is journald when systemd is available.
|
||||||
|
const DefaultEventerType = Journald
|
|
@ -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
|
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
|
// String converts a Type to a string
|
||||||
func (t Type) String() string {
|
func (t Type) String() string {
|
||||||
return string(t)
|
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
|
package events
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -21,3 +24,19 @@ func NewEventer(options EventerOptions) (Eventer, error) {
|
||||||
return nil, fmt.Errorf("unknown event logger type: %s", strings.ToLower(options.EventerType))
|
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
|
package events
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -17,9 +17,6 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultEventerType is journald when systemd is available
|
|
||||||
const DefaultEventerType = Journald
|
|
||||||
|
|
||||||
// EventJournalD is the journald implementation of an eventer
|
// EventJournalD is the journald implementation of an eventer
|
||||||
type EventJournalD struct {
|
type EventJournalD struct {
|
||||||
options EventerOptions
|
options EventerOptions
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
//go:build !systemd
|
//go:build (linux && !systemd) || freebsd
|
||||||
|
|
||||||
package events
|
package events
|
||||||
|
|
||||||
// DefaultEventerType is logfile when systemd is not present
|
|
||||||
const DefaultEventerType = LogFile
|
|
||||||
|
|
||||||
// newJournalDEventer always returns an error if libsystemd not found
|
// newJournalDEventer always returns an error if libsystemd not found
|
||||||
func newJournalDEventer(options EventerOptions) (Eventer, error) {
|
func newJournalDEventer(options EventerOptions) (Eventer, error) {
|
||||||
return nil, ErrNoJournaldLogging
|
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")
|
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
|
// String returns a string representation of the logger
|
||||||
func (e EventToNull) String() string {
|
func (e EventToNull) String() string {
|
||||||
return "none"
|
return "none"
|
||||||
|
|
Loading…
Reference in New Issue