gohttp/admin/admin.go

41 lines
756 B
Go
Raw Normal View History

2023-12-07 00:22:53 +08:00
package admin
import (
"net/http"
2023-12-07 22:42:27 +08:00
"git.pyer.club/kingecg/gohttpd/server"
2023-12-07 00:22:53 +08:00
)
type Route struct {
Method string
Path string
Handle http.HandlerFunc
}
func about(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("About Page"))
}
2023-12-11 18:15:29 +08:00
func setConfig(w http.ResponseWriter, r *http.Request) {
}
2023-12-07 00:22:53 +08:00
var AdminRoutes = []Route{
// Admin Routes
{"GET", "/about", about},
2023-12-11 18:15:29 +08:00
{"Post", "/config", setConfig},
2023-12-07 00:22:53 +08:00
}
2023-12-07 22:42:27 +08:00
var AdminServerMux *server.RestMux
2023-12-07 00:22:53 +08:00
func init() {
2023-12-08 22:02:36 +08:00
AdminServerMux = server.NewRestMux("/")
2023-12-07 00:22:53 +08:00
// AdminServerMux.routes = make(map[string]map[string]http.HandlerFunc)
for _, route := range AdminRoutes {
2023-12-07 22:42:27 +08:00
AdminServerMux.HandleFunc(route.Method, route.Path, route.Handle)
2023-12-07 00:22:53 +08:00
}
2023-12-11 18:15:29 +08:00
AdminServerMux.Use(server.BasicAuth)
2023-12-07 00:22:53 +08:00
}