build: 初始化构建后端并集成Gin框架,开放健康检查端口
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port int
|
||||
Mode string
|
||||
MaxFileSize int64 // bytes
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
cfg := &Config{
|
||||
Port: 8080,
|
||||
Mode: "debug",
|
||||
MaxFileSize: 10 << 20, // 10MB
|
||||
}
|
||||
|
||||
if port := os.Getenv("GEN2D_PORT"); port != "" {
|
||||
if p, err := strconv.Atoi(port); err == nil {
|
||||
cfg.Port = p
|
||||
}
|
||||
}
|
||||
|
||||
if mode := os.Getenv("GEN2D_MODE"); mode != "" {
|
||||
cfg.Mode = mode
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"gen2d/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Health(c *gin.Context) {
|
||||
c.JSON(200, model.OK(gin.H{"status": "healthy"}))
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package model
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data any `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func OK(data any) Response {
|
||||
return Response{Code: 0, Message: "ok", Data: data}
|
||||
}
|
||||
|
||||
func Fail(code int, msg string) Response {
|
||||
return Response{Code: code, Message: msg}
|
||||
}
|
||||
Reference in New Issue
Block a user