Skip to content

A statically packaged http.Handler for Swagger's UI

Notifications You must be signed in to change notification settings

andrewbenton/go-swaggerui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Embedded Swagger UI for Go

This library exposes a simple parameterized http.Handler that will display the Swagger UI. All resources needed to run a standalone swagger-ui are packaged into a static filesystem and deployed with the library, which means that your documentation can be visually served alongside your application.

Example

package main

import (
	"fmt"
	"net/http"

	"github.com/gorilla/mux"

	"github.com/andrewbenton/go-swaggerui"
)

func main() {
	swaggerJSON := "..."

	router := mux.NewRouter()
	router.HandleFunc("/swagger.json", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		w.Write([]byte(swaggerJSON))
	})
	router.PathPrefix("/swagger-ui").Handler(swaggerui.Handle(swaggerui.Config{
		AppName: "swagger-demo",
		SwaggerURL: "/swagger.json",
		RootUIPath: "/swagger-ui",
	}))

	if err := http.ListenAndServe(":8080", router); err != nil {
		fmt.Println(err)
	}
}

Credits

When looking for something to do what this library does, I found a post from ribice that helped me get started.

Implementation of the UI is thanks to Swagger UI.

About

A statically packaged http.Handler for Swagger's UI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published