Swag: I want to be able to register multiple hosts

Created on 20 Sep 2019  路  3Comments  路  Source: swaggo/swag

I want to be able to register multiple hosts so that the production environment and development environment can be used simultaneously

Does this library provide such functionality?

Most helpful comment

First of all swag it's an cli application that generate OpenAPI 2.0 Specification from your go code annotations.
When ever you use the generated documentation into a http Handler (no matter what type), you can change the endpoint by assingin a new value to variable Host of SwaggerInfo object of your documentation.

import ("github.com/swaggo/swag/example/basic/docs/docs.go")

func register_routes(router) error {
   docs.SwaggerInfo.Host = "http://new.endpoint"
}

Unfortunately there is no way to do that in OpenAPI 2.0, so you will have to do that at runtime.

All 3 comments

First of all swag it's an cli application that generate OpenAPI 2.0 Specification from your go code annotations.
When ever you use the generated documentation into a http Handler (no matter what type), you can change the endpoint by assingin a new value to variable Host of SwaggerInfo object of your documentation.

import ("github.com/swaggo/swag/example/basic/docs/docs.go")

func register_routes(router) error {
   docs.SwaggerInfo.Host = "http://new.endpoint"
}

Unfortunately there is no way to do that in OpenAPI 2.0, so you will have to do that at runtime.

Just added this line ...
docs.SwaggerInfo.Host = *host + ":" + *port
host and port the flags to the application.

Thank you so much, You've been very helpful!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lfaoro picture lfaoro  路  4Comments

chiragg6 picture chiragg6  路  7Comments

fannheyward picture fannheyward  路  3Comments

dz0ny picture dz0ny  路  5Comments

welenlin picture welenlin  路  3Comments