summaryrefslogtreecommitdiff
path: root/internal/daemon/daemon.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/daemon/daemon.go')
-rw-r--r--internal/daemon/daemon.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go
index 22d9f1a..b913c43 100644
--- a/internal/daemon/daemon.go
+++ b/internal/daemon/daemon.go
@@ -30,6 +30,16 @@ type Config struct {
LogOutput io.Writer
}
+// NewHandler returns HTTP handlers for daemon routes using the default auth DB
+// under statsDir. It returns an error if the auth store cannot be opened.
+func NewHandler(statsDir string) (http.Handler, error) {
+ store, err := openAuthStore(context.Background(), statsDir, "")
+ if err != nil {
+ return nil, fmt.Errorf("auth db: %w", err)
+ }
+ return routes(statsDir, "", store), nil
+}
+
func routes(statsDir, authDB string, store *authkeys.Store) http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/health", health)
@@ -40,14 +50,6 @@ func routes(statsDir, authDB string, store *authkeys.Store) http.Handler {
return mux
}
-func Handler(statsDir string) http.Handler {
- store, err := openAuthStore(context.Background(), statsDir, "")
- if err != nil {
- panic(err)
- }
- return routes(statsDir, "", store)
-}
-
func logWriter(cfg Config) io.Writer {
if cfg.LogOutput != nil {
return cfg.LogOutput