swgui

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2017 License: Apache-2.0 Imports: 12 Imported by: 1

README

Swagger UI

GoDoc

Package swgui (Swagger UI) provide a HTTP handler to serve Swagger UI. All assets are embedded in GO source code, so just build and run.

How to use

package main

import (
    "http"

    "github.com/lazada/swgui"
)

func main() {
    http.Handle("/", swgui.NewHandler("Page title", "path/to/swagger.json", "/"))
    http.ListenAndServe(":8080", nil)
}

Run as standalone server

Install swgui-server

go get github.com/lazada/swgui/...

Start server

swgui-server -port 8080

Documentation

Overview

Package swgui provide a http FileSystem handler for swagger UI interface

File `bindata_assetfs.go` is generated by go-bindata-assetfs (https://github.com/elazarl/go-bindata-assetfs) tool, which help to embed all static files into a go source file.

How to generate file:

NOTE:

  • File `bindata_assetfs.go` ONLY need to re-generate file again when we update swagger-ui (swagger/ui/static)

1. Install tools:

go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/elazarl/go-bindata-assetfs/...

2. Generate file:

At root folder, run command:

go-bindata-assetfs -pkg=swgui static/...
gofmt -w bindata_assetfs.go

Or just run: `go generate`

Enjoy it ;)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Handler

type Handler struct {
	Title       string // title of index file
	SwaggerJSON string // path to swagger.json document specification
	BasePath    string // base path to docs

	JsonEditor bool // Enable visual json editor support (experimental, can fail with complex schemas)
	// contains filtered or unexported fields
}

Handler handle swagger UI request

func NewHandler

func NewHandler(title, swaggerJSONPath string, basePath string) *Handler

NewHandler returns a HTTP handler for swagger UI

func NewHandlerWithConfig

func NewHandlerWithConfig(handler Handler) *Handler

NewHandlerWithConfig returns a HTTP handler for swagger UI

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implement http.Handler interface, to handle swagger UI request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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