feat: 添加版本信息
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"ckwk/internal/router"
|
||||
"ckwk/pkg/log"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
func main() {
|
||||
router := router.SetupRouter()
|
||||
|
||||
fmt.Printf("启动服务: http://local.kmux.cn:8080\n")
|
||||
if err := http.ListenAndServe(
|
||||
":8080",
|
||||
router,
|
||||
|
||||
@@ -72,6 +72,20 @@ func GetRecords[T any](wk *WK, rType RecordType, courseID, page string) (*AllRec
|
||||
if !result.Status {
|
||||
return &result, fmt.Errorf("接口报错: %s", result.Msg)
|
||||
}
|
||||
currentPage := result.PageInfo.Page
|
||||
totalPages := result.PageInfo.PageCount
|
||||
|
||||
for currentPage < totalPages {
|
||||
nextPage := fmt.Sprint(currentPage + 1)
|
||||
nextResult, err := GetRecords[T](wk, rType, courseID, nextPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result.List = append(result.List, nextResult.List...)
|
||||
log.Debug("Page", zap.Int("currentPage", currentPage), zap.Int("Page", nextResult.PageInfo.Page))
|
||||
currentPage = nextResult.PageInfo.Page
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (h *WKHandler) AllRecord(ctx *gin.Context) {
|
||||
req.Page = 1
|
||||
}
|
||||
var list any
|
||||
var pageInfo any
|
||||
var pageInfo ckwk.PageInfo
|
||||
var err error
|
||||
|
||||
// 根据类型调用不同的泛型方法
|
||||
@@ -173,7 +173,10 @@ func (h *WKHandler) AllRecord(ctx *gin.Context) {
|
||||
|
||||
ctx.JSON(200, dto.Success(map[string]any{
|
||||
"list": list,
|
||||
"page_info": pageInfo,
|
||||
"page_info": map[string]any{
|
||||
"page": 1,
|
||||
"pageSize": pageInfo.RecordsCount,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
18
internal/handler/version.go
Normal file
18
internal/handler/version.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"ckwk/internal/conf"
|
||||
"ckwk/internal/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Version(ctx *gin.Context) {
|
||||
ctx.JSON(200, dto.Success(map[string]string{
|
||||
"Version": conf.Version,
|
||||
"BuildAt": conf.BuildAt,
|
||||
"GitAuthor": conf.GitAuthor,
|
||||
"GitEmail": conf.GitEmail,
|
||||
"GitCommit": conf.GitCommit,
|
||||
}))
|
||||
}
|
||||
@@ -24,9 +24,9 @@ func SetupRouter() *gin.Engine {
|
||||
}
|
||||
r := gin.Default()
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*://*", "http://localhost:5173"},
|
||||
AllowOrigins: []string{"*.kmux.cn"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
|
||||
AllowHeaders: []string{"*", "X-Session-Id"},
|
||||
AllowHeaders: []string{"X-Session-Id"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 12 * time.Hour,
|
||||
@@ -42,11 +42,12 @@ func SetupRouter() *gin.Engine {
|
||||
distHTTP := http.FS(dist)
|
||||
r.StaticFS("/js", http.FS(mustSub(dist, "js")))
|
||||
r.StaticFS("/assets", http.FS(mustSub(dist, "assets")))
|
||||
r.StaticFileFS("/favicon.ico", "favicon.ico", distHTTP)
|
||||
r.StaticFileFS("/favicon.png", "favicon.png", distHTTP)
|
||||
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.POST("/login", wkHandler.Login)
|
||||
api.Any("/version", handler.Version)
|
||||
v1 := api.Group("/v1")
|
||||
{
|
||||
v1.GET("/host", wkHandler.Host)
|
||||
|
||||
Reference in New Issue
Block a user