feat: 新增日志、配置文件和环境变量

This commit is contained in:
2026-03-02 02:01:08 +08:00
commit 607ff9a055
10 changed files with 1085 additions and 0 deletions

41
app.go Normal file
View File

@@ -0,0 +1,41 @@
package go_web_gin
import (
"log"
"git.hujye.com/infrastructure/go-web-gin/config"
"git.hujye.com/infrastructure/go-web-gin/server"
"github.com/gin-gonic/gin"
)
// App represents the application
type App struct {
server *server.Server
}
// New creates a new App instance and loads config file
func New() *App {
// Load config file
if _, err := config.Load(); err != nil {
log.Printf("Warning: failed to load config file, using defaults: %v", err)
}
return &App{
server: server.New(),
}
}
// UseMiddleware registers global middleware
func (a *App) UseMiddleware(middleware ...gin.HandlerFunc) {
a.server.Engine().Use(middleware...)
}
// RegisterRoutes registers routes with the given handler function
func (a *App) RegisterRoutes(registerFunc func(*gin.Engine)) {
registerFunc(a.server.Engine())
}
// Run starts the application server
func (a *App) Run(addr ...string) error {
return a.server.Run(addr...)
}