Files
Git-Website/main.go
2026-08-01 20:52:57 +08:00

46 lines
728 B
Go

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)
}