Files
svg-templater/internal/server/http.go
Tueem 884ad120c9
All checks were successful
build / Go-Build (pull_request) Successful in 32s
build / Go-Build (push) Successful in 40s
fix(upload): add some logging and cleanup
2026-02-03 08:16:10 +01:00

36 lines
848 B
Go

package server
import (
"fmt"
"log"
"net/http"
"tomatentum.net/svg-templater/internal/routes"
"tomatentum.net/svg-templater/pkg/auth"
)
func PrepareHTTP() {
registerAuthorized("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "You are authorized!")
})
registerAuthorized("/svg/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
routes.CreateSVG(w, *r)
})
}
func Start() {
log.Println("Starting http server on :3000")
if err := http.ListenAndServe(":3000", nil); err != nil {
panic(err)
}
}
func registerAuthorized(path string, f func(w http.ResponseWriter, r *http.Request)) {
http.HandleFunc(path, auth.AuthMiddleware(http.HandlerFunc(f)))
log.Println("Registered authorized handler for", path)
}