zhufuyi / sponge

Sponge is a powerful Go development framework, it's easy to develop web, gRPC and microservice projects.
https://go-sponge.com
MIT License
1.49k stars 147 forks source link

创建http-pb项目时,make proto命令出现错误 #7

Closed Rvn0xsy closed 1 year ago

Rvn0xsy commented 1 year ago

Describe the bug

我在通过命令创建项目时,make proto出现错误。

执行的命令如下:

  1. sponge web http-pb --module-name=tidy --server-name=tidy --project-name=tidy --protobuf-file=./tidy.proto --out=./generate

  2. sponge web handler-pb --db-dsn='root:123456@(127.0.0.1:3306)/tidy' --db-table=task,target --out=./generate --module-name=github.com/Rvn0xsy/tidy

在执行第二条命令时,出现如下错误:

go: found github.com/zhufuyi/sponge/pkg/gin/validator in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/jwt in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/gotest in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/gofile in github.com/zhufuyi/sponge v1.5.0
gofmt -s -w .
api/types/types.proto: File not found.
api/tidy/v1/target.proto:5:1: Import "api/types/types.proto" was not found or had errors.
api/tidy/v1/target.proto:231:3: "types.Params" is not defined.
make: *** [Makefile:81:proto] 错误 1

我的tidy.proto文件内容如下:

syntax = "proto3";

package api.tidy.v1;

import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "tidy/api/user/v1;v1";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  host: "localhost:8080"
  base_path: ""
  info: {
    title: "user api docs";
    version: "2.0";
  };
  schemes: HTTP;
  schemes: HTTPS;
  consumes: "application/json";
  produces: "application/json";
};

service user {
  rpc Login(LoginRequest) returns (LoginReply) {
    option (google.api.http) = {
      post: "/api/v1/login"
      body: "*"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
      summary: "登录",
      description: "使用邮箱登录",
    };
  }
}

message LoginRequest {
  string email = 1;
  string password = 2;
}

message LoginReply {
  string token = 1;
}

根据大致意思能够了解到,是Import "api/types/types.proto" 这个文件缺失,这个文件貌似没有生成。

sponge的版本:

$ sponge -v
sponge version v1.5.0
zhufuyi commented 1 year ago

在终端执行命令 make patch,解决缺少types.proto、cache、mysql初始化代码导致报错问题,执行make patch之后,再一次执行make proto即可,说明文档暂时还没同步更新,迟一点会更新上去。

你的第二个执行命令 sponge web handler-pb ...... 已经指定了--out参数(sponge创建的服务目录),不需要指定--module-name--server-name两个参数了,因为这两个参数值已经记录在文件docs/gen.info,指定了--module-name也无效的。

Rvn0xsy commented 1 year ago

非常感谢,通过make patch命令进行了修复,问题已经得到解决。