2018-05-11 04:08:20 +00:00
|
|
|
package control
|
|
|
|
|
2018-05-11 06:28:31 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/cretz/bine/util"
|
|
|
|
)
|
2018-05-11 04:08:20 +00:00
|
|
|
|
|
|
|
func (c *Conn) Signal(signal string) error {
|
2018-05-11 06:28:31 +00:00
|
|
|
return c.sendRequestIgnoreResponse("SIGNAL %v", signal)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) Quit() error {
|
|
|
|
return c.sendRequestIgnoreResponse("QUIT")
|
2018-05-11 04:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:58 +00:00
|
|
|
func (c *Conn) MapAddresses(addresses ...*KeyVal) ([]*KeyVal, error) {
|
2018-05-11 04:08:20 +00:00
|
|
|
cmd := "MAPADDRESS"
|
|
|
|
for _, address := range addresses {
|
2018-05-11 19:43:58 +00:00
|
|
|
cmd += " " + address.Key + "=" + address.Val
|
2018-05-11 04:08:20 +00:00
|
|
|
}
|
|
|
|
resp, err := c.SendRequest(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
data := resp.DataWithReply()
|
2018-05-11 19:43:58 +00:00
|
|
|
ret := make([]*KeyVal, 0, len(data))
|
2018-05-11 04:08:20 +00:00
|
|
|
for _, address := range data {
|
2018-05-11 19:43:58 +00:00
|
|
|
mappedAddress := &KeyVal{}
|
|
|
|
mappedAddress.Key, mappedAddress.Val, _ = util.PartitionString(address, '=')
|
2018-05-11 04:08:20 +00:00
|
|
|
ret = append(ret, mappedAddress)
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
2018-05-11 06:28:31 +00:00
|
|
|
|
2018-05-11 19:43:58 +00:00
|
|
|
func (c *Conn) GetInfo(keys ...string) ([]*KeyVal, error) {
|
2018-05-11 17:34:33 +00:00
|
|
|
resp, err := c.SendRequest("GETINFO %v", strings.Join(keys, " "))
|
2018-05-11 06:28:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-05-11 19:43:58 +00:00
|
|
|
ret := make([]*KeyVal, 0, len(resp.Data))
|
2018-05-11 06:28:31 +00:00
|
|
|
for _, val := range resp.Data {
|
2018-05-11 19:43:58 +00:00
|
|
|
infoVal := &KeyVal{}
|
|
|
|
infoVal.Key, infoVal.Val, _ = util.PartitionString(val, '=')
|
2018-05-11 06:28:31 +00:00
|
|
|
ret = append(ret, infoVal)
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) PostDescriptor(descriptor string, purpose string, cache string) error {
|
|
|
|
cmd := "+POSTDESCRIPTOR"
|
|
|
|
if purpose != "" {
|
|
|
|
cmd += " purpose=" + purpose
|
|
|
|
}
|
|
|
|
if cache != "" {
|
|
|
|
cmd += " cache=" + cache
|
|
|
|
}
|
|
|
|
cmd += "\r\n" + descriptor + "\r\n."
|
|
|
|
return c.sendRequestIgnoreResponse(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) UseFeatures(features ...string) error {
|
|
|
|
return c.sendRequestIgnoreResponse("USEFEATURE " + strings.Join(features, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: can this take multiple
|
|
|
|
func (c *Conn) ResolveAsync(address string, reverse bool) error {
|
|
|
|
cmd := "RESOLVE "
|
|
|
|
if reverse {
|
|
|
|
cmd += "mode=reverse "
|
|
|
|
}
|
|
|
|
return c.sendRequestIgnoreResponse(cmd + address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) TakeOwnership() error {
|
|
|
|
return c.sendRequestIgnoreResponse("TAKEOWNERSHIP")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) DropGuards() error {
|
|
|
|
return c.sendRequestIgnoreResponse("DROPGUARDS")
|
|
|
|
}
|