swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

is there a way to use diff host in diff env? #89

Open dezhishen opened 4 years ago

dezhishen commented 4 years ago

@host can't do that. Can I set host like set url? url := ginSwagger.URL(myConfig.GetString("ginswagger.url"))

ubogdan commented 4 years ago

The generated doc allows you to use different settings. See example doc.go . Unfortunately, the gin-swagger middleware wasn't updated to support this.

chrisbbe commented 4 years ago

@dezhiShen You could do something like this to create a middleware wrapping ginSwagger handler, retrieving the Host from os.Env or similar. Note that I'm using another approach, retrieving the Host from the request.

router.GET("/swagger/*any", func(context *gin.Context) {
    docs.SwaggerInfo.Host = context.Request.Host
    ginSwagger.WrapHandler(swaggerFiles.Handler)(context)
})
dezhishen commented 4 years ago

@dezhiShen You could do something like this to create a middleware wrapping ginSwagger handler, retrieving the Host from os.Env or similar. Note that I'm using another approach, retrieving the Host from the request.

router.GET("/swagger/*any", func(context *gin.Context) {
  docs.SwaggerInfo.Host = context.Request.Host
  ginSwagger.WrapHandler(swaggerFiles.Handler)(context)
})

just reset the host before set router

   docs.SwaggerInfo.Host =  myconfigs.GetConfig().GetString("ginswagger.host")