diff --git a/ocis-pkg/handlers/debughandlers.go b/ocis-pkg/handlers/debughandlers.go new file mode 100644 index 0000000000..0ac3fed39a --- /dev/null +++ b/ocis-pkg/handlers/debughandlers.go @@ -0,0 +1,34 @@ +package handlers + +import ( + "io" + "net/http" +) + +// Health can be used for a health endpoint +func Health(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } +} + +// Ready can be used as a ready endpoint +func Ready(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + + // TODO: check if services are up and running + + _, err := io.WriteString(w, http.StatusText(http.StatusOK)) + // io.WriteString should not fail but if it does we want to know. + if err != nil { + panic(err) + } +} diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index c256ddb7d2..257ab6c2b7 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -3,11 +3,10 @@ package command import ( "context" "fmt" - "io" - "net/http" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" + "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -65,34 +64,8 @@ func Server(cfg *config.Config) *cli.Command { debug.Token(cfg.Debug.Token), debug.Pprof(cfg.Debug.Pprof), debug.Zpages(cfg.Debug.Zpages), - debug.Health( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does we want to know. - if err != nil { - panic(err) - } - }, - ), - debug.Ready( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.WriteHeader(http.StatusOK) - - // TODO: check if services are up and running - - _, err := io.WriteString(w, http.StatusText(http.StatusOK)) - // io.WriteString should not fail but if it does we want to know. - if err != nil { - panic(err) - } - }, - ), + debug.Health(handlers.Health), + debug.Ready(handlers.Ready), ) gr.Add(server.ListenAndServe, func(_ error) { diff --git a/services/userlog/pkg/service/conversion.go b/services/userlog/pkg/service/conversion.go index 12a7b264f8..90e9579f52 100644 --- a/services/userlog/pkg/service/conversion.go +++ b/services/userlog/pkg/service/conversion.go @@ -5,6 +5,7 @@ import ( "context" "embed" "errors" + "fmt" "io/fs" "strings" "text/template" @@ -96,11 +97,11 @@ func (c *Converter) ConvertEvent(event *ehmsg.Event) (OC10Notification, error) { switch ev := einterface.(type) { default: - return OC10Notification{}, errors.New("unknown event type") + return OC10Notification{}, fmt.Errorf("unknown event type: %T", ev) // file related case events.PostprocessingStepFinished: if ev.FinishedStep != events.PPStepAntivirus { - return OC10Notification{}, errors.New("unknown event type") + return OC10Notification{}, fmt.Errorf("unknown event type: %T", ev) } res := ev.Result.(events.VirusscanResult) return c.virusMessage(event.Id, VirusFound, ev.ExecutingUser, res.ResourceID, ev.Filename, res.Description, res.Scandate)