add create command

This commit is contained in:
Victor Vieux 2014-11-18 01:34:08 +00:00
parent 05e95dfc7e
commit 45ca8472f1
2 changed files with 28 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package discovery
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
) )
@ -38,3 +39,13 @@ func RegisterSlave(addr, token string) error {
_, err := http.Post(fmt.Sprintf("%s/%s/%s", DISCOVERY_URL, "clusters", token), "application/json", buf) _, err := http.Post(fmt.Sprintf("%s/%s/%s", DISCOVERY_URL, "clusters", token), "application/json", buf)
return err return err
} }
// CreateCluster returns a unique cluster token
func CreateCluster() (string, error) {
resp, err := http.Post(fmt.Sprintf("%s/%s", DISCOVERY_URL, "clusters"), "", nil)
if err != nil {
return "", err
}
token, err := ioutil.ReadAll(resp.Body)
return string(token), err
}

18
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"os" "os"
"time" "time"
@ -60,6 +61,19 @@ func main() {
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{
Name: "create",
ShortName: "c",
Usage: "create a cluster",
Action: func(c *cli.Context) {
token, err := discovery.CreateCluster()
if err != nil {
log.Fatal(err)
}
fmt.Println(token)
},
},
{ {
Name: "manage", Name: "manage",
ShortName: "m", ShortName: "m",
@ -144,5 +158,7 @@ func main() {
}, },
} }
log.Fatal(app.Run(os.Args)) if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
} }