Esempio n. 1
0
File: ent.go Progetto: queer1/ent
func handleCreate(p Provider, fs FileSystem) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			began  = time.Now()
			bucket = r.URL.Query().Get(":bucket")
			key    = r.URL.Query().Get(":key")
		)
		defer r.Body.Close()

		b, err := p.Get(bucket)
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}

		rd := NewReaderDelegator(r.Body)
		f, err := fs.Create(b, key, rd)
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}
		h, err := f.Hash()
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}

		rwd := exp.NewResponseWriterDelegator(w)
		defer reportMetrics(rwd, r, rd, b, began, "handleCreate")

		respondCreated(rwd, b, key, h, began)
	}
}
Esempio n. 2
0
File: ent.go Progetto: queer1/ent
func handleGet(p Provider, fs FileSystem) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			began  = time.Now()
			bucket = r.URL.Query().Get(":bucket")
			key    = r.URL.Query().Get(":key")
		)

		b, err := p.Get(bucket)
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}

		f, err := fs.Open(b, key)
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}

		rwd := exp.NewResponseWriterDelegator(w)
		defer reportMetrics(rwd, r, nil, b, began, "handleGet")

		http.ServeContent(rwd, r, key, time.Now(), f)
	}
}
Esempio n. 3
0
File: ent.go Progetto: queer1/ent
func handleBucketList(p Provider) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		began := time.Now()

		bs, err := p.List()
		if err != nil {
			respondError(w, r.Method, r.URL.String(), err)
			return
		}

		rwd := exp.NewResponseWriterDelegator(w)
		defer reportMetrics(rwd, r, nil, nil, began, "handleBucketList")

		respondBucketList(rwd, bs, began)
	}
}