feat(upload): add first prototype of File storage, svg database and svg processing. Also added --help command
All checks were successful
build / Go-Build (push) Successful in 1m5s
All checks were successful
build / Go-Build (push) Successful in 1m5s
This commit is contained in:
32
internal/server/http.go
Normal file
32
internal/server/http.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
routes.CreateSVG(w, *r)
|
||||
})
|
||||
}
|
||||
|
||||
func Start() {
|
||||
log.Println("Starting http server on :3000")
|
||||
http.ListenAndServe(":3000", nil)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user