Beispiel #1
0
func BlockHandler(store fs.LocalStore) http.HandlerFunc {
	return func(resp http.ResponseWriter, req *http.Request) {
		setBinaryResp(resp)

		strong, hasVar := mux.Vars(req)["strong"]
		if !hasVar {
			writeResponseError(resp, http.StatusInternalServerError,
				"Missing parameter: strong")
			return
		}

		if !hasVar {
			resp.WriteHeader(http.StatusNotFound)
			return
		}

		buf, err := store.ReadBlock(strong)
		if err != nil {
			writeResponseError(resp, http.StatusInternalServerError, err.String())
			return
		}

		resp.Write(buf)
	}
}