| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package main
- import (
- "flag"
- "fmt"
- "gframe/controller"
- "gframe/docs"
- "gframe/global"
- "gframe/logger"
- "gframe/middleware"
- "gframe/repository/postgres"
- "gitee.com/zr233/bsf"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- ginSwagger "github.com/swaggo/gin-swagger"
- "github.com/swaggo/gin-swagger/swaggerFiles"
- "os"
- )
- var _VERSION_ = "unknown"
- func flagInit() {
- flag.BoolVar(&global.Project.Debug, "d", global.Project.Debug, "是否debug")
- flag.StringVar(&global.Project.Host, "s", global.Project.Host, "swag host")
- flag.BoolVar(&help, "h", false, "this help")
- flag.Parse()
- if help {
- flag.Usage()
- os.Exit(0)
- }
- }
- // @title web框架
- // @version 1.0
- // @description web框架 API 文档
- // @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
- // @BasePath /v1
- // @securityDefinitions.basic BasicAuth
- // @securityDefinitions.apikey ApiKeyAuth
- // @in header
- // @name Authorization
- // @securitydefinitions.oauth2.application OAuth2Application
- // @tokenUrl https://example.com/oauth/token
- // @scope.write Grants write access
- // @scope.admin Grants read and write access to administrative information
- // @securitydefinitions.oauth2.implicit OAuth2Implicit
- // @authorizationurl https://example.com/oauth/authorize
- // @scope.write Grants write access
- // @scope.admin Grants read and write access to administrative information
- // @securitydefinitions.oauth2.password OAuth2Password
- // @tokenUrl https://example.com/oauth/token
- // @scope.read Grants read access
- // @scope.write Grants write access
- // @scope.admin Grants read and write access to administrative information
- // @securitydefinitions.oauth2.accessCode OAuth2AccessCode
- // @tokenUrl https://example.com/oauth/token
- // @authorizationurl https://example.com/oauth/authorize
- // @scope.admin Grants read and write access to administrative information
- func main() {
- logger.Init()
- global.Init()
- logger.SetOnlineWriters()
- flagInit()
- postgres.Init()
- r := bsf.NewDefaultEngine()
- gin.SetMode(gin.ReleaseMode)
- r.Use(
- middleware.ErrorResponse(),
- middleware.Logger(),
- middleware.Session(),
- )
- r.AutoRegisterController("/v1", &controller.Auth{})
- r.AutoRegisterController("/v1", &controller.Test{})
- //debug模式下启用swag文档
- if global.Project.Debug {
- gin.SetMode(gin.DebugMode)
- //设置swagger文档主机
- docs.SwaggerInfo.Host = fmt.Sprintf("%s:%d", global.Project.Host, global.Port)
- // 注册swagger文档
- // 查看地址为 /v1/docs/index.html /v1/SignIn/docs/doc.json
- r.GET("/v1/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
- }
- logrus.Infof("Version:[%s]\n", _VERSION_)
- _ = r.Run(fmt.Sprintf(":%d", global.Port))
- }
- var (
- help bool
- )
|