Browse Source

Handle json encoding errors

feature/add-executable-steps
Roman Zipp 2 years ago
parent
commit
dbcf08b197
  1. 15
      main.go

15
main.go

@ -18,12 +18,18 @@ type Metadata struct {
func PipelineHandler(pipeline pipelines.IPipeline, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(pipeline)
err := json.NewEncoder(w).Encode(pipeline)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}
func IndexHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(Metadata{Name, Version})
err := json.NewEncoder(w).Encode(Metadata{Name, Version})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}
func RegisterPipelineRoutes(r *mux.Router, pipelines []pipelines.IPipeline) {
@ -42,5 +48,8 @@ func main() {
RegisterPipelineRoutes(r, pipes)
http.ListenAndServe(":8000", r)
err := http.ListenAndServe(":8000", r)
if err != nil {
panic(err)
}
}
Loading…
Cancel
Save