This commit is contained in:
2025-12-27 02:50:16 +08:00
parent 9cf62f793b
commit e9ef58e6fa
138 changed files with 2288 additions and 174165 deletions

12
internal/logic/all.go Normal file
View File

@@ -0,0 +1,12 @@
package logic
import (
"github.com/gin-gonic/gin"
)
func All(c *gin.Context) {
data := gin.H{}
tplName := c.GetString("TplName")
c.HTML(200, tplName, data)
}

View File

@@ -1,11 +1,30 @@
package routers
import (
"os"
"strings"
"git.apinb.com/senlinai/site/internal/logic"
"github.com/gin-gonic/gin"
)
// Register public 注册路由
func Registers_Public(engine *gin.Engine) {
//fmt.Println("Register public")
func RegistersPublic(engine *gin.Engine) {
engine.GET("/", logic.Index)
}
func RegistersAll(engine *gin.Engine) {
templs, err := os.ReadDir("./res/templates/")
if err != nil {
panic(err)
}
for _, item := range templs {
name := strings.TrimSuffix(item.Name(), ".html")
engine.GET("/all/"+name, func(ctx *gin.Context) {
ctx.Set("TplName", item.Name())
logic.All(ctx)
return
})
}
}

View File

@@ -1,13 +1,71 @@
package tmpl
import (
"html/template"
"encoding/json"
"strings"
"text/template"
"github.com/gin-gonic/gin"
)
func New(app *gin.Engine) {
app.Static("/assets", "./res/assets")
html := template.Must(template.ParseFiles("file1", "file2"))
app.SetHTMLTemplate(html)
funcMap := template.FuncMap{
"mod": GetRemainder,
"add": GetAdd,
"div": GetDivision,
"sub": Sub,
"seq": Seq,
"mul": GetMultiply,
"test": TestFunc,
}
app.SetFuncMap(funcMap)
app.LoadHTMLGlob("./res/templates/*")
}
func TestFunc(in string) string {
return strings.ToUpper(in)
}
func AnyToBytes(data any) ([]byte, error) {
return json.Marshal(data)
}
// 定义取余函数
func GetRemainder(a, b int) int {
return a % b
}
// 定义 整数相加
func GetAdd(a, b int) int {
return a + b
}
// 定义 整数相乘
func GetMultiply(a, b int) int {
return a * b
}
// 定义 整数相除
func GetDivision(a, b int) int {
if b == 0 {
return 0 // 当除数为 0 时返回 0避免 panic
}
return a / b
}
// 定义 整数相减
func Sub(a, b int) int {
return a - b
}
// 定义 获取页码
func Seq(start, end int) []int {
result := make([]int, end-start+1)
for i := range result {
result[i] = start + i
}
return result
}