From 277de43a0212e8efc901d0e2d2d390bad63842f9 Mon Sep 17 00:00:00 2001 From: David Allen Date: Sun, 31 Aug 2025 22:04:02 -0600 Subject: [PATCH] feat: added Init() and Cleanup() in hooks --- internal/archive/archive.go | 8 ++++++++ pkg/service/routes.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/archive/archive.go b/internal/archive/archive.go index eaf6412..4fadf22 100644 --- a/internal/archive/archive.go +++ b/internal/archive/archive.go @@ -133,10 +133,18 @@ func addToArchive(tw *tar.Writer, filename string, hooks []makeshift.Hook) error } hook.Data.Set("file", contents) + err = hook.Init() + if err != nil { + return err + } err = hook.Run() if err != nil { return err } + err = hook.Cleanup() + if err != nil { + return err + } // create temporary file to use to add to archive hook = hooks[len(hooks)-1] diff --git a/pkg/service/routes.go b/pkg/service/routes.go index d63201d..7d371c9 100644 --- a/pkg/service/routes.go +++ b/pkg/service/routes.go @@ -142,6 +142,14 @@ func (s *Service) Download() http.HandlerFunc { "version": hook.Plugin.Version(), }, }).Send() + err = hook.Init() + if err != nil { + log.Error(). + Err(err). + Str("plugin", hook.Plugin.Name()). + Msg("failed to initialize plugin") + continue + } err = hook.Run() if err != nil { log.Error(). @@ -150,6 +158,14 @@ func (s *Service) Download() http.HandlerFunc { Msg("failed to run plugin") continue } + err = hook.Cleanup() + if err != nil { + log.Error(). + Err(err). + Str("plugin", hook.Plugin.Name()). + Msg("failed to cleanup plugin") + continue + } } // take the contents from the last hook and update files