Пример #1
0
func FileHandler(store fs.LocalStore) http.HandlerFunc {
	return func(resp http.ResponseWriter, req *http.Request) {
		setBinaryResp(resp)

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

		offsetStr, hasOffset := mux.Vars(req)["offset"]
		if !hasOffset {
			writeResponseError(resp, http.StatusInternalServerError,
				"Missing parameter: offset")
			return
		}
		offset, err := strconv.Atoi64(offsetStr)
		if err != nil {
			writeResponseError(resp, http.StatusInternalServerError,
				fmt.Sprintf("Invalid format for length: %s", offsetStr))
			return
		}

		lengthStr, hasLength := mux.Vars(req)["length"]
		if !hasLength {
			writeResponseError(resp, http.StatusInternalServerError,
				"Missing parameter: length")
			return
		}
		length, err := strconv.Atoi64(lengthStr)
		if err != nil {
			writeResponseError(resp, http.StatusInternalServerError,
				fmt.Sprintf("Invalid format for length: %s", lengthStr))
			return
		}

		buffer := bytes.NewBuffer([]byte{})
		n, err := store.ReadInto(strong, offset, length, buffer)
		if err != nil {
			writeResponseError(resp, http.StatusInternalServerError, err.String())
			return
		}
		if n < length {
			writeResponseError(resp, http.StatusInternalServerError, io.ErrShortWrite.String())
		}

		resp.Write(buffer.Bytes())
	}
}
Пример #2
0
func RetrieveProcess(res http.ResponseWriter, req *http.Request) {
	if p := proc[mux.Vars(req)["id"]]; p != nil {
		RespondJSON(res, p)
	} else {
		res.WriteHeader(http.StatusNotFound)
	}
}
Пример #3
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)
	}
}
Пример #4
0
func (hp Homepage) GetPerson(req *http.Request) []byte {
	p := mux.Vars(req)["person"]

	person := Person{}
	person.GetByName(p)

	return []byte(fmt.Sprintf(`{person:"%s"}`, person.Email))
}
Пример #5
0
func (this *Router) MatchRequest(request *httpcontext.Request) mux.RouteVars {
	rawRequest := request.Request
	if match, ok := this.Match(rawRequest); ok {
		defer context.DefaultContext.Clear(rawRequest)
		params := mux.Vars(rawRequest)
		params[httpcontext.ROUTE_PARAM] = match.Route.GetName()
		return params
	}

	panic("No match found")
}
Пример #6
0
func FeedProcess(res http.ResponseWriter, req *http.Request) {
	if p := proc[mux.Vars(req)["id"]]; p != nil {
		body := make([]byte, 4096)
		if _, err := req.Body.Read(body); err == nil {
			body = bytes.TrimRight(body, string([]byte{0}))
			p.Write(body)
			//if err := p.Write(body); err == nil {
			RespondJSON(res, true)
			//}
		}
	} else {
		res.WriteHeader(http.StatusNotFound)
	}
}
Пример #7
0
func helloHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("Content-Type", "text/html")
	vars := mux.Vars(r)
	fmt.Fprintf(w, "%s, %s!", vars["salutation"], vars["name"])
}
Пример #8
0
func (hp Homepage) GetPerson(req *http.Request) []byte {
	p := mux.Vars(req)["person"]
	return []byte("{person:" + p + "}")
}