12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package v1
- import (
- "net/http"
- "strconv"
- "strings"
- "devt.de/krotik/eliasdb/api"
- )
- const APIv1 = "/v1"
- const HTTPHeaderTotalCount = "X-Total-Count"
- const HTTPHeaderCacheID = "X-Cache-Id"
- var V1EndpointMap = map[string]api.RestEndpointInst{
- EndpointBlob: BlobEndpointInst,
- EndpointClusterQuery: ClusterEndpointInst,
- EndpointEql: EqlEndpointInst,
- EndpointGraph: GraphEndpointInst,
- EndpointGraphQL: GraphQLEndpointInst,
- EndpointGraphQLQuery: GraphQLQueryEndpointInst,
- EndpointGraphQLSubscriptions: GraphQLSubscriptionsEndpointInst,
- EndpointIndexQuery: IndexEndpointInst,
- EndpointFindQuery: FindEndpointInst,
- EndpointInfoQuery: InfoEndpointInst,
- EndpointQuery: QueryEndpointInst,
- EndpointQueryResult: QueryResultEndpointInst,
- }
- func checkResources(w http.ResponseWriter, resources []string, requiredMin int, requiredMax int, errorMsg string) bool {
- if len(resources) < requiredMin {
- http.Error(w, errorMsg, http.StatusBadRequest)
- return false
- } else if len(resources) > requiredMax {
- http.Error(w, "Invalid resource specification: "+strings.Join(resources[1:], "/"), http.StatusBadRequest)
- return false
- }
- return true
- }
- func queryParamPosNum(w http.ResponseWriter, r *http.Request, param string) (int, bool) {
- val := r.URL.Query().Get(param)
- if val == "" {
- return -1, true
- }
- num, err := strconv.Atoi(val)
- if err != nil || num < 0 {
- http.Error(w, "Invalid parameter value: "+param+" should be a positive integer number", http.StatusBadRequest)
- return -1, false
- }
- return num, true
- }
|