2015-11-12 01:27:51 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-09-06 10:34:28 +00:00
|
|
|
cachetype "github.com/hashicorp/consul/agent/cache-types"
|
2017-07-06 10:34:00 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2015-11-12 01:27:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// preparedQueryCreateResponse is used to wrap the query ID.
|
|
|
|
type preparedQueryCreateResponse struct {
|
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// preparedQueryCreate makes a new prepared query.
|
|
|
|
func (s *HTTPServer) preparedQueryCreate(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
args := structs.PreparedQueryRequest{
|
|
|
|
Op: structs.PreparedQueryCreate,
|
|
|
|
}
|
|
|
|
s.parseDC(req, &args.Datacenter)
|
|
|
|
s.parseToken(req, &args.Token)
|
2019-10-29 18:13:36 +00:00
|
|
|
if err := decodeBody(req.Body, &args.Query); err != nil {
|
2018-01-10 17:33:49 +00:00
|
|
|
resp.WriteHeader(http.StatusBadRequest)
|
|
|
|
fmt.Fprintf(resp, "Request decode failed: %v", err)
|
|
|
|
return nil, nil
|
2015-11-17 17:16:04 +00:00
|
|
|
}
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
var reply string
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Apply", &args, &reply); err != nil {
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return preparedQueryCreateResponse{reply}, nil
|
|
|
|
}
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// preparedQueryList returns all the prepared queries.
|
|
|
|
func (s *HTTPServer) preparedQueryList(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
var args structs.DCSpecificRequest
|
|
|
|
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
var reply structs.IndexedPreparedQueries
|
2018-03-30 15:14:44 +00:00
|
|
|
defer setMeta(resp, &reply.QueryMeta)
|
|
|
|
RETRY_ONCE:
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.List", &args, &reply); err != nil {
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-03-30 15:14:44 +00:00
|
|
|
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < reply.LastContact {
|
|
|
|
args.AllowStale = false
|
|
|
|
args.MaxStaleDuration = 0
|
|
|
|
goto RETRY_ONCE
|
|
|
|
}
|
|
|
|
reply.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
|
2015-11-15 05:59:23 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// Use empty list instead of nil.
|
|
|
|
if reply.Queries == nil {
|
|
|
|
reply.Queries = make(structs.PreparedQueries, 0)
|
|
|
|
}
|
|
|
|
return reply.Queries, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PreparedQueryGeneral handles all the general prepared query requests.
|
|
|
|
func (s *HTTPServer) PreparedQueryGeneral(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
switch req.Method {
|
|
|
|
case "POST":
|
|
|
|
return s.preparedQueryCreate(resp, req)
|
|
|
|
|
|
|
|
case "GET":
|
|
|
|
return s.preparedQueryList(resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
|
|
|
|
default:
|
2017-09-26 06:11:19 +00:00
|
|
|
return nil, MethodNotAllowedError{req.Method, []string{"GET", "POST"}}
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parseLimit parses the optional limit parameter for a prepared query execution.
|
|
|
|
func parseLimit(req *http.Request, limit *int) error {
|
|
|
|
*limit = 0
|
|
|
|
if arg := req.URL.Query().Get("limit"); arg != "" {
|
2017-04-21 01:59:42 +00:00
|
|
|
i, err := strconv.Atoi(arg)
|
|
|
|
if err != nil {
|
2015-11-12 01:27:51 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-04-21 01:59:42 +00:00
|
|
|
*limit = i
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// preparedQueryExecute executes a prepared query.
|
|
|
|
func (s *HTTPServer) preparedQueryExecute(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
args := structs.PreparedQueryExecuteRequest{
|
|
|
|
QueryIDOrName: id,
|
2016-06-30 23:51:18 +00:00
|
|
|
Agent: structs.QuerySource{
|
|
|
|
Node: s.agent.config.NodeName,
|
|
|
|
Datacenter: s.agent.config.Datacenter,
|
2017-09-25 18:40:42 +00:00
|
|
|
Segment: s.agent.config.SegmentName,
|
2016-06-30 23:51:18 +00:00
|
|
|
},
|
2015-11-17 17:16:04 +00:00
|
|
|
}
|
|
|
|
s.parseSource(req, &args.Source)
|
|
|
|
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if err := parseLimit(req, &args.Limit); err != nil {
|
|
|
|
return nil, fmt.Errorf("Bad limit: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-06-05 23:04:50 +00:00
|
|
|
params := req.URL.Query()
|
|
|
|
if raw := params.Get("connect"); raw != "" {
|
|
|
|
val, err := strconv.ParseBool(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error parsing 'connect' value: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
args.Connect = val
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
var reply structs.PreparedQueryExecuteResponse
|
2018-03-30 15:14:44 +00:00
|
|
|
defer setMeta(resp, &reply.QueryMeta)
|
2018-09-06 10:34:28 +00:00
|
|
|
|
2020-06-08 08:08:12 +00:00
|
|
|
if s.agent.config.HTTPUseCache && args.QueryOptions.UseCache {
|
2020-06-15 15:01:25 +00:00
|
|
|
raw, m, err := s.agent.cache.Get(req.Context(), cachetype.PreparedQueryName, &args)
|
2018-09-06 10:34:28 +00:00
|
|
|
if err != nil {
|
|
|
|
// Don't return error if StaleIfError is set and we are within it and had
|
|
|
|
// a cached value.
|
|
|
|
if raw != nil && m.Hit && args.QueryOptions.StaleIfError > m.Age {
|
|
|
|
// Fall through to the happy path below
|
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer setCacheMeta(resp, &m)
|
|
|
|
r, ok := raw.(*structs.PreparedQueryExecuteResponse)
|
|
|
|
if !ok {
|
|
|
|
// This should never happen, but we want to protect against panics
|
|
|
|
return nil, fmt.Errorf("internal error: response type not correct")
|
|
|
|
}
|
|
|
|
reply = *r
|
|
|
|
} else {
|
|
|
|
RETRY_ONCE:
|
|
|
|
if err := s.agent.RPC("PreparedQuery.Execute", &args, &reply); err != nil {
|
|
|
|
// We have to check the string since the RPC sheds
|
|
|
|
// the specific error type.
|
2020-07-01 13:12:59 +00:00
|
|
|
if structs.IsErrQueryNotFound(err) {
|
2018-09-06 10:34:28 +00:00
|
|
|
resp.WriteHeader(http.StatusNotFound)
|
|
|
|
fmt.Fprint(resp, err.Error())
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < reply.LastContact {
|
|
|
|
args.AllowStale = false
|
|
|
|
args.MaxStaleDuration = 0
|
|
|
|
goto RETRY_ONCE
|
2015-11-17 17:16:04 +00:00
|
|
|
}
|
2018-03-30 15:14:44 +00:00
|
|
|
}
|
|
|
|
reply.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
|
2015-11-17 17:16:04 +00:00
|
|
|
|
2016-08-15 22:05:02 +00:00
|
|
|
// Note that we translate using the DC that the results came from, since
|
|
|
|
// a query can fail over to a different DC than where the execute request
|
|
|
|
// was sent to. That's why we use the reply's DC and not the one from
|
|
|
|
// the args.
|
2020-01-17 14:54:17 +00:00
|
|
|
s.agent.TranslateAddresses(reply.Datacenter, reply.Nodes, TranslateAddressAcceptAny)
|
2016-08-15 22:05:02 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// Use empty list instead of nil.
|
|
|
|
if reply.Nodes == nil {
|
|
|
|
reply.Nodes = make(structs.CheckServiceNodes, 0)
|
|
|
|
}
|
|
|
|
return reply, nil
|
|
|
|
}
|
|
|
|
|
2016-03-04 01:30:36 +00:00
|
|
|
// preparedQueryExplain shows which query a name resolves to, the fully
|
|
|
|
// interpolated template (if it's a template), as well as additional info
|
|
|
|
// about the execution of a query.
|
|
|
|
func (s *HTTPServer) preparedQueryExplain(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2016-03-03 09:04:12 +00:00
|
|
|
args := structs.PreparedQueryExecuteRequest{
|
|
|
|
QueryIDOrName: id,
|
2016-06-30 23:51:18 +00:00
|
|
|
Agent: structs.QuerySource{
|
|
|
|
Node: s.agent.config.NodeName,
|
|
|
|
Datacenter: s.agent.config.Datacenter,
|
2017-09-25 18:40:42 +00:00
|
|
|
Segment: s.agent.config.SegmentName,
|
2016-06-30 23:51:18 +00:00
|
|
|
},
|
2016-03-03 09:04:12 +00:00
|
|
|
}
|
2016-03-04 01:30:36 +00:00
|
|
|
s.parseSource(req, &args.Source)
|
2016-03-03 09:04:12 +00:00
|
|
|
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2016-03-04 01:30:36 +00:00
|
|
|
if err := parseLimit(req, &args.Limit); err != nil {
|
|
|
|
return nil, fmt.Errorf("Bad limit: %s", err)
|
|
|
|
}
|
2016-03-03 09:04:12 +00:00
|
|
|
|
2016-03-04 01:30:36 +00:00
|
|
|
var reply structs.PreparedQueryExplainResponse
|
2018-03-30 15:14:44 +00:00
|
|
|
defer setMeta(resp, &reply.QueryMeta)
|
|
|
|
RETRY_ONCE:
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Explain", &args, &reply); err != nil {
|
2016-03-03 09:04:12 +00:00
|
|
|
// We have to check the string since the RPC sheds
|
|
|
|
// the specific error type.
|
2020-07-01 13:12:59 +00:00
|
|
|
if structs.IsErrQueryNotFound(err) {
|
2017-08-23 19:19:11 +00:00
|
|
|
resp.WriteHeader(http.StatusNotFound)
|
Use fmt.Fprint/Fprintf/Fprintln
Used the following rewrite rules:
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c, d))) -> fmt.Fprintf(resp, a, b, c, d)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c))) -> fmt.Fprintf(resp, a, b, c)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b))) -> fmt.Fprintf(resp, a, b)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a))) -> fmt.Fprint(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a + "\n")) -> fmt.Fprintln(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a)) -> fmt.Fprint(resp, a)' *.go
2017-04-20 14:07:42 +00:00
|
|
|
fmt.Fprint(resp, err.Error())
|
2016-03-03 09:04:12 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-03-30 15:14:44 +00:00
|
|
|
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < reply.LastContact {
|
|
|
|
args.AllowStale = false
|
|
|
|
args.MaxStaleDuration = 0
|
|
|
|
goto RETRY_ONCE
|
|
|
|
}
|
|
|
|
reply.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
|
2016-03-03 09:04:12 +00:00
|
|
|
return reply, nil
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// preparedQueryGet returns a single prepared query.
|
|
|
|
func (s *HTTPServer) preparedQueryGet(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
args := structs.PreparedQuerySpecificRequest{
|
|
|
|
QueryID: id,
|
|
|
|
}
|
|
|
|
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var reply structs.IndexedPreparedQueries
|
2018-03-30 15:14:44 +00:00
|
|
|
defer setMeta(resp, &reply.QueryMeta)
|
|
|
|
RETRY_ONCE:
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Get", &args, &reply); err != nil {
|
2015-11-17 17:16:04 +00:00
|
|
|
// We have to check the string since the RPC sheds
|
|
|
|
// the specific error type.
|
2020-07-01 13:12:59 +00:00
|
|
|
if structs.IsErrQueryNotFound(err) {
|
2017-08-23 19:19:11 +00:00
|
|
|
resp.WriteHeader(http.StatusNotFound)
|
Use fmt.Fprint/Fprintf/Fprintln
Used the following rewrite rules:
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c, d))) -> fmt.Fprintf(resp, a, b, c, d)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c))) -> fmt.Fprintf(resp, a, b, c)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b))) -> fmt.Fprintf(resp, a, b)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a))) -> fmt.Fprint(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a + "\n")) -> fmt.Fprintln(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a)) -> fmt.Fprint(resp, a)' *.go
2017-04-20 14:07:42 +00:00
|
|
|
fmt.Fprint(resp, err.Error())
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-03-30 15:14:44 +00:00
|
|
|
if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < reply.LastContact {
|
|
|
|
args.AllowStale = false
|
|
|
|
args.MaxStaleDuration = 0
|
|
|
|
goto RETRY_ONCE
|
|
|
|
}
|
|
|
|
reply.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
|
2015-11-17 17:16:04 +00:00
|
|
|
return reply.Queries, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// preparedQueryUpdate updates a prepared query.
|
|
|
|
func (s *HTTPServer) preparedQueryUpdate(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
args := structs.PreparedQueryRequest{
|
|
|
|
Op: structs.PreparedQueryUpdate,
|
|
|
|
}
|
|
|
|
s.parseDC(req, &args.Datacenter)
|
|
|
|
s.parseToken(req, &args.Token)
|
|
|
|
if req.ContentLength > 0 {
|
2019-10-29 18:13:36 +00:00
|
|
|
if err := decodeBody(req.Body, &args.Query); err != nil {
|
2017-08-23 19:19:11 +00:00
|
|
|
resp.WriteHeader(http.StatusBadRequest)
|
Use fmt.Fprint/Fprintf/Fprintln
Used the following rewrite rules:
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c, d))) -> fmt.Fprintf(resp, a, b, c, d)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b, c))) -> fmt.Fprintf(resp, a, b, c)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a, b))) -> fmt.Fprintf(resp, a, b)' *.go
gofmt -w -r 'resp.Write([]byte(fmt.Sprintf(a))) -> fmt.Fprint(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a + "\n")) -> fmt.Fprintln(resp, a)' *.go
gofmt -w -r 'resp.Write([]byte(a)) -> fmt.Fprint(resp, a)' *.go
2017-04-20 14:07:42 +00:00
|
|
|
fmt.Fprintf(resp, "Request decode failed: %v", err)
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
if args.Query == nil {
|
|
|
|
args.Query = &structs.PreparedQuery{}
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// Take the ID from the URL, not the embedded one.
|
|
|
|
args.Query.ID = id
|
|
|
|
|
|
|
|
var reply string
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Apply", &args, &reply); err != nil {
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// preparedQueryDelete deletes prepared query.
|
|
|
|
func (s *HTTPServer) preparedQueryDelete(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
args := structs.PreparedQueryRequest{
|
|
|
|
Op: structs.PreparedQueryDelete,
|
|
|
|
Query: &structs.PreparedQuery{
|
|
|
|
ID: id,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s.parseDC(req, &args.Datacenter)
|
|
|
|
s.parseToken(req, &args.Token)
|
|
|
|
|
|
|
|
var reply string
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Apply", &args, &reply); err != nil {
|
2015-11-17 17:16:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-02-18 01:33:21 +00:00
|
|
|
// PreparedQuerySpecificOptions handles OPTIONS requests to prepared query endpoints.
|
|
|
|
func (s *HTTPServer) preparedQuerySpecificOptions(resp http.ResponseWriter, req *http.Request) interface{} {
|
|
|
|
path := req.URL.Path
|
|
|
|
switch {
|
|
|
|
case strings.HasSuffix(path, "/execute"):
|
|
|
|
resp.Header().Add("Allow", strings.Join([]string{"OPTIONS", "GET"}, ","))
|
|
|
|
return resp
|
|
|
|
|
|
|
|
case strings.HasSuffix(path, "/explain"):
|
|
|
|
resp.Header().Add("Allow", strings.Join([]string{"OPTIONS", "GET"}, ","))
|
|
|
|
return resp
|
|
|
|
|
|
|
|
default:
|
|
|
|
resp.Header().Add("Allow", strings.Join([]string{"OPTIONS", "GET", "PUT", "DELETE"}, ","))
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
// PreparedQuerySpecific handles all the prepared query requests specific to a
|
2015-11-12 01:27:51 +00:00
|
|
|
// particular query.
|
|
|
|
func (s *HTTPServer) PreparedQuerySpecific(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2018-02-18 01:33:21 +00:00
|
|
|
if req.Method == "OPTIONS" {
|
|
|
|
return s.preparedQuerySpecificOptions(resp, req), nil
|
|
|
|
}
|
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
path := req.URL.Path
|
|
|
|
id := strings.TrimPrefix(path, "/v1/query/")
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
switch {
|
|
|
|
case strings.HasSuffix(path, "/execute"):
|
|
|
|
if req.Method != "GET" {
|
|
|
|
return nil, MethodNotAllowedError{req.Method, []string{"GET"}}
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
2017-09-26 06:11:19 +00:00
|
|
|
id = strings.TrimSuffix(id, "/execute")
|
|
|
|
return s.preparedQueryExecute(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
case strings.HasSuffix(path, "/explain"):
|
|
|
|
if req.Method != "GET" {
|
|
|
|
return nil, MethodNotAllowedError{req.Method, []string{"GET"}}
|
|
|
|
}
|
|
|
|
id = strings.TrimSuffix(id, "/explain")
|
|
|
|
return s.preparedQueryExplain(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
|
|
|
|
default:
|
2017-09-26 06:11:19 +00:00
|
|
|
switch req.Method {
|
|
|
|
case "GET":
|
|
|
|
return s.preparedQueryGet(id, resp, req)
|
|
|
|
|
|
|
|
case "PUT":
|
|
|
|
return s.preparedQueryUpdate(id, resp, req)
|
|
|
|
|
|
|
|
case "DELETE":
|
|
|
|
return s.preparedQueryDelete(id, resp, req)
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nil, MethodNotAllowedError{req.Method, []string{"GET", "PUT", "DELETE"}}
|
|
|
|
}
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
|
|
|
}
|