move debughandlers to their own package

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-03-22 13:59:54 +01:00
parent 6c00708dbc
commit 86980441fe
3 changed files with 40 additions and 32 deletions

View File

@@ -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)
}
}

View File

@@ -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) {

View File

@@ -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)