Ejemplo n.º 1
0
func handlePkgsinfoReplace(db datastore.Datastore) httprouter.Handle {
	return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		name := strings.TrimLeft(ps.ByName("name"), "/")
		accept := acceptHeader(r)
		pkgsinfo, err := db.Pkgsinfo(name)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to upddate pkgsinfo: %v", err))
			return
		}

		payload := &models.PkgsInfo{}
		err = decodeRequest(r, payload)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to decode request payload: %v", err))
			return
		}

		if err := db.SavePkgsinfo(pkgsinfo); err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to save pkginfo: %v", err))
			return
		}

		pkgsinfo = payload
		pkgsinfo.Filename = name

		// manifest updated ok, respond
		respondOK(rw, pkgsinfo, accept)
	}
}
Ejemplo n.º 2
0
func handlePkgsinfoShow(db datastore.Datastore) httprouter.Handle {
	return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		name := strings.TrimLeft(ps.ByName("name"), "/")
		accept := acceptHeader(r)
		pkgsinfo, err := db.Pkgsinfo(name)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to fetch pkgsinfo from the datastore: %v", err))
			return
		}
		respondOK(rw, pkgsinfo, accept)
	}
}