From 57e57e5028d83974592fa71e54dcae13bbb56182 Mon Sep 17 00:00:00 2001 From: Twilight Date: Sun, 14 Jul 2024 22:14:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20swag=20go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 3 ++- internal/routes/router.go | 21 +++++++++++++++++++++ main.go | 11 ++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7ff66cc..a9719ae 100644 --- a/Makefile +++ b/Makefile @@ -6,4 +6,5 @@ grpc-web: grpcwebproxy --backend_addr=localhost:8081 --run_http_server --run_tls_server=false --server_http_debug_port 18081 --allow_all_origins --server_bind_address 127.0.0.1 install-deps: go install github.com/swaggo/swag/cmd/swag@latest - go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest \ No newline at end of file +swag: + swag init -g internal/routes/router.go \ No newline at end of file diff --git a/internal/routes/router.go b/internal/routes/router.go index 3fb3a2c..168e3fd 100644 --- a/internal/routes/router.go +++ b/internal/routes/router.go @@ -7,6 +7,27 @@ import ( "github.com/gin-gonic/gin" ) +// @title Swagger Example API +// @version 1.0 +// @description This is a sample server celler server. +// @termsOfService http://swagger.io/terms/ + +// @contact.name API Support +// @contact.url http://www.swagger.io/support +// @contact.email support@swagger.io + +// @license.name Apache 2.0 +// @license.url http://www.apache.org/licenses/LICENSE-2.0.html + +// @host localhost:8080 +// @BasePath /api/v1 + +// @securityDefinitions.basic BasicAuth + +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name Authorization +// @description Description for what is this security definition being used func InitApiRoutes() { var router = *providers.MustGet[gin.Engine]() diff --git a/main.go b/main.go index a39fe01..be861a2 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "framework_v2/internal/cmd" + "framework_v2/internal/providers" "io/fs" "os" "os/exec" @@ -17,9 +18,13 @@ const frameworkModuleName = "framework_v2" func main() { flag.Parse() - if len(os.Args) == 2 && os.Args[1] == "setup" { - setup() - return + var config = providers.MustGet[providers.GlobalConfig]() + + if config.DebugMode.Enable { + if len(os.Args) == 2 && os.Args[1] == "setup" { + setup() + return + } } cmd.Execute()