-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
77 lines (65 loc) · 1.45 KB
/
cli.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// shippy-user-cli/cli.go
package main
import (
"log"
"os"
"github.com/micro/cli"
"github.com/micro/go-micro"
"github.com/micro/go-micro/cmd"
"golang.org/x/net/context"
microclient "github.com/micro/go-micro/client"
pb "github.com/seiji-thirdbridge/shippy-user-service/proto/user"
)
func main() {
cmd.Init()
client := pb.NewUserServiceClient("go.micro.srv.user", microclient.DefaultClient)
service := micro.NewService(
micro.Flags(
cli.StringFlag{
Name: "name",
Usage: "Your full name",
},
cli.StringFlag{
Name: "email",
Usage: "Your email",
},
cli.StringFlag{
Name: "password",
Usage: "Your password",
},
cli.StringFlag{
Name: "company",
Usage: "Your company",
},
),
)
service.Init(
micro.Action(func(c *cli.Context) {
name := c.String("name")
email := c.String("email")
password := c.String("password")
company := c.String("company")
r, err := client.Create(context.TODO(), &pb.User{
Name: name,
Email: email,
Password: password,
Company: company,
})
if err != nil {
log.Fatalf("Could not create: %v", err)
}
log.Printf("Created: %s", r.User.Id)
getAll, err := client.GetAll(context.Background(), &pb.Request{})
if err != nil {
log.Fatalf("Could not list users: %v", err)
}
for _, v := range getAll.Users {
log.Println(v)
}
os.Exit(0)
}),
)
if err := service.Run(); err != nil {
log.Println(err)
}
}