Skip to content

如何使用 “自定义字段 tag” #45

@achilsh

Description

@achilsh

Is your feature request related to a problem?

  1. 我设置了 proto 如下:

syntax = "proto3";
package helloworld;

import "trpc/proto/trpc_options.proto";
import "trpc/swagger/swagger.proto";
import "validate/validate.proto";
option go_package = "trpc-http-demo/helloworld";

// HelloRequest is hello request.
message HelloRequest {
string msg = 1 [ (trpc.go_tag)='json:"xxx"', (validate.rules).string.email=true];
}

// HelloResponse is hello response.
message HelloResponse {
string msg = 1;
}

// HelloWorldService handles hello request and echo message.
service HelloWorldService {
// Hello says hello.
//@alias="/api/helloworld"
rpc Hello(HelloRequest) returns(HelloResponse);
}

  1. 运行命令行阐述 项目:
    trpc create --protocol http -p ./hello-world.proto -f -o . --alias --gotag --validate

  2. 修改配置文件,http端口号为9100

  3. 使用http client 调用:
    5
    image

  4. 服务端错误:
    2024-09-10 00:09:06.615 DEBUG server/service.go:235 service: helloworld.HelloWorldService handle err (if caused by health checking, this error can be ignored): type:framework, code:1, msg:service codec Unmarshal: proto: (line 2:5): unknown field "xxx"

What is the solution you'd like?

What alternatives have you considered?

Could you provide additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions