add Stop function to module

This commit is contained in:
Joel Wetzell
2026-02-07 09:53:38 -06:00
parent 8f5091cf9b
commit 33ecc94097
19 changed files with 156 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ type HTTPServer struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
type ResponseIOError struct {
@@ -153,7 +154,9 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
return errors.New("http.server unable to get router from context")
}
hs.router = router
hs.ctx = ctx
moduleContext, cancel := context.WithCancel(ctx)
hs.ctx = moduleContext
hs.cancel = cancel
httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", hs.Port),
@@ -199,3 +202,7 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error {
responseWriter.Write(payloadResponse.Body)
return nil
}
func (hs *HTTPServer) Stop() {
hs.cancel()
}