2015-02-15 01:33:21 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2015-04-27 23:21:56 +02:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
|
|
|
"text/template"
|
2015-02-15 01:33:21 +02:00
|
|
|
|
2015-04-27 23:21:56 +02:00
|
|
|
"github.com/codegangsta/cli"
|
2015-05-05 20:05:06 +02:00
|
|
|
"github.com/myodc/go-micro/registry"
|
|
|
|
"github.com/myodc/go-micro/server"
|
|
|
|
"github.com/myodc/go-micro/store"
|
2015-02-15 01:33:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-04-27 23:21:56 +02:00
|
|
|
Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{Name: "bind_address", Value: ":0", Usage: "Bind address for the server. 127.0.0.1:8080"},
|
|
|
|
cli.StringFlag{Name: "registry", Value: "consul", Usage: "Registry for discovery. kubernetes, consul, etc"},
|
|
|
|
cli.StringFlag{Name: "store", Value: "consul", Usage: "Store used as a basic key/value store using consul, memcached, etc"},
|
|
|
|
}
|
2015-02-15 01:33:21 +02:00
|
|
|
)
|
|
|
|
|
2015-04-27 23:21:56 +02:00
|
|
|
func Setup(c *cli.Context) error {
|
|
|
|
server.Address = c.String("bind_address")
|
2015-02-15 01:33:21 +02:00
|
|
|
|
2015-04-27 23:21:56 +02:00
|
|
|
switch c.String("registry") {
|
2015-02-15 01:33:21 +02:00
|
|
|
case "kubernetes":
|
|
|
|
registry.DefaultRegistry = registry.NewKubernetesRegistry()
|
|
|
|
}
|
|
|
|
|
2015-04-27 23:21:56 +02:00
|
|
|
switch c.String("store") {
|
2015-02-15 01:33:21 +02:00
|
|
|
case "memcached":
|
|
|
|
store.DefaultStore = store.NewMemcacheStore()
|
2015-03-06 21:08:55 +02:00
|
|
|
case "memory":
|
|
|
|
store.DefaultStore = store.NewMemoryStore()
|
2015-03-06 20:59:24 +02:00
|
|
|
case "etcd":
|
|
|
|
store.DefaultStore = store.NewEtcdStore()
|
2015-02-15 01:33:21 +02:00
|
|
|
}
|
2015-04-27 23:21:56 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
cli.AppHelpTemplate = `
|
|
|
|
GLOBAL OPTIONS:
|
|
|
|
{{range .Flags}}{{.}}
|
|
|
|
{{end}}
|
|
|
|
`
|
|
|
|
|
|
|
|
cli.HelpPrinter = func(templ string, data interface{}) {
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
|
|
|
t := template.Must(template.New("help").Parse(templ))
|
|
|
|
err := t.Execute(w, data)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.HideVersion = true
|
|
|
|
app.Usage = "a go micro app"
|
|
|
|
app.Action = func(c *cli.Context) {}
|
|
|
|
app.Before = Setup
|
|
|
|
app.Flags = Flags
|
|
|
|
app.RunAndExitOnError()
|
2015-02-15 01:33:21 +02:00
|
|
|
}
|