Skip to content

Instantly share code, notes, and snippets.

@telecoda
Created July 27, 2018 12:06
Show Gist options
  • Save telecoda/05ab2e7b7d53f2a1378cc8cba8bd7172 to your computer and use it in GitHub Desktop.
Save telecoda/05ab2e7b7d53f2a1378cc8cba8bd7172 to your computer and use it in GitHub Desktop.
embed swaggerui in a go service
package swaggerui
import (
"net/http"
)
//go:generate go-bindata-assetfs -pkg=swaggerui -prefix=static/swagger-ui static/swagger-ui/dist/...
/*
*/
/*
Building
We serve the verion of swaggerui contained in the dist folder. To rebuild this distribution run the commands below.
To add a new API swagger spec to the list of dropdowns edit the topbar.jsx file and rebuild the npm project as follows:
1.) Create a swagger package in your project
2.) Clone https://github.com/swagger-api/swagger-ui swaggerui/static/swagger-ui folder in your project
3.) cd <your-project>/swaggerui/static/swagger-ui
4.) npm run build
After the swagger-ui distribution has been built you need to generate a static version of it which is embedded in the api-service as static content.
5.) Install this tool to generate embedded assets
https://github.com/elazarl/go-bindata-assetfs
6.) cd <your-project>/swaggerui
go generate ./...
This will generate an embedded version of swaggerui in your project
*/
var handler = http.FileServer(assetFS())
// Wire this handler up to the endpoint of your choice eg https://myapi.com/swaggerui
func GetSwaggerHandler() http.Handler {
return handler
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment