1
0
Fork 0
mirror of https://github.com/adnanh/webhook.git synced 2026-07-22 09:48:14 +00:00
webhook/admin_ui.go
jason.liao 8272126474 feat: 添加管理配置功能
默认不启用,需要通过启动参数开启
2026-04-28 10:35:11 +08:00

41 lines
881 B
Go

package main
import (
"embed"
"html/template"
"io/fs"
"net/http"
)
//go:embed adminui/index.html adminui/assets/*
var adminUIFiles embed.FS
var (
adminIndexTemplate = template.Must(template.ParseFS(adminUIFiles, "adminui/index.html"))
adminStaticFS = mustAdminSub(adminUIFiles, "adminui")
)
type adminUIData struct {
BasePath string
}
func mustAdminSub(fsys fs.FS, dir string) fs.FS {
sub, err := fs.Sub(fsys, dir)
if err != nil {
panic(err)
}
return sub
}
func adminUIHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := adminIndexTemplate.Execute(w, adminUIData{BasePath: currentAdminAuth.basePath}); err != nil {
http.Error(w, "admin UI render failed", http.StatusInternalServerError)
}
}
func adminStaticHandler() http.Handler {
return http.FileServer(http.FS(adminStaticFS))
}