GrantZheng / kit

GoKit CLI
MIT License
268 stars 54 forks source link

Could kit allow to specify the path of the pb directory? #11

Closed chaseSpace closed 4 years ago

chaseSpace commented 4 years ago

Now, this cmd will gen /pb dir to /pkg/grpc:

kit g s hello -t grpc

but sometimes, put pb dir in root dir of project is a common practice. so, could I ask you to add a flag to specify the location of the pb directory? thanks in advance.

GrantZheng commented 4 years ago

Now, this cmd will gen /pb dir to /pkg/grpc:

kit g s hello -t grpc

but sometimes, put pb dir in root dir of project is a common practice. so, could I ask you to add a flag to specify the location of the pb directory? thanks in advance.

Hello, thanks for your suggestion. The go-kit should support some transport protocols, such http , grpc, thrift and so on. So, putting pb dir in root dir of project is not a better way for the project generated by kit, I think :)

chaseSpace commented 4 years ago

The go-kit should support some transport protocols, such http , grpc, thrift and so on.

That is surely right. I mean provide a new flag --pb_path specify pb path only works when transport is grpc, Isn't it have to be more flexible?


And, In order to improve efficiency, in the last two hours, I have basically completed the update of this function. Just see effects below:

$ kit g service hello -t grpc --help
Initiate a service

Usage:
  kit generate service [flags]

Aliases:
  service, s

Flags:
  -w, --dmw                   Generate default middleware for service and endpoint
      --endpoint-mdw          If set a default Logging and Tracking middleware will be created and attached to the endpoint
      --gorilla               Generate http using gorilla mux
  -h, --help                  help for service
  -m, --methods stringArray   Specify methods to be generated
  -p, --pb_path string        The path of pb dir store  <-------------------------------------
      --svc-mdw               If set a default Logging and Instrumental middleware will be created and attached to the service
  -t, --transport string      The transport you want your service to be initiated with (default "http")

Global Flags:
  -d, --debug           If you want to see the debug logs.
  -b, --folder string   If you want to specify the base folder of the project.
  -f, --force           Force overide existing files without asking.

Use --pb_path or -p:

kit g service hello -t grpc -p hello/

This will do:
Create pb dir in the hello/, this is relatively path to root dir of hello project; surely, absolute path is supported.

If --pb_path or -p not provided, there will put pb dir in /pkg/grpc, just as old.

Thanks to read :)

chaseSpace commented 4 years ago

If a team choosed gRPC as their rpc method, then they don't care about HTTP or other RPC methods, So it is very important to choose the path to the pb directory.

GrantZheng commented 4 years ago

The go-kit should support some transport protocols, such http , grpc, thrift and so on.

That is surely right. I mean provide a new flag --pb_path specify pb path only works when transport is grpc, Isn't it have to be more flexible?

And, In order to improve efficiency, in the last two hours, I have basically completed the update of this function. Just see effects below:

$ kit g service hello -t grpc --help
Initiate a service

Usage:
  kit generate service [flags]

Aliases:
  service, s

Flags:
  -w, --dmw                   Generate default middleware for service and endpoint
      --endpoint-mdw          If set a default Logging and Tracking middleware will be created and attached to the endpoint
      --gorilla               Generate http using gorilla mux
  -h, --help                  help for service
  -m, --methods stringArray   Specify methods to be generated
  -p, --pb_path string        The path of pb dir store  <-------------------------------------
      --svc-mdw               If set a default Logging and Instrumental middleware will be created and attached to the service
  -t, --transport string      The transport you want your service to be initiated with (default "http")

Global Flags:
  -d, --debug           If you want to see the debug logs.
  -b, --folder string   If you want to specify the base folder of the project.
  -f, --force           Force overide existing files without asking.

Use --pb_path or -p:

kit g service hello -t grpc -p hello/

This will do: Create pb dir in the hello/, this is relatively path to root dir of hello project; surely, absolute path is supported.

If --pb_path or -p not provided, there will put pb dir in /pkg/grpc, just as old.

Thanks to read :)

That is a good job ! 👍 Could you submit a PR for it ? :)

chaseSpace commented 4 years ago

If developer provides a valid pa path by flag --pb_path, he has to provide pb import path by flag --pb_import_path, Because the path to import pb will so difficult to determinate at that time, so it only be pass it by flag directly.

Usage

$ kit g s --help
Initiate a service

Usage:
  kit generate service [flags]

Aliases:
  service, s

Flags:

(ignored some flags...)
  -i, --pb_import_path string   Specify path to import pb
  -p, --pb_path string          Specify path to store pb dir
  -t, --transport string        The transport you want your service to be initiated with (default "http")

(ignored global flags...)

Use this two flags(--pb_path must be with --pb_import_path):

$pwd
/root/kit
$kit n s hello
# create a service method, then continue
$kit g s hello -t grpc -p hello -i hello/pb

Check generated structure:

[root@localhost kit]# tree hello/
hello/
├── cmd
│   ├── main.go
│   └── service
│       ├── service_gen.go
│       └── service.go
├── go.mod
├── pb   <------------------------- pb dir be here now, instead of /pkg/grpc/pb
│   ├── compile.sh
│   ├── hello.pb.go
│   └── hello.proto
└── pkg
    ├── endpoint
    │   ├── endpoint_gen.go
    │   └── endpoint.go
    ├── grpc
    │   ├── handler_gen.go  <------ `hello/pb` will be used as pb import path
    │   └── handler.go  <------ `hello/pb` will be used as pb import path
    └── service
        ├── middleware.go
        └── service.go

7 directories, 13 files

Then generate client file:

$kit g c hello -t grpc -i hello/pb

Check generated client dir structure:

[root@localhost kit]# tree hello/client/
hello/client/
└── grpc
    └── grpc.go <------ `hello/pb` will be used as pb import path

Thanks.