Help us shape the future of Go! Take the 2026 Go Developer Survey

swagserver

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2018 License: MIT Imports: 10 Imported by: 1

README

swagserver Go Report Card

Middleware used to serve swagger ui with go-swagger generated api servers

Usage

This simple project is intended to be used as middle ware that can be used to serve swagger ui using a valid Open API json specification document. The middleware only has standard lib dependencies, so it should be fairly easy to compose in the context of other popular web frameworks.

Setup and usage

go get github.com/syllabix/swagserver

Initialize an instance of swag server middle ware with the new factory function using a swagserver.Config struct. Register it as middleware that occurs prior to routing.

func setupGlobalMiddleware(handler http.Handler) http.Handler {
	swagserve := swagserver.New(swagserver.Config{
		URLPath:        "/v1/swagger",
		ShouldRender:   true,
		SwaggerSpecURL: "/swagger.json",
	})
	return swagserve(handler)
}

Development

To remove the need to keep static web ui files in the repository, this project uses statik to embed the swagger-ui-dist npm package into the package's binary. A simple build script is included in the repository that can be used to resolve swagger-ui-dist from npm, copy and embed necessary files from the package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// URLPath is the path at which swagger ui will be served at
	URLPath string

	// ShouldRender is used to signal to the middleware whether or not to serve
	// swagger ui (Ex. expose swagger ui in non production environments, while not rendering in production)
	ShouldRender bool

	// SwaggerSpecURL is the url swagger ui will try to resolve a valid specifcation file from
	SwaggerSpecURL string
}

Config is an object intended to be used to configure an instance of a swag server middle ware

type Middleware

type Middleware func(next http.Handler) http.Handler

Middleware is a simple alias for a commonmiddle ware function signature, func(next http.Handler) http.Handler

func New

func New(config ...Config) Middleware

New is the factory constructor for intializing a SwagServer middleware It takes an optional SwagServerConfig object as its single argument. If used without providing a config object, it will intialize the middleware using default settings:

UrlPath:      "/swagger/"
ShouldRender: true
SpecUrl:      "/swagger.json"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL