diff --git a/pkg/contracts/contracts.go b/pkg/contracts/contracts.go index 3fad9d07..44298677 100644 --- a/pkg/contracts/contracts.go +++ b/pkg/contracts/contracts.go @@ -54,3 +54,9 @@ type EntityFactoryFunc func() Entity type Waiter interface { Wait() error // Wait waits for execution to complete. } + +// Initer implements the Init method, +// which initializes the object in addition to zeroing. +type Initer interface { + Init() // Init initializes the object. +} diff --git a/pkg/icingadb/v1/checkable.go b/pkg/icingadb/v1/checkable.go index 0d914358..c4a7eba9 100644 --- a/pkg/icingadb/v1/checkable.go +++ b/pkg/icingadb/v1/checkable.go @@ -1,6 +1,7 @@ package v1 import ( + "github.com/icinga/icingadb/pkg/contracts" "github.com/icinga/icingadb/pkg/types" ) @@ -38,3 +39,8 @@ type Checkable struct { Zone string `json:"zone"` ZoneId types.Binary `json:"zone_id"` } + +// Assert interface compliance. +var ( + _ contracts.Initer = (*Checkable)(nil) +) diff --git a/pkg/icingadb/v1/host.go b/pkg/icingadb/v1/host.go index 067df706..dc349d93 100644 --- a/pkg/icingadb/v1/host.go +++ b/pkg/icingadb/v1/host.go @@ -49,3 +49,8 @@ func NewHost() contracts.Entity { return h } + +// Assert interface compliance. +var ( + _ contracts.Initer = (*Host)(nil) +) diff --git a/pkg/icingadb/v1/meta.go b/pkg/icingadb/v1/meta.go index b44e7756..48903fc5 100644 --- a/pkg/icingadb/v1/meta.go +++ b/pkg/icingadb/v1/meta.go @@ -51,3 +51,13 @@ type NameCiMeta struct { NameMeta NameCi *string `json:"name_ci"` } + +// Init implements the contracts.Initer interface. +func (n *NameCiMeta) Init() { + n.NameCi = &n.Name +} + +// Assert interface compliance. +var ( + _ contracts.Initer = (*NameCiMeta)(nil) +) diff --git a/pkg/icingadb/v1/service.go b/pkg/icingadb/v1/service.go index 379684d7..1c51d4f1 100644 --- a/pkg/icingadb/v1/service.go +++ b/pkg/icingadb/v1/service.go @@ -17,3 +17,8 @@ func NewService() contracts.Entity { return s } + +// Assert interface compliance. +var ( + _ contracts.Initer = (*Service)(nil) +)