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

swagserver

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 11 Imported by: 1

README

swagserver

Go Report Card

A simple middleware that serves swagger ui using a valid Open API json specification document.

The middleware func is typed using the common convention func(next http.Handler) http.Handler - which should make it pluggable into most Go web frameworks.

Setup and usage

go get github.com/syllabix/swagserver

Initialize an instance of swag server middleware with various options.

func setupGlobalMiddleware(handler http.Handler) http.Handler {
	swagserve := swagserver.New(
		option.Path("/internal/apidocs"),
		option.SwaggerSpecURL("/swagger.json"),
		option.Theme(theme.Material),
	)
	return swagserve(handler)
}

Options

Path - the the url path swagger ui should be served at

Disable - swagger ui will not be rendered

SwaggerSpecURL - the url where the swagger json specification is served from

Theme - the theme the ui should by displayed in

Themes

Themes, with exclusion of the default, are all sourced from swagger-ui-themes.

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 project source.

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. You will need to be running on a mac (macOS style sed is used) and npm installed in order for it to run.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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(options ...config.Option) Middleware

New is the factory constructor for intializing a middleware using config.Option funcs to override defaults settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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