This commit is contained in:
wjqserver 2025-07-01 10:32:26 +08:00
parent d4e7f83131
commit cfaf82def3
12 changed files with 232 additions and 10 deletions

View file

@ -9,7 +9,7 @@ import (
"github.com/infinite-iroha/touka"
)
func ApiGroup(v0 touka.IRouter, cdb *db.ConfigDB, cfg *config.Config) {
func ApiGroup(v0 touka.IRouter, cdb *db.ConfigDB, cfg *config.Config, version string) {
api := v0.Group("/api")
api.GET("/config/filenames", func(c *touka.Context) {
filenames, err := cdb.GetFileNames()
@ -20,6 +20,8 @@ func ApiGroup(v0 touka.IRouter, cdb *db.ConfigDB, cfg *config.Config) {
c.JSON(200, filenames)
})
api.GET("/info", infoHandle(version))
// 配置参数相关
cfgr := api.Group("/config")
{

View file

@ -20,6 +20,7 @@ var (
"/v0/api/auth/init": {},
"/init.html": {},
"/favicon.ico": {},
"/v0/api/info": {},
}
prefixMatchPaths = []string{ // 保持前缀匹配,因为数量少
"/js/",
@ -38,17 +39,18 @@ var (
)
func isPassPath(requestPath string) bool {
// 精确匹配
if _, ok := exactMatchPaths[requestPath]; ok {
return true
}
// 前缀匹配
for _, prefix := range prefixMatchPaths {
if strings.HasPrefix(requestPath, prefix) {
return true
}
}
// 精确匹配
if _, ok := exactMatchPaths[requestPath]; ok {
return true
}
return false
}

33
api/info.go Normal file
View file

@ -0,0 +1,33 @@
package api
import (
"runtime/debug"
"github.com/infinite-iroha/touka"
)
type InfoApiStruct struct {
Version string `json:"version"`
License string `json:"license"`
Author []string `json:"author"`
BuildVersion string `json:"build_version"`
GoVersion string `json:"go_version"`
}
func infoHandle(version string) touka.HandlerFunc {
return func(c *touka.Context) {
buildinfo, ok := debug.ReadBuildInfo()
if !ok {
c.JSON(500, touka.H{"error": "no build info"})
return
}
c.JSON(200, InfoApiStruct{
Version: version,
License: "Mozilla Public License 2.0",
//Author: "WJQSERVER",
Author: []string{"WJQSERVER"},
BuildVersion: buildinfo.Main.Version,
GoVersion: buildinfo.GoVersion,
})
}
}