Skip to content

Instantly share code, notes, and snippets.

@XUJiahua
Last active May 2, 2017 02:47
Show Gist options
  • Save XUJiahua/9b041330db9dc40583dd482b88858438 to your computer and use it in GitHub Desktop.
Save XUJiahua/9b041330db9dc40583dd482b88858438 to your computer and use it in GitHub Desktop.
Host Swagger API Doc
http.HandleFunc("/", SpecUIPage)
http.HandleFunc("/swagger.json", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
// put swagger.json under current folder
http.ServeFile(w, r, "swagger.json")
})
func SpecUIPage(w http.ResponseWriter, r *http.Request) {
swaggerAddr := "http://" + r.Host + "/swagger.json"
http.Redirect(w, r, "http://petstore.swagger.io/?url="+url.QueryEscape(swaggerAddr), http.StatusSeeOther)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment