39 lines
945 B
Go
39 lines
945 B
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.pyer.club/kingecg/gohttpd/model"
|
|
"git.pyer.club/kingecg/gohttpd/server"
|
|
)
|
|
|
|
func about(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write([]byte("About Page"))
|
|
|
|
}
|
|
|
|
func setConfig(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
ctxData := ctx.Value(server.RequestCtxKey("ctxData")).(map[string]interface{})
|
|
data, ok := ctxData["data"]
|
|
if !ok {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
t := data.(model.HttpServerConfig)
|
|
model.SetServerConfig(&t)
|
|
|
|
}
|
|
|
|
var AdminServerMux *server.RestMux
|
|
|
|
func init() {
|
|
AdminServerMux = server.NewRestMux("/api")
|
|
AdminServerMux.Use(server.BasicAuth)
|
|
AdminServerMux.HandleFunc("GET", "/about", http.HandlerFunc(about))
|
|
postConfigRoute := AdminServerMux.HandleFunc("POST", "/config", http.HandlerFunc(setConfig))
|
|
postConfigRoute.Add(server.Parse[model.HttpServerConfig])
|
|
AdminServerMux.Use(server.BasicAuth)
|
|
}
|