Skip to content

Commit

Permalink
feat: add save rpc response
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool committed Oct 23, 2024
1 parent e6b232e commit 05e2b67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/argparse/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (a *Argument) buildFlags() *flag.FlagSet {

f.BoolVar(&a.version, "version", false, "Show the version of kitexcall.")

f.StringVar(&a.RespFileName, "o", "", "Specify the file name to save the rpc response.")

return f
}

Expand Down Expand Up @@ -279,6 +281,7 @@ func (a *Argument) BuildConfig() *config.Config {
MetaPersistent: a.MetaPersistent,
MetaBackward: a.MetaBackward,
BizError: a.BizError,
RespFileName: a.RespFileName,
}
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/client/generic_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ func (c *GenericClientBase) Output() error {
}

log.Success()
log.Println(result)

if c.Conf.RespFileName == "" {
log.Println(result)
} else {
err = os.WriteFile(c.Conf.RespFileName, []byte(result), 0644)
if err != nil {
return err
}
}

if c.Conf.MetaBackward {
log.Println("\033[32mReceived metainfo from server: \033[0m")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
MetaPersistent map[string]string
MetaBackward bool
BizError bool
RespFileName string
}

type ConfigBuilder interface {
Expand Down

0 comments on commit 05e2b67

Please sign in to comment.