2026-08-01

This commit is contained in:
2026-08-01 20:52:57 +08:00
parent 1090291fc3
commit 33031875ec
5 changed files with 170 additions and 0 deletions

45
main.go Normal file
View File

@@ -0,0 +1,45 @@
package main
import (
"encoding/json"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
// Static Folders
router.StaticFS("/static", http.Dir("static"))
// Templates Folders
router.LoadHTMLGlob("templates/*")
// Router Rules
router.GET("/user/:uname", UnameFunc)
router.GET("/", HomeFunc)
router.Run(":8080")
}
// Func Rules
func UnameFunc(c *gin.Context) {
uname := c.Param("uname")
c.String(http.StatusOK, "Hello %s", uname)
}
func HomeFunc(c *gin.Context) {
type home_json struct {
Title string
Menu string
}
data_json, _ := os.ReadFile("data/web/home.json")
var data home_json
json.Unmarshal(data_json, &data)
c.HTML(http.StatusOK, "home.html", data)
}