Skip to content

Commit

Permalink
Merge pull request #16 from timaschew/reload-url
Browse files Browse the repository at this point in the history
provide endpoint to reload the URL
  • Loading branch information
danielgtaylor committed Feb 28, 2019
2 parents dee2f9c + 39bceab commit d8bca8b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apisprout.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ func server(cmd *cobra.Command, args []string) {

swagger, router = load(uri, data)

if strings.HasPrefix(uri, "http") {
http.HandleFunc("/__reload", func(w http.ResponseWriter, r *http.Request) {
resp, err := http.Get(uri)
if err != nil {
log.Printf("ERROR: %v", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("error while reloading"))
return
}

data, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Printf("ERROR: %v", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("error while parsing"))
return
}
swagger, router = load(uri, data)
w.WriteHeader(200)
w.Write([]byte("reloaded"))
})
}

// Register our custom HTTP handler that will use the router to find
// the appropriate OpenAPI operation and try to return an example.
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
Expand Down

0 comments on commit d8bca8b

Please sign in to comment.