github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/controller/api/nodes.go (about) 1 package api 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/gorilla/mux" 8 ) 9 10 func (a *Api) nodes(w http.ResponseWriter, r *http.Request) { 11 w.Header().Set("content-type", "application/json") 12 13 nodes, err := a.manager.Nodes() 14 if err != nil { 15 http.Error(w, err.Error(), http.StatusInternalServerError) 16 return 17 } 18 if err := json.NewEncoder(w).Encode(nodes); err != nil { 19 http.Error(w, err.Error(), http.StatusInternalServerError) 20 return 21 } 22 } 23 24 func (a *Api) node(w http.ResponseWriter, r *http.Request) { 25 w.Header().Set("content-type", "application/json") 26 27 vars := mux.Vars(r) 28 name := vars["name"] 29 node, err := a.manager.Node(name) 30 if err != nil { 31 http.Error(w, err.Error(), http.StatusInternalServerError) 32 return 33 } 34 if err := json.NewEncoder(w).Encode(node); err != nil { 35 http.Error(w, err.Error(), http.StatusInternalServerError) 36 return 37 } 38 }