基于 opsx-web-lite 框架(Go+Gin+Vue3+Element Plus)构建许可证管理服务器,
业务域参考 Licence 服务器 Web 版。
【后端 - 4层架构】
- 认证:单 Admin 表 + JWT(HS256)
- 核心授权域:Product / Customer / License / Activation
· License 生成/验证/激活/机器绑定/心跳/续期/吊销
· 客户端契约接口:/api/v1/license/{verify,activate,deactivate,heartbeat}
- 定价订单:Plan / Order / 支付网关配置
- 防重复购买:CustomerEntitlement + 幂等支付 webhook + 手动发放
- 分析审计:Dashboard 统计 / Analytics / AuditLog / Setting 管理
【前端】
- Dashboard(ECharts 图表)、产品、客户、License、计划、订单、权益、日志、设置
- 9 个完整 CRUD 业务页面 + 登录/布局
【部署】
- SQLite + 单二进制(//go:embed 嵌入前端)
- 开发:./run.sh start(前端5181/后端9001)
- 生产:./run.sh build && ./run.sh binary start
- 默认账号:admin/admin
Author: Logan.Li
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// frontendFS 是构建时嵌入的前端生产资源。 // Logan.Li
|
|
//
|
|
//go:embed all:static
|
|
var frontendFS embed.FS
|
|
|
|
// setupEmbeddedFrontend 为单二进制模式提供前端静态资源和 SPA 回退。 // Logan.Li
|
|
func setupEmbeddedFrontend(r *gin.Engine) {
|
|
staticFS, err := fs.Sub(frontendFS, "static")
|
|
if err != nil {
|
|
return
|
|
}
|
|
if _, err := fs.Stat(staticFS, "index.html"); err != nil {
|
|
// 开发模式不复制 dist,后端仅提供 API。 // Logan.Li
|
|
return
|
|
}
|
|
|
|
httpFS := http.FS(staticFS)
|
|
r.NoRoute(func(c *gin.Context) {
|
|
path := c.Request.URL.Path
|
|
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/ws/") {
|
|
c.JSON(http.StatusNotFound, gin.H{"code": 404, "message": "接口不存在"})
|
|
return
|
|
}
|
|
|
|
filePath := strings.TrimPrefix(path, "/")
|
|
if filePath == "" {
|
|
filePath = "index.html"
|
|
}
|
|
if _, err := staticFS.Open(filePath); err == nil {
|
|
if strings.HasSuffix(filePath, ".html") {
|
|
c.Header("Cache-Control", "no-store, no-cache, must-revalidate")
|
|
}
|
|
c.FileFromFS(path, httpFS)
|
|
return
|
|
}
|
|
|
|
if strings.HasPrefix(filePath, "assets/") {
|
|
c.String(http.StatusNotFound, "static asset not found")
|
|
return
|
|
}
|
|
index, err := fs.ReadFile(staticFS, "index.html")
|
|
if err != nil {
|
|
c.String(http.StatusInternalServerError, "前端资源不可用")
|
|
return
|
|
}
|
|
c.Header("Cache-Control", "no-store, no-cache, must-revalidate")
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", index)
|
|
})
|
|
}
|