/
commands.go
140 lines (118 loc) · 3.52 KB
/
commands.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"github.com/spf13/cobra"
"github.com/undeconstructed/sample/auth"
"github.com/undeconstructed/sample/config"
"github.com/undeconstructed/sample/fetcher"
"github.com/undeconstructed/sample/frontend"
"github.com/undeconstructed/sample/store"
"github.com/undeconstructed/sample/user"
)
func makeTestMode() *cobra.Command {
cmd := &cobra.Command{
Use: "testmode",
Short: "Test",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(makeTestService())
},
}
return cmd
}
func makeRunAuth() *cobra.Command {
var httpBind, userURL string
cmd := &cobra.Command{
Use: "auth",
Short: "Auth service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(auth.New(httpBind, userURL))
},
}
cmd.Flags().StringVarP(&httpBind, "http-bind", "", ":8080", "where to bind HTTP")
cmd.Flags().StringVarP(&userURL, "user", "", "", "user URL")
cmd.MarkFlagRequired("user")
return cmd
}
func makeRunConfig() *cobra.Command {
var grpcBind, httpBind, path, defaultStoreURL string
cmd := &cobra.Command{
Use: "config",
Short: "Config service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(config.New(grpcBind, httpBind, path, defaultStoreURL))
},
}
cmd.Flags().StringVarP(&grpcBind, "grpc-bind", "", ":8000", "where to bind gRPC")
cmd.Flags().StringVarP(&httpBind, "http-bind", "", ":8080", "where to bind HTTP")
cmd.Flags().StringVarP(&path, "data-path", "", "config.json", "data storage path")
cmd.Flags().StringVarP(&defaultStoreURL, "default-store", "", "", "default store")
cmd.MarkFlagRequired("default-store")
return cmd
}
func makeRunFetcher() *cobra.Command {
var configURL string
cmd := &cobra.Command{
Use: "fetcher",
Short: "Fetcher service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(fetcher.New(configURL))
},
}
cmd.Flags().StringVarP(&configURL, "config", "", "", "config URL")
cmd.MarkFlagRequired("config")
return cmd
}
func makeRunFrontend() *cobra.Command {
var httpBind, configURL, userURL string
cmd := &cobra.Command{
Use: "frontend",
Short: "Frontend service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(frontend.New(httpBind, configURL, userURL))
},
}
cmd.Flags().StringVarP(&httpBind, "http-bind", "", ":8080", "where to bind HTTP")
cmd.Flags().StringVarP(&configURL, "config", "", "", "config URL")
cmd.MarkFlagRequired("config")
cmd.Flags().StringVarP(&configURL, "user", "", "", "user URL")
cmd.MarkFlagRequired("user")
return cmd
}
func makeRunStore() *cobra.Command {
var grpcBind, path string
cmd := &cobra.Command{
Use: "store",
Short: "Store service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(store.New(grpcBind, path))
},
}
cmd.Flags().StringVarP(&grpcBind, "grpc-bind", "", ":8000", "where to bind gRPC")
cmd.Flags().StringVarP(&path, "data-path", "", "store.db", "data storage path")
return cmd
}
func makeRunUser() *cobra.Command {
var grpcBind string
cmd := &cobra.Command{
Use: "user",
Short: "User service",
Long: `test.`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
runService(user.New(grpcBind))
},
}
cmd.Flags().StringVarP(&grpcBind, "grpc-bind", "", ":8000", "where to bind gRPC")
return cmd
}