summaryrefslogtreecommitdiff
path: root/handlers.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2026-06-21 10:49:11 +0200
committerxengineering <me@xengineering.eu>2026-06-21 10:49:11 +0200
commit2dc210a7ee7272f241f6d159ccca01c4da4228d2 (patch)
tree3e8f10c0da7321146453d22a9d741dc98f28d675 /handlers.go
parentb4950dfa73802afb63009f3ef501463baf5c30e2 (diff)
downloadfinserv-2dc210a7ee7272f241f6d159ccca01c4da4228d2.tar
finserv-2dc210a7ee7272f241f6d159ccca01c4da4228d2.tar.zst
finserv-2dc210a7ee7272f241f6d159ccca01c4da4228d2.zip
Do not use init for HTTP handler registration
This does not allow to use a *sql.DB which is initialized in main() inside to pass it to handlers with DB access.
Diffstat (limited to 'handlers.go')
-rw-r--r--handlers.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/handlers.go b/handlers.go
index 141230d..d28a491 100644
--- a/handlers.go
+++ b/handlers.go
@@ -6,20 +6,22 @@ import (
"io/fs"
"log"
"net/http"
+
+ "github.com/gorilla/mux"
)
//go:embed build/frontend/public
var frontendEmbed embed.FS
-func init() {
- router.HandleFunc("/api/version", version)
+func registerHandlers(r *mux.Router) {
+ r.HandleFunc("/api/version", version)
// frontend must come last to make sure /api takes precedence
frontend, err := fs.Sub(frontendEmbed, "build/frontend/public")
if err != nil {
log.Fatalf("No embedded frontend: %v.", err)
}
- router.PathPrefix("/").Handler(http.FileServerFS(frontend))
+ r.PathPrefix("/").Handler(http.FileServerFS(frontend))
}
func version(w http.ResponseWriter, r *http.Request) {