aboutsummaryrefslogtreecommitdiff
path: root/pkg/server/handler.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@rgdd.se>2023-12-31 09:39:25 +0100
committerRasmus Dahlberg <rasmus@rgdd.se>2024-01-07 20:22:23 +0100
commite18d36ebae30536c77c61cd5da123991e0ca1629 (patch)
treebf4880c0019a6009ab1b671e23ef4a1a4a5e8e08 /pkg/server/handler.go
parent54d980afcbd6f0011d6a162e0003587d26a3e311 (diff)
Add drafty prototype
Diffstat (limited to 'pkg/server/handler.go')
-rw-r--r--pkg/server/handler.go32
1 files changed, 0 insertions, 32 deletions
diff --git a/pkg/server/handler.go b/pkg/server/handler.go
deleted file mode 100644
index 6d17af7..0000000
--- a/pkg/server/handler.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package server
-
-import (
- "fmt"
- "net/http"
-)
-
-// handler implements the http.Handler interface
-type handler struct {
- method string
- endpoint string
- callback func(w http.ResponseWriter, r *http.Request) (int, string)
-}
-
-func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
- w.Header().Set("Cache-Control", "no-cache")
- if r.Method != h.method {
- http.Error(w, "Invalid HTTP method, expected "+h.method, http.StatusMethodNotAllowed)
- return
- }
- code, text := h.callback(w, r)
- if code != http.StatusOK {
- http.Error(w, text, code)
- return
- }
- fmt.Fprintf(w, fmt.Sprintf("%s\n", text))
-}
-
-func (h handler) register(mux *http.ServeMux) {
- mux.Handle("/"+h.endpoint, h)
-}