generated from bing/readnotes
49 lines
6.6 KiB
Go
49 lines
6.6 KiB
Go
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.StaticFS("/SC", http.Dir(dir + "/SC"))
|
|
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+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UGf//lRn//5UZ//+VGf//lRn//5QZ//+UGP//lBj//5QZ//+UGf//lRn//5UZ//+VGf//lRn//5UZ//+UGf//lRn//5UZ//+SFP//oje4/8WCAP/EfgD/wXgA/963AP/hvAD/xoUA/8mJAP/JiQD/yYkA/8yQAP+uUIb/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/6xMlv+aJd7/khX//5ES//+TF///lBn//5IU//+hNK3/y44A///+AP///wD///8A////AP///wD///8A/7FXuv+PDv//lBn//5QY//+SFP//6c44//77AP/IhwD/xIAA/8J8AP/fuQD/58kA/6tKj/+oRLr/3LMA/8eFAP/KiwD/zpUA/71wC/+4ZUf/q0qY/5kk4P+SFf//jw7//6E0rP/LjgD///4A////AP///wD///8A////AP/u2Sr/lBn7/5MX//+UGf//kxf//5cg+f/16B3//PcA/8J7AP++cwD/vG8A/9yyAP/kxAD/tmJY/8eGQv/csgD/z5YA/8eGAP/LjgD/vnIA/8iIAP/NkQD/u2wM/7hlSf+nQqD/qEOL/86UAP///wD///8A////AP///wD///8A/8WBi/+NC///lRn//5QZ//+TF///lRz3/+3VL////wD/3rcA/9yyAP/bsAD/7NUA/+/cAP/guwf/5MQB/+XGAP/hvQD/zJAA/8qNAP++cQD/xoMA/8qLAP+8bgD/yYoA/8iJAP/NkgL/69EA//DdAP/s1QD/6M0A/+rQAP/lxQ//ni3m/5IU//+VGf//lBn//5UZ//+REv//pDzU/+zVE//x3gD/7dcA/+3VAP/16QD/9uoA/+7ZAP/u2gD/79oA/+rSAP/OlAD/yowA/75xAP/GggD/yosA/7xtAP/HhAD/xoQA/82SAP/oywD/4sAA/9qvAP/arQD/3bUA/8J6U/+PD///khP//5MW//+TGf//lRn//5Ua//+ODf//qke4/+zUBP/t1wD/6tEA//TnAP/16AD/7NUA/+3XAP/u2AD/6c8A/86UAP/KjQD/vnEA/8aCAP/KiwD/vG0A/8eFAP/GhAD/zZIA/+jMAP/ivwD/3LIA/920AP/fuQD/x4UP/6hER/+nQpj/mibg/5IW//+TFf//kxf//5QZ//+ODf//t2OW//DdAP/s1AD/9egA//XoAP/s1QD/7dcA/+7YAP/pzwD/zpQA/8qNAP++cQD/xoIA/8qLAP+8bQD/x4QA/8aDAP/NkgD/6MwA/+K/AP/cswD/3bQA/9+5AP/JigD/sVcA/8eFAP/AeAz/rlFI/6Ezmv+aJOH/kxb//5IU//+ODf//xH9y//HeAP/16AD/9egA/+zVAP/t1wD/7tgA/+nPAP/OkwD/yowA/75xAP/GggD/yooA/7xtAP/HhAD/xoMA/82RAP/ozAD/4r8A/9yyAP/dswD/37kA/8mJAP+vVAD/xH8A/8J9AP+5agD/tF4A/8N9Df+2YUj/ozmY/5cf3v+REv//y49Z//jwAP/05wD/69QA/+zWAP/t1wD/6M4A/82TAP/JjAD/vXEA/8WCAP/JigD/u20A/8aEAP/FgwD/zJEA/+fLAP/hvgD/27IA/9yzAP/euAD/yIkA/69UAP/DfwD/wXsA/7dmAP+yWgD/xoMA/8WAAP+7awD/sVcP/7JZV/+nQ57/5sgk8P////Af///wA///+AB///gAD//4AAH/+AAAP/gAAAf4AAAH/AAAD/wAAA/8AAAP/AB/z/wAH//8AQf//gGB//4DwH/4A+AfAAPgHwAD8B8AA/gfAAP4HwAD+B+AA/gfngPwH5/D8B+f++AP///gB///4Af///wD////gf////A=")
|
|
})
|
|
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)
|
|
}
|
|
} |