Skip to content

Commit

Permalink
perf: 优化简化静态资源引入
Browse files Browse the repository at this point in the history
  • Loading branch information
v03413 committed Dec 1, 2024
1 parent 7260c60 commit 3534d85
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
go build -v -o ${{ env.BUILD_DIR }}/${{ env.APP_NAME }} -trimpath -ldflags "-s -w -buildid=" ./main
- name: Prepare package
run: |
cp -v -R ./templates ./${{ env.BUILD_DIR }}
cp -v -R ./static ./${{ env.BUILD_DIR }}
cp -v ./docs/${{ env.APP_NAME }}.service ./${{ env.BUILD_DIR }}
cp -v ./docs/Environment.conf ./${{ env.BUILD_DIR }}
mv -v ./${{ env.BUILD_DIR }} ./${{ env.APP_NAME }}
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ ENV TZ=Asia/Shanghai
RUN apk add --no-cache tzdata ca-certificates

COPY --from=builder /go/release/bepusdt /runtime/bepusdt
ADD ./templates /runtime/templates
ADD ./static /runtime/static

# 设置时区
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Expand Down
2 changes: 1 addition & 1 deletion app/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app

// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
const Version = "1.13.32"
const Version = "1.13.33"
23 changes: 19 additions & 4 deletions app/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ import (
"github.com/v03413/bepusdt/app/config"
"github.com/v03413/bepusdt/app/help"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/static"
"html/template"
"io/fs"
"net/http"
)

func Start() {
gin.SetMode(gin.ReleaseMode)

listen := config.GetListen()
r := gin.New()
r.Static("/img", config.GetStaticPath()+"img")
r.Static("/css", config.GetStaticPath()+"css")
r.Static("/js", config.GetStaticPath()+"js")
r.LoadHTMLGlob(config.GetTemplatePath())

// ----- 静态资源 -----
r.StaticFS("/img", http.FS(subFs(static.Img, "img")))
r.StaticFS("/css", http.FS(subFs(static.Css, "css")))
r.StaticFS("/js", http.FS(subFs(static.Js, "js")))
tmpl := template.Must(template.New("").ParseFS(static.Views, "views/*.html"))
r.SetHTMLTemplate(tmpl)
// ----- 静态资源 -----

r.Use(gin.LoggerWithWriter(log.GetWriter()), gin.Recovery())
r.Use(func(ctx *gin.Context) {
// 解析请求地址
Expand Down Expand Up @@ -91,3 +100,9 @@ func Start() {
}
}()
}

func subFs(src fs.FS, dir string) fs.FS {
subFS, _ := fs.Sub(src, dir)

return subFS
}
17 changes: 17 additions & 0 deletions static/embep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package static

import (
"embed"
)

//go:embed css/*
var Css embed.FS

//go:embed img/*
var Img embed.FS

//go:embed js/*
var Js embed.FS

//go:embed views/*
var Views embed.FS
6 changes: 6 additions & 0 deletions static/js/layer.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion static/js/layer/3.5.1/layer.min.js

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion templates/tron.trx.html → static/views/tron.trx.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="/js/jquery.min.js"></script>
<script src="/js/jquery.qrcode_1.0.min.js"></script>
<script src="/js/clipboard.min.js"></script>
<script src="/js/layer/3.5.1/layer.min.js"></script>
<script src="/js/layer.min.js"></script>
</head>
<body>
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion templates/usdt.trc20.html → static/views/usdt.trc20.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script src="/js/jquery.min.js"></script>
<script src="/js/jquery.qrcode_1.0.min.js"></script>
<script src="/js/clipboard.min.js"></script>
<script src="/js/layer/3.5.1/layer.min.js"></script>
<script src="/js/layer.min.js"></script>
</head>
<body>
<div class="container">
Expand Down

0 comments on commit 3534d85

Please sign in to comment.