2015-11-12 01:27:51 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
pkg refactor
command/agent/* -> agent/*
command/consul/* -> agent/consul/*
command/agent/command{,_test}.go -> command/agent{,_test}.go
command/base/command.go -> command/base.go
command/base/* -> command/*
commands.go -> command/commands.go
The script which did the refactor is:
(
cd $GOPATH/src/github.com/hashicorp/consul
git mv command/agent/command.go command/agent.go
git mv command/agent/command_test.go command/agent_test.go
git mv command/agent/flag_slice_value{,_test}.go command/
git mv command/agent .
git mv command/base/command.go command/base.go
git mv command/base/config_util{,_test}.go command/
git mv commands.go command/
git mv consul agent
rmdir command/base/
gsed -i -e 's|package agent|package command|' command/agent{,_test}.go
gsed -i -e 's|package agent|package command|' command/flag_slice_value{,_test}.go
gsed -i -e 's|package base|package command|' command/base.go command/config_util{,_test}.go
gsed -i -e 's|package main|package command|' command/commands.go
gsed -i -e 's|base.Command|BaseCommand|' command/commands.go
gsed -i -e 's|agent.Command|AgentCommand|' command/commands.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/commands.go
gsed -i -e 's|base\.||' command/commands.go
gsed -i -e 's|command\.||' command/commands.go
gsed -i -e 's|command|c|' main.go
gsed -i -e 's|range Commands|range command.Commands|' main.go
gsed -i -e 's|Commands: Commands|Commands: command.Commands|' main.go
gsed -i -e 's|base\.BoolValue|BoolValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.DurationValue|DurationValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.StringValue|StringValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.UintValue|UintValue|' command/operator_autopilot_set.go
gsed -i -e 's|\bCommand\b|BaseCommand|' command/base.go
gsed -i -e 's|BaseCommand Options|Command Options|' command/base.go
gsed -i -e 's|base.Command|BaseCommand|' command/*.go
gsed -i -e 's|c\.Command|c.BaseCommand|g' command/*.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/*_test.go
gsed -i -e 's|base\.||' command/*_test.go
gsed -i -e 's|\bCommand\b|AgentCommand|' command/agent{,_test}.go
gsed -i -e 's|cmd.AgentCommand|cmd.BaseCommand|' command/agent.go
gsed -i -e 's|cli.AgentCommand = new(Command)|cli.Command = new(AgentCommand)|' command/agent_test.go
gsed -i -e 's|exec.AgentCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|exec.BaseCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|NewTestAgent|agent.NewTestAgent|' command/agent_test.go
gsed -i -e 's|= TestConfig|= agent.TestConfig|' command/agent_test.go
gsed -i -e 's|: RetryJoin|: agent.RetryJoin|' command/agent_test.go
gsed -i -e 's|\.\./\.\./|../|' command/config_util_test.go
gsed -i -e 's|\bverifyUniqueListeners|VerifyUniqueListeners|' agent/config{,_test}.go command/agent.go
gsed -i -e 's|\bserfLANKeyring\b|SerfLANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bserfWANKeyring\b|SerfWANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bNewAgent\b|agent.New|g' command/agent{,_test}.go
gsed -i -e 's|\bNewAgent|New|' agent/{acl_test,agent,testagent}.go
gsed -i -e 's|\bAgent\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bBool\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDefaultConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDevConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bMergeConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bReadConfigPaths\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bParseMetaPair\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfLANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfWANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|circonus\.agent|circonus|g' command/agent{,_test}.go
gsed -i -e 's|logger\.agent|logger|g' command/agent{,_test}.go
gsed -i -e 's|metrics\.agent|metrics|g' command/agent{,_test}.go
gsed -i -e 's|// agent.Agent|// agent|' command/agent{,_test}.go
gsed -i -e 's|a\.agent\.Config|a.Config|' command/agent{,_test}.go
gsed -i -e 's|agent\.AppendSliceValue|AppendSliceValue|' command/{configtest,validate}.go
gsed -i -e 's|consul/consul|agent/consul|' GNUmakefile
gsed -i -e 's|\.\./test|../../test|' agent/consul/server_test.go
# fix imports
f=$(grep -rl 'github.com/hashicorp/consul/command/agent' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/command/agent|github.com/hashicorp/consul/agent|' $f
goimports -w $f
f=$(grep -rl 'github.com/hashicorp/consul/consul' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/consul|github.com/hashicorp/consul/agent/consul|' $f
goimports -w $f
goimports -w command/*.go main.go
)
2017-06-09 22:28:28 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul"
|
2017-07-06 10:34:00 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2015-11-12 01:27:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
preparedQueryExecuteSuffix = "/execute"
|
2016-03-04 01:30:36 +00:00
|
|
|
preparedQueryExplainSuffix = "/explain"
|
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)
|
|
|
|
if req.ContentLength > 0 {
|
|
|
|
if err := decodeBody(req, &args.Query, nil); err != nil {
|
|
|
|
resp.WriteHeader(400)
|
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
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
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
|
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
|
|
|
|
}
|
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:
|
|
|
|
resp.WriteHeader(405)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
},
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
var reply structs.PreparedQueryExecuteResponse
|
2017-06-16 07:54:09 +00:00
|
|
|
if err := s.agent.RPC("PreparedQuery.Execute", &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.
|
|
|
|
if err.Error() == consul.ErrQueryNotFound.Error() {
|
|
|
|
resp.WriteHeader(404)
|
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
|
|
|
|
}
|
|
|
|
|
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.
|
2017-06-30 19:42:53 +00:00
|
|
|
s.agent.TranslateAddresses(reply.Datacenter, reply.Nodes)
|
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,
|
|
|
|
},
|
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
|
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.
|
|
|
|
if err.Error() == consul.ErrQueryNotFound.Error() {
|
|
|
|
resp.WriteHeader(404)
|
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
|
|
|
|
}
|
|
|
|
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
|
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.
|
|
|
|
if err.Error() == consul.ErrQueryNotFound.Error() {
|
|
|
|
resp.WriteHeader(404)
|
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
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
if err := decodeBody(req, &args.Query, nil); err != nil {
|
|
|
|
resp.WriteHeader(400)
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
id := strings.TrimPrefix(req.URL.Path, "/v1/query/")
|
2016-03-03 09:04:12 +00:00
|
|
|
|
2016-03-04 01:30:36 +00:00
|
|
|
execute, explain := false, false
|
2015-11-12 01:27:51 +00:00
|
|
|
if strings.HasSuffix(id, preparedQueryExecuteSuffix) {
|
|
|
|
execute = true
|
|
|
|
id = strings.TrimSuffix(id, preparedQueryExecuteSuffix)
|
2016-03-04 01:30:36 +00:00
|
|
|
} else if strings.HasSuffix(id, preparedQueryExplainSuffix) {
|
|
|
|
explain = true
|
|
|
|
id = strings.TrimSuffix(id, preparedQueryExplainSuffix)
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch req.Method {
|
2015-11-17 17:16:04 +00:00
|
|
|
case "GET":
|
2015-11-12 01:27:51 +00:00
|
|
|
if execute {
|
2015-11-17 17:16:04 +00:00
|
|
|
return s.preparedQueryExecute(id, resp, req)
|
2016-03-04 01:30:36 +00:00
|
|
|
} else if explain {
|
|
|
|
return s.preparedQueryExplain(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
} else {
|
2015-11-17 17:16:04 +00:00
|
|
|
return s.preparedQueryGet(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
case "PUT":
|
|
|
|
return s.preparedQueryUpdate(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
|
2015-11-17 17:16:04 +00:00
|
|
|
case "DELETE":
|
|
|
|
return s.preparedQueryDelete(id, resp, req)
|
2015-11-12 01:27:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
resp.WriteHeader(405)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|