🔨 switch fiber to gin

This commit is contained in:
微凉
2021-11-13 15:53:26 +08:00
parent 65ec4e3611
commit cf07b3921c
22 changed files with 320 additions and 252 deletions

31
server/static.go Normal file
View File

@ -0,0 +1,31 @@
package server
import (
"github.com/Xhofe/alist/public"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"io/fs"
"io/ioutil"
"net/http"
)
var data []byte
func init() {
index, _ := public.Public.Open("index.html")
data, _ = ioutil.ReadAll(index)
}
func Static(r *gin.Engine) {
assets, err := fs.Sub(public.Public, "assets")
if err != nil {
log.Fatalf("can't find assets folder")
}
r.StaticFS("/assets/", http.FS(assets))
r.NoRoute(func(c *gin.Context) {
c.Status(200)
c.Header("Content-Type", "text/html")
_, _ = c.Writer.Write(data)
c.Writer.Flush()
})
}