Files

50 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-10-09 12:27:54 +02:00
package debug
import (
2024-10-09 13:50:33 +02:00
"context"
2024-10-14 16:19:28 +02:00
"errors"
2024-10-09 12:27:54 +02:00
"net/http"
"net/url"
2024-10-09 12:27:54 +02:00
"github.com/dutchcoders/go-clamd"
"github.com/owncloud/ocis/v2/ocis-pkg/checks"
2024-10-09 12:27:54 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
)
// Server initializes the debug service and server.
func Server(opts ...Option) (*http.Server, error) {
options := newOptions(opts...)
readyHandlerConfiguration := handlers.NewCheckHandlerConfiguration().
WithLogger(options.Logger).
2024-10-18 17:30:39 +02:00
WithCheck("nats reachability", checks.NewNatsCheck(options.Config.Events.Endpoint)).
WithCheck("antivirus reachability", func(ctx context.Context) error {
cfg := options.Config
switch cfg.Scanner.Type {
default:
return errors.New("no antivirus configured")
case "clamav":
return clamd.NewClamd(cfg.Scanner.ClamAV.Socket).Ping()
case "icap":
u, err := url.Parse(cfg.Scanner.ICAP.URL)
if err != nil {
return err
}
return checks.NewTCPCheck(u.Host)(ctx)
}
})
2024-10-09 12:27:54 +02:00
return debug.NewService(
debug.Logger(options.Logger),
debug.Name(options.Config.Service.Name),
debug.Version(version.GetString()),
debug.Address(options.Config.Debug.Addr),
debug.Token(options.Config.Debug.Token),
debug.Pprof(options.Config.Debug.Pprof),
debug.Zpages(options.Config.Debug.Zpages),
debug.Ready(handlers.NewCheckHandler(readyHandlerConfiguration)),
2024-10-09 12:27:54 +02:00
), nil
}