콘텐츠로 이동

Proto DSL 참조

syntax = "proto3";
package user;
option go_package = "./user";
service User {
rpc GetUser(GetUserRequest) returns (GetUserResponse);
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
}
message GetUserRequest {
int64 id = 1;
}
message GetUserResponse {
int64 id = 1;
string name = 2;
}
message CreateUserRequest {
string name = 1;
string email = 2;
}
message CreateUserResponse {
int64 id = 1;
}
option go_package = "./user"; // 예시입니다
Proto 타입Go 타입
stringstring
int32int32
int64int64
boolbool
floatfloat32
doublefloat64
bytes[]byte
message ListUsersResponse {
repeated UserInfo users = 1;
int64 total = 2;
}
message UserInfo {
int64 id = 1;
string name = 2;
}
message CreateOrderRequest {
int64 user_id = 1;
Address address = 2;
}
message Address {
string street = 1;
string city = 2;
string zip = 3;
}
enum UserStatus {
ACTIVE = 0;
INACTIVE = 1;
BANNED = 2;
}
message UserInfo {
int64 id = 1;
string name = 2;
UserStatus status = 3;
}

goctl 생성합니다 separate zRPC 서비스 위한 각 service block. Keep one 서비스 별 .proto 파일.

Terminal window
# 사용 예시
goctl rpc protoc user.proto \
--go_out=./user \
--go-grpc_out=./user \
--zrpc_out=.
# 또는 다음 방법 사용
protoc user.proto \
--go_out=./user \
--go-grpc_out=./user
WhatConvention예제
Service namePascalCaseUserService
RPC 메서드PascalCaseGetUserById
메시지 namePascalCaseGetUserRequest
필드 namesnake_caseuser_id
패키지 namelowercasepackage user