Code Monkey home page Code Monkey logo

Comments (5)

GrantZheng avatar GrantZheng commented on August 22, 2024

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 :)

from kit.

chaseSpace avatar chaseSpace commented on August 22, 2024

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 :)

from kit.

chaseSpace avatar chaseSpace commented on August 22, 2024

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.

from kit.

GrantZheng avatar GrantZheng commented on August 22, 2024

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 ? :)

from kit.

chaseSpace avatar chaseSpace commented on August 22, 2024

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.

from kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.