command/connect/proxy: can specify prepared query upstream types
This commit is contained in:
parent
4f8fbd53d3
commit
692f1ef357
|
@ -34,6 +34,23 @@ func (f *FlagUpstreams) Set(value string) error {
|
||||||
portRaw = portRaw[idx+1:]
|
portRaw = portRaw[idx+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destinationType := "service"
|
||||||
|
if idx := strings.Index(name, "."); idx != -1 {
|
||||||
|
typ := name[idx+1:]
|
||||||
|
name = name[:idx]
|
||||||
|
switch typ {
|
||||||
|
case "", "service":
|
||||||
|
destinationType = "service"
|
||||||
|
|
||||||
|
case "query":
|
||||||
|
destinationType = "prepared_query"
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf(
|
||||||
|
"Upstream type must be blank, 'service', or 'query'. Got: %q", typ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
port, err := strconv.ParseInt(portRaw, 0, 0)
|
port, err := strconv.ParseInt(portRaw, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -47,7 +64,7 @@ func (f *FlagUpstreams) Set(value string) error {
|
||||||
LocalBindAddress: addr,
|
LocalBindAddress: addr,
|
||||||
LocalBindPort: int(port),
|
LocalBindPort: int(port),
|
||||||
DestinationName: name,
|
DestinationName: name,
|
||||||
DestinationType: "service",
|
DestinationType: destinationType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -53,6 +53,26 @@ func TestFlagUpstreams(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"single value prepared query",
|
||||||
|
[]string{"db.query:8181"},
|
||||||
|
map[string]proxy.UpstreamConfig{
|
||||||
|
"db": proxy.UpstreamConfig{
|
||||||
|
LocalBindPort: 8181,
|
||||||
|
DestinationName: "db",
|
||||||
|
DestinationType: "prepared_query",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"invalid type",
|
||||||
|
[]string{"db.bad:8181"},
|
||||||
|
nil,
|
||||||
|
"Upstream type",
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"address specified",
|
"address specified",
|
||||||
[]string{"db:127.0.0.55:8181"},
|
[]string{"db:127.0.0.55:8181"},
|
||||||
|
|
Loading…
Reference in New Issue