diff --git a/pkg/hook/builder.go b/pkg/hook/builder.go index f4e4d2b0..cafc5c3a 100644 --- a/pkg/hook/builder.go +++ b/pkg/hook/builder.go @@ -1,18 +1,16 @@ package hook -type ( - // Builder builds a new Hooks. - Builder []func(*Hook) error -) +// Builder builds a new Hooks. +type Builder []func(*Hook) error // NewBuilder returns a new HooksBuilder. func NewBuilder(funcs ...func(*Hook) error) Builder { return Builder(funcs) } -// AddToHooks adds all registered hook to s. -func (b *Builder) AddToHooks(h *Hook) error { - for _, f := range *b { +// AddToHooks adds all registered hooks to h. +func (b Builder) AddToHooks(h *Hook) error { + for _, f := range b { if err := f(h); err != nil { return err } @@ -20,13 +18,13 @@ func (b *Builder) AddToHooks(h *Hook) error { return nil } -// Register adds one or more hook. +// Register adds one or more hooks. func (b *Builder) Register(funcs ...func(*Hook) error) { *b = append(*b, funcs...) } // Build returns a new Hooks containing the registered hooks. -func (b *Builder) Build() (*Hook, error) { +func (b Builder) Build() (*Hook, error) { h := New() if err := b.AddToHooks(h); err != nil { return nil, err diff --git a/pkg/hook/hook.go b/pkg/hook/hook.go index aabf50ea..95b7654e 100644 --- a/pkg/hook/hook.go +++ b/pkg/hook/hook.go @@ -7,24 +7,22 @@ import ( "github.com/siyul-park/uniflow/pkg/symbol" ) -type ( - // Hook is a collection of hook functions. - Hook struct { - loadHooks []symbol.LoadHook - unloadHooks []symbol.UnloadHook - mu sync.RWMutex - } -) +// Hook is a collection of hook functions for loading and unloading nodes. +type Hook struct { + loadHooks []symbol.LoadHook + unloadHooks []symbol.UnloadHook + mu sync.RWMutex +} var _ symbol.LoadHook = &Hook{} var _ symbol.UnloadHook = &Hook{} -// New returns a new Hooks. +// New creates a new Hook instance. func New() *Hook { return &Hook{} } -// AddLoadHook adds a LoadHook. +// AddLoadHook adds a LoadHook function to the Hook. func (h *Hook) AddLoadHook(hook symbol.LoadHook) { h.mu.Lock() defer h.mu.Unlock() @@ -32,7 +30,7 @@ func (h *Hook) AddLoadHook(hook symbol.LoadHook) { h.loadHooks = append(h.loadHooks, hook) } -// AddUnloadHook adds a UnloadHook. +// AddUnloadHook adds an UnloadHook function to the Hook. func (h *Hook) AddUnloadHook(hook symbol.UnloadHook) { h.mu.Lock() defer h.mu.Unlock() @@ -40,7 +38,7 @@ func (h *Hook) AddUnloadHook(hook symbol.UnloadHook) { h.unloadHooks = append(h.unloadHooks, hook) } -// Load runs LoadHooks. +// Load executes LoadHooks on the provided node. func (h *Hook) Load(n node.Node) error { h.mu.RLock() defer h.mu.RUnlock() @@ -53,7 +51,7 @@ func (h *Hook) Load(n node.Node) error { return nil } -// Unload runs UnloadHooks. +// Unload executes UnloadHooks on the provided node. func (h *Hook) Unload(n node.Node) error { h.mu.RLock() defer h.mu.RUnlock()