forked from vulcand/vulcand
/
listener.go
48 lines (44 loc) · 1.51 KB
/
listener.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package command
import (
"github.com/mailgun/vulcand/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/mailgun/vulcand/backend"
)
func NewListenerCommand(cmd *Command) cli.Command {
return cli.Command{
Name: "listener",
Usage: "Operations with vulcan listeners",
Subcommands: []cli.Command{
{
Name: "add",
Usage: "Add a new listener to host",
Flags: append([]cli.Flag{
cli.StringFlag{Name: "id", Usage: "id, autogenerated if empty"},
cli.StringFlag{Name: "host", Usage: "parent host"},
cli.StringFlag{Name: "proto", Usage: "protocol, either http or https"},
cli.StringFlag{Name: "net", Value: "tcp", Usage: "network, tcp or unix"},
cli.StringFlag{Name: "addr", Value: "tcp", Usage: "address to bind to, e.g. 'localhost:31000'"},
}, locationOptions()...),
Action: cmd.addListenerAction,
},
{
Name: "rm",
Usage: "Remove a listener from host",
Action: cmd.deleteListenerAction,
Flags: []cli.Flag{
cli.StringFlag{Name: "id", Usage: "id"},
cli.StringFlag{Name: "host", Usage: "parent host"},
},
},
},
}
}
func (cmd *Command) addListenerAction(c *cli.Context) {
listener, err := backend.NewListener(c.String("id"), c.String("proto"), c.String("net"), c.String("addr"))
if err != nil {
cmd.printError(err)
}
cmd.printStatus(cmd.client.AddHostListener(c.String("host"), listener))
}
func (cmd *Command) deleteListenerAction(c *cli.Context) {
cmd.printStatus(cmd.client.DeleteHostListener(c.String("host"), c.String("id")))
}