-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (41 loc) · 1.41 KB
/
main.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
package main
import (
"fmt"
"github.com/Microkubes/microservice-registration/client"
"github.com/Microkubes/microservice-registration/tool/cli"
goaclient "github.com/goadesign/goa/client"
"github.com/spf13/cobra"
"net/http"
"os"
"time"
)
func main() {
// Create command line parser
app := &cobra.Command{
Use: "user-cli",
Short: `CLI client for the user service`,
}
// Create client struct
httpClient := newHTTPClient()
c := client.New(goaclient.HTTPClientDoer(httpClient))
// Register global flags
app.PersistentFlags().StringVarP(&c.Scheme, "scheme", "s", "", "Set the requests scheme")
app.PersistentFlags().StringVarP(&c.Host, "host", "H", "localhost:8081", "API hostname")
app.PersistentFlags().DurationVarP(&httpClient.Timeout, "timeout", "t", time.Duration(20)*time.Second, "Set the request timeout")
app.PersistentFlags().BoolVar(&c.Dump, "dump", false, "Dump HTTP request and response.")
// Initialize API client
c.UserAgent = "user-cli/1.0"
// Register API commands
cli.RegisterCommands(app, c)
// Execute!
if err := app.Execute(); err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(-1)
}
}
// newHTTPClient returns the HTTP client used by the API client to make requests to the service.
func newHTTPClient() *http.Client {
// TBD: Change as needed (e.g. to use a different transport to control redirection policy or
// disable cert validation or...)
return http.DefaultClient
}