From 84e2589b686680616340c33b9570cf12fa589305 Mon Sep 17 00:00:00 2001 From: ideaa Date: Mon, 29 Sep 2025 10:46:11 +0800 Subject: [PATCH] template --- internal/cli/cli_new.go | 2 +- internal/cli/templates/default/cmd/api.go.tmpl | 2 +- internal/cli/templates/default/middlewares/cors.go.tmpl | 2 +- internal/cli/templates/default/router/api.go.tmpl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/cli/cli_new.go b/internal/cli/cli_new.go index 0e8579f..52eb52c 100644 --- a/internal/cli/cli_new.go +++ b/internal/cli/cli_new.go @@ -121,7 +121,7 @@ func createProject(name, packageName string) { // runGoModTidy 在指定目录先更新依赖然后执行 func runGoModTidy(projectDir string) error { - getCmd := exec.Command("go", "get", "-u", "github.com/wonli/aqi@latest") + getCmd := exec.Command("go", "get", "-u", ".") getCmd.Dir = projectDir getCmd.Stdout = os.Stdout getCmd.Stderr = os.Stderr diff --git a/internal/cli/templates/default/cmd/api.go.tmpl b/internal/cli/templates/default/cmd/api.go.tmpl index c09cfc4..114fb1d 100644 --- a/internal/cli/templates/default/cmd/api.go.tmpl +++ b/internal/cli/templates/default/cmd/api.go.tmpl @@ -19,7 +19,7 @@ var api = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { app := aqi.Init( aqi.ConfigFile(configFile), - aqi.HttpServer("Api", "apiPort"), + aqi.HttpServer("Api", "port"), ) dbc.InitDBC() diff --git a/internal/cli/templates/default/middlewares/cors.go.tmpl b/internal/cli/templates/default/middlewares/cors.go.tmpl index ef3f082..a0668b5 100644 --- a/internal/cli/templates/default/middlewares/cors.go.tmpl +++ b/internal/cli/templates/default/middlewares/cors.go.tmpl @@ -7,7 +7,7 @@ func GinCORS() gin.HandlerFunc { // 设置响应头中的Access-Control-Allow-Origin为"*",允许所有域名的跨域请求。 c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") - c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") + c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Cache-Control, X-Requested-With") c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length") c.Writer.Header().Set("Access-Control-Allow-Credentials", "false") diff --git a/internal/cli/templates/default/router/api.go.tmpl b/internal/cli/templates/default/router/api.go.tmpl index 0f39a38..b42612c 100644 --- a/internal/cli/templates/default/router/api.go.tmpl +++ b/internal/cli/templates/default/router/api.go.tmpl @@ -10,7 +10,7 @@ import ( func Api(g *gin.Engine) { g.Use(middlewares.GinCORS()) - g.GET("/ok", func(c *gin.Context) { + g.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{ "t": time.Now().Unix(), })