blog/go/uiweb/main.go

48 lines
6.5 KiB
Go
Raw Normal View History

2023-03-13 16:17:29 +08:00
package main
import (
"flag"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
func run(dir, title, addr string)error{
engine := gin.Default()
engine.LoadHTMLGlob(dir + "/*.tmpl")
engine.Static("/ui", dir)
engine.GET("/", func(ctx *gin.Context) {
dirs, _ := os.ReadDir(dir)
files := []string{}
for _, d := range dirs {
if !d.IsDir() {
continue
}
files = append(files, d.Name())
}
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": title,
"files": files,
})
})
engine.GET("/favicon.ico", func(ctx *gin.Context) {
ctx.Header("Content-Type", "image/x-icon")
ctx.Writer.WriteString("data:image/x-icon;base64,AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAD/5sgA/9CaAP/SngD/1aMA/8N9Qv+dLMr/qklw/65RI/+9cgD/yowA/71yAP+1XwD/r1MA/8F5AP/AeAD/t2QA/7BVAP+wVgD/wnwA/7prAP+0XQD/rE0A/7ZjAP/AeAD/t2UA/7FYAP+pRwD/u20A//bsAP///wD///8A////AP/lxwD/z5gA/9KcAP/TnwD/yowi/5Ub//+SFP//lRzw/6E0tv+yWmj/uGYh/7diAP+xVwD/w3wA/8F5AP+4ZAD/sVUA/7FWAP/DfAD/u2sA/7VdAP+tTQD/t2MA/8F4AP+4ZQD/slgA/6pHAP+8bQD/9+0A////AP///wD///8A/+bJAP/RmwD/058A/9SgAP/SnAf/nSze/5IV//+UGP//khX//5IT//+WHPX/nS27/6Q7a/+8byP/wnsA/7ppAP+xVwD/sVYA/8N8AP+7awD/tV0A/61NAP+3YwD/wXgA/7hlAP+yWAD/qkcA/7xtAP/37QD///8A////AP///wD/5cUA/86UAP/QmAD/0JkA/9KdAP+lPbv/kRP//5UZ//+UGf//lRn//5QY//+TFv//kxX//5Yd9v+gMrz/qUZt/61OJP+yWQD/xYIA/7xuAP+1X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b/kRL//5QZ//+VGf//lRn//5UZ//+UGf//lhv+/5Ub9v+SE/3/khP//5ES//+REf//kBD//5AQ//+QEP//kBD//48Q//+REf//kRH//44M//+nQaL/y40A/8iHAP/FggD/4LwA/9+6AP/EfgD/xoMA/8aDAP/GgwD/yYkA/7VfW/+SFP//lBn//5UZ//+VGf//lRn//5MX//+YIeX/vnEr/8mLJ//EgDD/umlG/7hlVv+2YWb/s1p3/7FWiP+uT5j/rEyp/6pGuP+nQsf/ojfV/7pqc//UoQD/0ZsA/8+WAP/myAD/3bQA/8N+AP/GhAD/xoMA/8aDAP/IhwD/vW8z/5QZ//+UGf//lRn//5UZ//+VGf//kxf//5cf3v/hvAf/3LNW/+nOLf///wD///8A////AP///wD///8A////AP///wD///8A////AP/+/AL//fkC//LgAP/x3gD/8N0A//ftAP/bsQD/wHcA/8aEAP/HhQD/x4UA/8eHAP/DfRP/mCLv/5MX//+VGf//lRn//5UZ//+TFv//mCHc/9enAf/x3yf/ojfc/7lnoP/u2ir///8A////AP///wD///8A////AP///wD///8A////AP///wD/8uIA//HgAP/w3wD/9+4A/9yyAP+9cQD/wXkA/8N8AP/EfwD/xH8A/8R/Af+eLc//khX//5UZ//+VGf//lRn//5MW//+aJdf/yIcD////AP/q0DX/kBH//5MX+P+9cZn/7dgp////AP///wD///8A////AP///wD///8A///+AP/26gD/9ukA//XoAP/58gD/3LIA/75zAP/AdwD/wXoA/8J8AP/DfQD/xYIA/6U9qP+SFP//lRn//5UZ//+VGf//kxb//5sn0//LjQH///8A////AP/dtFL/jw///4wJ//+WHPb/vXCY/+7ZKP///wD///8A////AP///wD/+O4A/7dkAP+yWQD/tmEA/+rRAP/csgD/vnIA/8F3AP/CegD/wnsA/8R/AP/IiQD/r1J2/5ET//+VGf//lRn//5UZ//+TFv//myjP/8uNAP///wD///8A////AP/Nk3b/jgz//5MW//+OC///lh31/75yl//v2yf///8A////AP/05QD/kxgA/40KAP+KAwD/w34A/920AP/AeAD/w30A/8SAAP/DfgD/wXkF/8F4Ff+vUm3/khX//5QZ//+VGf//lRn//5IW//+cKsr/y44A////AP///wD///8A////AP++cZv/jQr//5Ua//+TFv//jQv//5ce9f++c5X/8N0n//frAP+aJgD/lBkA/5ESAP/EgAD/1KIt/6xNZv+qSIX/pT2k/6AzwP+cKdn/mCDu/5Ub+/+UGf//lBn//5UZ//+VGf//khX//5wrxv/JigD///8A////AP///wD///8A//36Bv+vUr3/jgz//5Ua//+UGf//kxb//4oD//+xV7z//PcA/791AP+7bAD/uWgA/9quAP/KjHP/jgz//5IT//+SFP//kxX//5MW//+UF///lBj//5QZ//+VGf//lRn//5UZ//+SFf//nS3B/8qLAP///wD///8A////AP///wD///8A//brFv+iN9r/kBD//5Qa//+VGf//jg3//7tspv/+/AD/yIgA/8WAAP/DfQD/37oA/9epPP+TFv7/lBn//5UZ//+VGf//lRn//5UZ//+VGf//lBn//5UZ//+VGf//lRn//5IV//+eL7z/y44A////AP///wD///8A////AP///wD///8A/+3XK/+bKOn/khX//5UZ//+OC///x4aI///9AP/GgwD/wnwA/8B4AP/etwD/4LsW/5gh6v+TF///kxX//5MW//+UGf//lRn//5UZ//+UGf//lRn//5UZ//+VGf//khX//58xt//LjgD///8A////AP///wD///8A////AP///wD///0D/6M63P+RE///lRn//44L///Tn2z///0A/8iJAP/FgQD/w34A/9+6AP/gvAH/nSzK/5ES//+gMdH/nSvY/5MV//+REv//kxb//5MZ//+VGf//lRn//5UZ//+SFf//oDKy/8uOAP///wD///8A////AP///wD///8A////AP/cs1T/jw7//5QZ//+UGf//jw7//9+4Uf/+/AD/xYEA/8F5AP+/dgD/3bYA/+PCAP+kO6r/khb//8uPJv/DfQf/umlF/6xM
})
return engine.Run(addr)
}
func main(){
var dir, title, addr string
flag.StringVar(&dir, "dir", "./", "service dir")
flag.StringVar(&title, "title", "无标题", "website title")
flag.StringVar(&addr,"addr", ":3000", "listen port")
flag.Parse()
err := run(dir, title, addr)
if err != nil {
panic(err)
}
}