swaggerui

package module
v0.0.0-...-8beb5ba Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 6 Imported by: 1

README

go-swagger-ui

Documentation Go Report Card test MIT License

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.

  1. Add updated assets to //third_party/swagger-ui
  2. Run make build which will compile swagger into swagger/bindata.go

Documentation

Overview

Package swaggerui provides Handlers for serving the swagger UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandle

func AddHandle(mux *http.ServeMux, root string)

AddHandle adds the swagger-ui Handle to the provided mux at the provided root.

func NewServeMux

func NewServeMux(assetFn AssetFn, filename string) *http.ServeMux

NewServeMux creates a new http.ServeMux which serves the swagger ui and json with the default root "/".

func NewServeMuxWithRoot

func NewServeMuxWithRoot(assetFn AssetFn, filename, root string) *http.ServeMux

NewServeMuxWithRoot creates a new http.ServeMux which serves the swagger ui and json with the provided root. Passing in root = "/v1/auth" will yield a path of "/v1/auth/swagger.json"

Types

type AssetFn

type AssetFn func(string) ([]byte, error)

AssetFn is a function handler which returns the swagger.json bytes. Used to instantiate handler with swagger.json.

func AssetFnFromBytes

func AssetFnFromBytes(swagFileBytes []byte) AssetFn

AssetFnFromBytes should recieve swagger json file bytes and returns an AssetFn to use with NewServeMux.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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