Skip to content

Commit

Permalink
accept map[string]string as flag, update main template generation,al…
Browse files Browse the repository at this point in the history
…low micro kill .
  • Loading branch information
crazybber committed Mar 22, 2022
2 parents 405a869 + 84cb465 commit a96c462
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions client/cli/new/template/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
type {{title .Alias}} struct{}
// Return a new handler
func New() *{{title .Alias}} {
return &{{title .Alias}}{}
}
// Call is a single request handler called via client.Call or the generated client code
func (e *{{title .Alias}}) Call(ctx context.Context, req *{{dehyphen .Alias}}.Request, rsp *{{dehyphen .Alias}}.Response) error {
log.Info("Received {{title .Alias}}.Call request")
Expand Down
3 changes: 1 addition & 2 deletions client/cli/new/template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ func main() {
// Create service
srv := service.New(
service.Name("{{lower .Alias}}"),
service.Version("latest"),
)
// Register handler
pb.Register{{title .Alias}}Handler(srv.Server(), new(handler.{{title .Alias}}))
pb.Register{{title .Alias}}Handler(srv.Server(), handler.New())
// Run service
if err := srv.Run(); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions client/cli/run/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ func killService(ctx *cli.Context) error {
name = v
}

// special case
if name == "." {
dir, _ := os.Getwd()
name = filepath.Base(dir)
}

var ref string
if parts := strings.Split(name, "@"); len(parts) > 1 {
name = parts[0]
Expand Down
6 changes: 6 additions & 0 deletions cmd/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ func flagsToRequest(flags map[string][]string, req *registry.Value) (map[string]
return ret, nil
case "string":
return value[0], nil
case "map[string]string":
var val map[string]string
if err := json.Unmarshal([]byte(value[0]), &val); err != nil {
return value[0], nil
}
return val, nil
default:
return value, nil
}
Expand Down

0 comments on commit a96c462

Please sign in to comment.