From 48a99c6514fbc418b10084504d630aaa94491aff Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 25 Jan 2024 12:05:40 +0100 Subject: [PATCH] domain: move Event to types sub-package Signed-off-by: Giuseppe Scrivano --- pkg/bindings/system/system.go | 5 +++-- pkg/domain/entities/events.go | 18 ++++++------------ pkg/domain/entities/types/events.go | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 pkg/domain/entities/types/events.go diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go index 733b2cb5c3..b17f16be11 100644 --- a/pkg/bindings/system/system.go +++ b/pkg/bindings/system/system.go @@ -12,13 +12,14 @@ import ( "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/sirupsen/logrus" ) // Events allows you to monitor libdpod related events like container creation and // removal. The events are then passed to the eventChan provided. The optional cancelChan // can be used to cancel the read of events and close down the HTTP connection. -func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, options *EventsOptions) error { +func Events(ctx context.Context, eventChan chan types.Event, cancelChan chan bool, options *EventsOptions) error { conn, err := bindings.GetClient(ctx) if err != nil { return err @@ -44,7 +45,7 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan dec := json.NewDecoder(response.Body) for err = (error)(nil); err == nil; { - var e = entities.Event{} + var e = types.Event{} err = dec.Decode(&e) if err == nil { eventChan <- e diff --git a/pkg/domain/entities/events.go b/pkg/domain/entities/events.go index 6e635d78ac..f1b4e0c90e 100644 --- a/pkg/domain/entities/events.go +++ b/pkg/domain/entities/events.go @@ -5,17 +5,11 @@ import ( "time" libpodEvents "github.com/containers/podman/v4/libpod/events" + types "github.com/containers/podman/v4/pkg/domain/entities/types" dockerEvents "github.com/docker/docker/api/types/events" ) -// Event combines various event-related data such as time, event type, status -// and more. -type Event struct { - // TODO: it would be nice to have full control over the types at some - // point and fork such Docker types. - dockerEvents.Message - HealthStatus string `json:",omitempty"` -} +type Event = types.Event // ConvertToLibpodEvent converts an entities event to a libpod one. func ConvertToLibpodEvent(e Event) *libpodEvents.Event { @@ -59,7 +53,7 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event { } // ConvertToEntitiesEvent converts a libpod event to an entities one. -func ConvertToEntitiesEvent(e libpodEvents.Event) *Event { +func ConvertToEntitiesEvent(e libpodEvents.Event) *types.Event { attributes := e.Details.Attributes if attributes == nil { attributes = make(map[string]string) @@ -85,8 +79,8 @@ func ConvertToEntitiesEvent(e libpodEvents.Event) *Event { Time: e.Time.Unix(), TimeNano: e.Time.UnixNano(), } - return &Event{ - message, - e.HealthStatus, + return &types.Event{ + Message: message, + HealthStatus: e.HealthStatus, } } diff --git a/pkg/domain/entities/types/events.go b/pkg/domain/entities/types/events.go new file mode 100644 index 0000000000..a9e9dd6a1b --- /dev/null +++ b/pkg/domain/entities/types/events.go @@ -0,0 +1,14 @@ +package types + +import ( + dockerEvents "github.com/docker/docker/api/types/events" +) + +// Event combines various event-related data such as time, event type, status +// and more. +type Event struct { + // TODO: it would be nice to have full control over the types at some + // point and fork such Docker types. + dockerEvents.Message + HealthStatus string `json:",omitempty"` +}