I have go application(gorilla/mux) that serves a specific port. I too have a swagger API specification in the form of json file. Is there any go API that can generate a swagger UI definition from the JSON file just like spring boot. I am looking at https://github.com/go-swagger/go-swagger, but i am not able to use this in my go-lang code. It seems this API can be used only from the command line.
If you already have your APIs defined in YAML or JSON format, you can use the static 'dist' tree to render it from a browser:
https://github.com/swagger-api/swagger-ui/tree/master/dist
Update index.html
to point to your API doc via this tag:
url: "https://petstore.swagger.io/v2/swagger.json",
And if you want to serve this static tree from your go REST-API server, add the following handler:
fs := http.FileServer(http.Dir("dist"))
http.Handle("/swagger/", http.StripPrefix("/swagger/", fs))
This will serve the swaggers docs off the /swagger/
route - reading the content from the dist
directory.
Here as an alternative to using the static dist
code
SwaggerUI has a URL
parameter that you can provide your own swagger.json and it will render the UI with your definitions, here is an example:
http://petstore.swagger.io/?url=http://swagger-net-test.azurewebsites.net/swagger/docs/V1
As you can see you don't really need anything other than your own swagger spec and internet access