Usage

    Tool Usage

    Output:

    1. kratos version v2.0.0

    To create a new project:

    1. helloworld
    2. |____api
    3. | |____helloworld
    4. | | |____v1
    5. | | | |____helloworld_grpc.pb.go
    6. | | | |____helloworld.proto
    7. | | | |____helloworld.pb.go
    8. | | | |____helloworld_http.pb.go
    9. | | |____errors
    10. | | | |____helloworld_errors.pb.go
    11. | | | |____helloworld.proto
    12. | | | |____helloworld.pb.go
    13. |____cmd
    14. | |____helloworld
    15. |____internal
    16. | |____biz
    17. | | |____README.md
    18. | |____service
    19. | | |____README.md
    20. | |____data
    21. | | |____README.md
    22. |____README.md
    23. |____Makefile
    24. |____LICENSE
    25. |____go.mod
    26. |____go.sum

    Adding Proto files

    1. kratos proto add api/helloworld/demo.proto

    Output:

    api/helloworld/demo.proto

    1. kratos proto client api/helloworld/demo.proto
    1. api/helloworld/demo.pb.go
    2. api/helloworld/demo_grpc.pb.go
    3. api/helloworld/demo_http.pb.go

    Generate Service Codes

    kratos can generate the bootstrap codes from the proto file.

    Output: internal/service/demo.go

    1. package service
    2. import (
    3. "context"
    4. )
    5. type DemoService struct {
    6. }
    7. func NewDemoService() pb.DemoServer {
    8. return &DemoService{}
    9. }
    10. func (s *DemoService) CreateDemo(ctx context.Context, req *pb.CreateDemoRequest) (*pb.CreateDemoReply, error) {
    11. return &pb.CreateDemoReply{}, nil
    12. }
    13. func (s *DemoService) UpdateDemo(ctx context.Context, req *pb.UpdateDemoRequest) (*pb.UpdateDemoReply, error) {
    14. return &pb.UpdateDemoReply{}, nil
    15. }
    16. func (s *DemoService) DeleteDemo(ctx context.Context, req *pb.DeleteDemoRequest) (*pb.DeleteDemoReply, error) {
    17. return &pb.DeleteDemoReply{}, nil
    18. }
    19. func (s *DemoService) GetDemo(ctx context.Context, req *pb.GetDemoRequest) (*pb.GetDemoReply, error) {
    20. return &pb.GetDemoReply{}, nil
    21. }
    22. func (s *DemoService) ListDemo(ctx context.Context, req *pb.ListDemoRequest) (*pb.ListDemoReply, error) {
    23. }