From f1741a7faa9538e9b12ac60e0fbf6c7721a36059 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 9 Sep 2025 22:44:09 +0100 Subject: Initial commit --- api/router.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 api/router.go (limited to 'api/router.go') diff --git a/api/router.go b/api/router.go new file mode 100644 index 0000000..9ea7ac0 --- /dev/null +++ b/api/router.go @@ -0,0 +1,27 @@ +package api + +import ( + "net/http" + + "git.leonardobishop.net/history/api/handlers" + "git.leonardobishop.net/history/api/middleware" + "git.leonardobishop.net/history/internal/config" + "git.leonardobishop.net/history/pkg/entries" + "git.leonardobishop.net/history/pkg/html" +) + +type ApiServices struct { + EntiresService entries.Service + HtmlService html.Service + + Config config.Config +} + +func NewServer(api ApiServices) *http.ServeMux { + mux := http.NewServeMux() + + mux.HandleFunc("POST /record", middleware.Cors(handlers.RecordEntry(api.EntiresService, api.Config.Token))) + mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.HtmlService)) + + return mux +} -- cgit v1.2.3-70-g09d2