Last active
May 2, 2017 02:47
-
-
Save XUJiahua/9b041330db9dc40583dd482b88858438 to your computer and use it in GitHub Desktop.
Host Swagger API Doc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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