-
-
Save kyawmyintthein/b0a21ae8109a18c3f133e0554ded8c6f to your computer and use it in GitHub Desktop.
embed swaggerui in a go service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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