working commit
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
uuidRegex = `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
|
||||
defaultHostname = "localhost:1025"
|
||||
)
|
||||
|
||||
@@ -41,7 +40,7 @@ func (util *ServiceUtil) MakeServiceCmds() *cobra.Command {
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Password, "pass", "P", util.commonServiceParams.Password, "Password")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Hostname, "host", "X", defaultHostname, "Hostname")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonServiceParams.Timeout, "timeout", "T", defaultTimeout, "Operation timeout")
|
||||
subCmd.PersistentFlags().BoolVarP(&util.commonServiceParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
//subCmd.PersistentFlags().BoolVarP(&util.commonServiceParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
vi := viper.New()
|
||||
@@ -53,7 +52,7 @@ func (util *ServiceUtil) MakeServiceCmds() *cobra.Command {
|
||||
|
||||
// GetService
|
||||
var getservcmd = &cobra.Command{
|
||||
Use: "get [user:pass@]hostname[:port]",
|
||||
Use: "hello [user:pass@]hostname[:port]",
|
||||
Short: "Get service hello",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.GetHello,
|
||||
|
||||
@@ -23,7 +23,10 @@ func (util *ServiceUtil) GetHello(cmd *cobra.Command, args []string) {
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type GetHelloResult struct{}
|
||||
type GetHelloResult struct {
|
||||
Message string `json:"message"`
|
||||
Alive bool `json:"alive"`
|
||||
}
|
||||
|
||||
func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloParams) (*GetHelloResult, error) {
|
||||
var err error
|
||||
@@ -38,9 +41,11 @@ func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloP
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := servcli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := servcli.NewClient(nil, mw)
|
||||
err = cli.GetHello(ctx, ref.Raw())
|
||||
operRes, err := cli.GetHello(ctx, ref.Raw())
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Message = operRes.Message
|
||||
res.Alive = operRes.Alive
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (util *Util) Build() error {
|
||||
execName := filepath.Base(os.Args[0])
|
||||
rootCmd := &cobra.Command{
|
||||
Use: execName,
|
||||
Short: "\nGet hello from service",
|
||||
Short: "\nSupport tools",
|
||||
SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
Reference in New Issue
Block a user