// test read func TestRead(t *testing.T) { reader, err := backends.Read("testfile") if err != nil { t.Error("Failed to READ file - ", err) } data, _ := ioutil.ReadAll(reader) if string(data) != "testdata" { t.Errorf("Failed to READ file - incorrect contents: %s", data) } }
// get returns the data corresponding to specified key func get(rw http.ResponseWriter, req *http.Request) { // r, err := backends.Read(req.URL.Query().Get(":blob")) if err != nil { rw.WriteHeader(404) rw.Write([]byte(fmt.Sprintf("%s\n", err.Error()))) return } defer r.Close() // close the file // pipe the file rather than consume the rams _, err = io.Copy(rw, r) if err != nil { rw.WriteHeader(500) rw.Write([]byte(fmt.Sprintf("%s\n", err.Error()))) return } }