modulepackage
0.0.0-20221023084847-8beb5ba14803
Repository: https://github.com/esurdam/go-swagger-ui.git
Documentation: pkg.go.dev
# README
go-swagger-ui
This repo provides go handlers for serving swagger.json
and the Swagger UI.
Commonly used with grpc-gateway compiled swagger.
Usage
import (
"github.com/esurdam/go-swagger-ui"
)
// Asset represents a AssetFn - compiled bindata swagger file
mux := swaggerui.NewServeMux(Asset, "swagger.json") // add swagger bindata asset
// /swagger.json serves json
// /swagger-ui serves the swagger-ui
With custom root:
import (
"github.com/esurdam/go-swagger-ui"
)
// Asset represents a AssetFn - compiled bindata swagger file
mux := swaggerui.NewServeMuxWithRoot(Asset, "swagger.json", "/v1/auth") // add swagger bindata asset
// v1/auth/swagger.json serves json
// v1/auth/swagger-ui serves the swagger-ui
Updating UI
swagger
directory contains auto-generated output.
- Add updated assets to //third_party/swagger-ui
- Run
make build
which will compile swagger intoswagger/bindata.go
# Functions
AddHandle adds the swagger-ui Handle to the provided mux at the provided root.
AssetFnFromBytes should recieve swagger json file bytes and returns an AssetFn to use with NewServeMux.
NewServeMux creates a new http.ServeMux which serves the swagger ui and json with the default root "/".
NewServeMuxWithRoot creates a new http.ServeMux which serves the swagger ui and json with the provided root.
# Type aliases
AssetFn is a function handler which returns the swagger.json bytes.