func HandleManifestRequest(w http.ResponseWriter, r *http.Request) { var status int projName := filepath.Base(r.URL.String()) switch r.Method { case "HEAD": if data.BrokerHasProject(projName) { status = http.StatusOK w.WriteHeader(status) } case "GET": if data.BrokerHasProject(projName) { bytes := data.EncodeProject(projName) status = http.StatusOK w.Write(bytes) } else { status = http.StatusNotFound w.WriteHeader(status) } default: status = http.StatusMethodNotAllowed } log.Printf("%s %s => %d %s", r.Method, r.URL, status, http.StatusText(status)) }
func HandleProjectRequest(w http.ResponseWriter, r *http.Request) { var status int switch r.Method { case "POST": body, _ := ioutil.ReadAll(r.Body) defer r.Body.Close() proj := data.DecodeProjectFrom(r.RemoteAddr, body) found := data.BrokerHasProject(proj.Name) if found { status = http.StatusConflict } else { data.StoreProject(proj) status = http.StatusCreated } default: status = http.StatusMethodNotAllowed } w.WriteHeader(status) log.Printf("%s %s => %d %s", r.Method, r.URL, status, http.StatusText(status)) }