docs: add Korean translations (#5579)

Co-authored-by: kevin <wanjunfeng@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Jeonghyeon Kim
2026-06-21 22:49:20 +09:00
committed by GitHub
parent d4882c1da0
commit 48ca7f03b5
51 changed files with 1982 additions and 91 deletions

View File

@@ -1,5 +1,7 @@
# 示例 01基础 RPC 服务
[English](README.md) | 中文 | [한국어](README-ko.md)
这是使用 goctl 生成 RPC 服务的最简单示例。
## Proto 定义

View File

@@ -0,0 +1,102 @@
# 예제 01: 기본 RPC 서비스
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 goctl로 RPC 서비스를 생성하는 가장 간단한 예제입니다.
## proto 정의
외부 import 없이 하나의 서비스와 하나의 RPC 메서드를 가진 `greeter.proto` 파일 하나를 사용합니다.
`go_package`는 전체 모듈 경로를 사용합니다.
```protobuf
option go_package = "example.com/demo/greeter";
```
## 생성 명령
### 방법 1: `goctl rpc new`로 빠르게 시작
```bash
# 한 번의 명령으로 완전한 RPC 프로젝트 생성
goctl rpc new greeter
```
이 명령은 proto 파일과 서비스 코드를 함께 생성합니다.
```
greeter/
├── etc
│ └── greeter.yaml
├── greeter
│ ├── greeter.pb.go
│ └── greeter_grpc.pb.go
├── greeter.go
├── greeter.proto
├── greeterclient
│ └── greeter.go
└── internal
├── config
│ └── config.go
├── logic
│ └── pinglogic.go
├── server
│ └── greeterserver.go
└── svc
└── servicecontext.go
```
### 방법 2: 기존 proto에서 생성
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc greeter.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── greeter.yaml
├── go.mod
├── greeter
│ ├── greeter.pb.go
│ └── greeter_grpc.pb.go
├── greeter.go
├── greeterclient
│ └── greeter.go
└── internal
├── config
│ └── config.go
├── logic
│ └── sayhellologic.go
├── server
│ └── greeterserver.go
└── svc
└── servicecontext.go
```
## 핵심 사항
- 가장 단순한 시나리오입니다. proto 파일 하나, 서비스 하나, RPC 메서드 하나를 사용합니다.
- `go_package`는 상대 경로가 아닌 전체 모듈 경로(`example.com/demo/greeter`)를 사용합니다.
- `--module` 플래그는 goctl에 Go 모듈 이름을 알려줍니다. `--go_opt=module=...``--go-grpc_opt=module=...`은 protoc에 출력 경로에서 모듈 접두사를 제거하라고 알려줍니다.
- `--zrpc_out` 플래그는 goctl이 생성하는 서비스 코드의 출력 위치를 지정합니다.
- `--go_out``--go-grpc_out` 플래그는 protoc가 생성하는 코드의 출력 위치를 지정합니다.
- 비즈니스 로직을 구현하려면 logic 파일(`internal/logic/sayhellologic.go`)을 수정하세요.

View File

@@ -1,5 +1,7 @@
# Example 01: Basic RPC Service
English | [中文](README-cn.md) | [한국어](README-ko.md)
This is the simplest example of generating an RPC service with goctl.
## Proto Definition

View File

@@ -1,5 +1,7 @@
# 示例 02导入同级 Proto 文件
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示如何导入同一目录下的 proto 文件。
## Proto 定义

View File

@@ -0,0 +1,79 @@
# 예제 02: 같은 디렉터리의 proto 파일 import
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 같은 디렉터리에 있는 proto 파일을 import하는 방법을 보여줍니다.
## proto 정의
같은 디렉터리의 두 proto 파일이 동일한 `go_package`를 공유합니다.
- `types.proto` — 공유 메시지 타입(`User`)을 정의합니다.
- `user.proto` — RPC 서비스를 정의하고 `types.proto`를 import합니다.
두 파일은 전체 모듈 경로를 가진 동일한 `go_package`를 사용합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
`user.proto`는 다음과 같이 `types.proto`를 import합니다.
```protobuf
import "types.proto";
```
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc user.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── usersvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── createuserlogic.go
│ │ └── getuserlogic.go
│ ├── server
│ │ └── userserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── types.pb.go
│ ├── user.pb.go
│ └── user_grpc.pb.go
├── userservice
│ └── userservice.go
└── usersvc.go
```
## 핵심 사항
- 두 proto 파일(`user.proto``types.proto`)은 동일한 `go_package = "example.com/demo/pb"`를 공유하며 하나의 Go 패키지로 컴파일됩니다.
- `user.proto``import "types.proto"``types.proto`를 import합니다.
- 여러 proto 파일이 동일한 `go_package`를 공유하면 하나의 Go 패키지로 컴파일됩니다.
- `service` 정의를 포함한 proto 파일만 `goctl rpc protoc`에 전달하면 됩니다.
- import된 proto는 protoc가 자동으로 컴파일하고 goctl이 해결합니다.

View File

@@ -1,5 +1,7 @@
# Example 02: Importing a Sibling Proto File
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates importing a proto file from the same directory.
## Proto Definition

View File

@@ -1,5 +1,7 @@
# 示例 03导入子目录中的 Proto 文件
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示如何导入子目录中的 proto 文件。
## Proto 定义

View File

@@ -0,0 +1,84 @@
# 예제 03: 하위 디렉터리의 proto import
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 하위 디렉터리에 있는 proto 파일을 import하는 방법을 보여줍니다.
## proto 정의
두 proto 파일은 **서로 다른** `go_package` 값을 사용합니다.
- `order.proto``OrderService`를 정의하고 `common/types.proto`를 import합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
- `common/types.proto` — 재사용 가능한 페이지네이션 및 정렬 메시지를 정의합니다.
```protobuf
option go_package = "example.com/demo/pb/common";
```
`order.proto`는 하위 디렉터리에서 `common/types.proto`를 import합니다.
```protobuf
import "common/types.proto";
```
두 파일은 **서로 다른** `go_package` 값을 가지므로 별도의 Go 패키지로 컴파일됩니다.
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc order.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── ordersvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── getorderlogic.go
│ │ └── listorderslogic.go
│ ├── server
│ │ └── orderserviceserver.go
│ └── svc
│ └── servicecontext.go
├── orderservice
│ └── orderservice.go
├── ordersvc.go
└── pb
├── common
│ └── types.pb.go
├── order.pb.go
└── order_grpc.pb.go
```
## 핵심 사항
- 두 proto 파일은 **서로 다른** `go_package` 값을 가지므로 별도의 Go 패키지(`pb/``pb/common/`)로 컴파일됩니다.
- `order.proto`는 하위 디렉터리에서 `common/types.proto`를 import합니다.
- import된 proto의 `go_package`가 다르면 goctl은 패키지 간 import를 자동으로 생성합니다.
- `-I .` 플래그는 protoc에 현재 디렉터리부터 검색하라고 알려주어 `common/types.proto`를 찾을 수 있게 합니다.

View File

@@ -1,5 +1,7 @@
# Example 03: Importing Proto from a Subdirectory
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates importing a proto file from a subdirectory.
## Proto Definition

View File

@@ -1,5 +1,7 @@
# 示例 04传递性导入
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示 proto 的传递性导入,即 A 导入 BB 导入 C。
## Proto 定义
@@ -65,7 +67,7 @@ output/
## 要点说明
- 三个 proto 文件(`base.proto``middleware.proto``main.proto`)形成传递导入链。
- 三个 proto 文件(`main.proto``middleware.proto``base.proto`)形成传递导入链。
- goctl 自动递归解析所有传递导入。
- 三个文件共享相同的 `go_package = "example.com/demo/pb"`
- 只需指定入口 proto 文件goctl 和 protoc 会自动处理其余部分。

View File

@@ -0,0 +1,74 @@
# 예제 04: 전이 import
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 A가 B를 import하고 B가 C를 import하는 전이 proto import를 보여줍니다.
## proto 정의
세 proto 파일이 전이 import 체인을 이루며, 모두 동일한 `go_package`를 공유합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
- `base.proto` — 계층 C: 기본 타입(`BaseResp`)을 정의합니다.
- `middleware.proto` — 계층 B: `base.proto`를 import하고 `RequestMeta`를 정의합니다.
- `main.proto` — 계층 A: `middleware.proto`를 import하고 `PingService`(진입점)를 정의합니다.
import 체인: `main.proto``middleware.proto``base.proto`
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc main.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── pingsvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ └── pinglogic.go
│ ├── server
│ │ └── pingserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── base.pb.go
│ ├── main.pb.go
│ ├── main_grpc.pb.go
│ └── middleware.pb.go
├── pingservice
│ └── pingservice.go
└── pingsvc.go
```
## 핵심 사항
- 세 proto 파일(`main.proto``middleware.proto``base.proto`)이 전이 import 체인을 이룹니다.
- goctl은 모든 전이 import를 자동으로 재귀 해결합니다.
- 세 파일 모두 동일한 `go_package = "example.com/demo/pb"`를 공유합니다.
- 진입 proto 파일만 지정하면 됩니다. 나머지는 goctl과 protoc가 처리합니다.
- 순환 import는 감지되며 오류가 발생합니다(protoc 동작과 동일).

View File

@@ -1,5 +1,7 @@
# Example 04: Transitive Imports
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates transitive proto imports, where A imports B and B imports C.
## Proto Definition
@@ -65,7 +67,7 @@ output/
## Key Points
- Three proto files (`base.proto``middleware.proto``main.proto`) form a transitive import chain.
- Three proto files (`main.proto``middleware.proto``base.proto`) form a transitive import chain.
- goctl recursively resolves all transitive imports automatically.
- All three files share the same `go_package = "example.com/demo/pb"`.
- You only need to specify the entry proto file — goctl and protoc handle the rest.

View File

@@ -1,5 +1,7 @@
# 示例 05多服务模式`--multiple`
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示从一个 proto 文件生成多个 RPC 服务。
## Proto 定义

View File

@@ -0,0 +1,82 @@
# 예제 05: 다중 서비스(`--multiple`)
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 하나의 proto 파일에서 여러 RPC 서비스를 생성하는 방법을 보여줍니다.
## proto 정의
두 proto 파일이 동일한 `go_package`를 공유합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
- `shared.proto` — 공유 메시지 타입(`Meta`)을 정의합니다.
- `multi.proto`**두 개의** 서비스 `SearchService``NotifyService`를 정의합니다.
proto 파일에 `service` 블록이 둘 이상 포함된 경우 `-m`(또는 `--multiple`) 플래그가 필요합니다.
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 `-m` 플래그와 함께 코드를 생성합니다.
```bash
goctl rpc protoc multi.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I . \
-m
```
생성되는 디렉터리 구조:
```
output/
├── client
│ ├── notifyservice
│ │ └── notifyservice.go
│ └── searchservice
│ └── searchservice.go
├── etc
│ └── multisvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── notifyservice
│ │ │ └── notifylogic.go
│ │ └── searchservice
│ │ └── searchlogic.go
│ ├── server
│ │ ├── notifyservice
│ │ │ └── notifyserviceserver.go
│ │ └── searchservice
│ │ └── searchserviceserver.go
│ └── svc
│ └── servicecontext.go
├── multisvc.go
└── pb
├── multi.pb.go
├── multi_grpc.pb.go
└── shared.pb.go
```
## 핵심 사항
- `-m`(또는 `--multiple`) 플래그는 다중 서비스 모드를 활성화합니다.
- 다중 모드에서는 `client/`가 서비스별 하위 디렉터리를 포함합니다. `logic/``server/`도 서비스 이름별로 그룹화됩니다.
- 두 서비스는 하나의 진입점(`multisvc.go`)과 설정을 공유합니다.
- `--multiple`이 없으면 goctl은 proto 파일당 하나의 `service` 블록만 허용합니다.
- 모든 서비스는 동일한 `config.go``servicecontext.go`를 공유합니다.

View File

@@ -1,5 +1,7 @@
# Example 05: Multiple Services (`--multiple`)
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates generating multiple RPC services from a single proto file.
## Proto Definition

View File

@@ -1,6 +1,8 @@
# 示例 06知名类型
本示例演示如何使用 Google protobuf 知名类型(`Timestamp``Duration``Any`)作为消息字段。
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示如何使用 Google protobuf 知名类型(`Timestamp`)作为消息字段。
## Proto 定义
@@ -60,6 +62,6 @@ output/
## 要点说明
- 使用 Google 知名类型`google.protobuf.Timestamp``google.protobuf.Duration``google.protobuf.Any`作为消息字段。
- goctl 自动将知名类型映射到 Go 导入包`timestamppb``durationpb``anypb` 等)
- 使用 Google 知名类型 `google.protobuf.Timestamp` 作为消息字段。
- goctl 自动将知名类型映射到 Go 导入包;在本示例中,`Timestamp` 会映射到 `timestamppb`
- 如果 protoc 已正确安装,知名类型无需额外的 `--proto_path`

View File

@@ -0,0 +1,67 @@
# 예제 06: Google well-known types
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 Google protobuf well-known type(`Timestamp`)을 메시지 필드로 사용하는 방법을 보여줍니다.
## proto 정의
`events.proto``google.protobuf.Timestamp`를 메시지 필드 타입으로 사용합니다.
`go_package`는 전체 모듈 경로를 사용합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc events.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── eventsvc.yaml
├── eventservice
│ └── eventservice.go
├── eventsvc.go
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── createeventlogic.go
│ │ └── listeventslogic.go
│ ├── server
│ │ └── eventserviceserver.go
│ └── svc
│ └── servicecontext.go
└── pb
├── events.pb.go
└── events_grpc.pb.go
```
## 핵심 사항
- Google well-known type인 `google.protobuf.Timestamp`를 메시지 필드로 사용합니다.
- goctl은 well-known types를 Go import로 자동 매핑합니다. 이 예제에서는 `Timestamp``timestamppb`로 매핑됩니다.
- protoc가 올바르게 설치되어 있다면 well-known types에는 추가 `--proto_path`가 필요하지 않습니다.

View File

@@ -1,6 +1,8 @@
# Example 06: Well-Known Types
This example demonstrates using Google protobuf well-known types (`Timestamp`, `Duration`, `Any`) as message fields.
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates using a Google protobuf well-known type (`Timestamp`) as a message field.
## Proto Definition
@@ -60,6 +62,6 @@ output/
## Key Points
- Uses Google well-known types (`google.protobuf.Timestamp`, `google.protobuf.Duration`, `google.protobuf.Any`) as message fields.
- goctl automatically maps well-known types to Go imports (`timestamppb`, `durationpb`, `anypb`, etc.).
- Uses the Google well-known type `google.protobuf.Timestamp` as a message field.
- goctl automatically maps well-known types to Go imports; in this example, `Timestamp` maps to `timestamppb`.
- No extra `--proto_path` needed for well-known types if protoc is properly installed.

View File

@@ -1,5 +1,7 @@
# 示例 07外部 Proto — 相同 `go_package`
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示从外部目录导入 proto 文件,且两个文件共享**相同**的 `go_package`
## Proto 定义
@@ -18,7 +20,8 @@ option go_package = "example.com/demo/pb";
│ └── ext.proto # 外部 protogo_package = "example.com/demo/pb"
├── service.proto # 服务定义go_package = "example.com/demo/pb"
├── README.md
── README-cn.md
── README-cn.md
└── README-ko.md
```
- `ext.proto` 位于独立目录(`ext_protos/`),但与 `service.proto` 有相同的 `go_package`

View File

@@ -0,0 +1,80 @@
# 예제 07: 외부 proto — 동일한 `go_package`
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 두 파일이 **동일한** `go_package`를 공유하는 외부 디렉터리의 proto 파일을 import하는 방법을 보여줍니다.
## proto 정의
`service.proto``ext.proto`는 모두 동일한 `go_package`를 사용합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
소스 레이아웃:
```
07-external-proto-same-pkg/
├── ext_protos
│ └── ext.proto # 외부 proto (go_package = "example.com/demo/pb")
├── service.proto # 서비스 정의 (go_package = "example.com/demo/pb")
├── README.md
├── README-cn.md
└── README-ko.md
```
- `ext.proto`는 별도 디렉터리(`ext_protos/`)에 있지만 `service.proto`와 동일한 `go_package`를 가집니다.
- `service.proto``ext.proto`를 import하고 `ext.ExtReq` / `ext.ExtReply`를 RPC 타입으로 사용합니다.
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다(`-I ./ext_protos`에 주목하세요).
```bash
goctl rpc protoc service.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I . -I ./ext_protos
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── svc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ └── querylogic.go
│ ├── server
│ │ └── queryserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── ext.pb.go
│ ├── service.pb.go
│ └── service_grpc.pb.go
├── queryservice
│ └── queryservice.go
└── svc.go
```
## 핵심 사항
- `ext.proto`는 별도 디렉터리(`ext_protos/`)에 있지만 `service.proto`와 동일한 `go_package`를 가집니다.
- 외부 디렉터리를 proto 검색 경로에 추가하려면 `-I ./ext_protos`를 사용합니다.
- 외부 proto가 **동일한** `go_package`를 가지면 모든 타입이 하나의 Go 패키지로 병합되므로 패키지 간 import가 필요하지 않습니다.

View File

@@ -1,5 +1,7 @@
# Example 07: External Proto — Same `go_package`
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates importing proto files from an external directory where both files share the **same** `go_package`.
## Proto Definition
@@ -18,7 +20,8 @@ Source layout:
│ └── ext.proto # External proto (go_package = "example.com/demo/pb")
├── service.proto # Service definition (go_package = "example.com/demo/pb")
├── README.md
── README-cn.md
── README-cn.md
└── README-ko.md
```
- `ext.proto` lives in a separate directory (`ext_protos/`), but has the same `go_package` as `service.proto`.

View File

@@ -1,5 +1,7 @@
# 示例 08外部 Proto — 不同 `go_package`
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示从外部目录导入 proto 文件,且文件具有**不同**的 `go_package` 值,需要在生成的 Go 代码中进行跨包导入。
## Proto 定义
@@ -18,7 +20,8 @@ proto 文件使用不同的 `go_package` 值:
│ └── types.proto # 外部 protogo_package = "example.com/demo/pb/common"
├── service.proto # 服务定义go_package = "example.com/demo/pb"
├── README.md
── README-cn.md
── README-cn.md
└── README-ko.md
```
- `types.proto``go_package = "example.com/demo/pb/common"` — **不同**的 Go 包。

View File

@@ -0,0 +1,81 @@
# 예제 08: 외부 proto — 다른 `go_package`
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 파일들이 **서로 다른** `go_package` 값을 가져 생성된 Go 코드에 패키지 간 import가 필요한 외부 디렉터리의 proto 파일을 import하는 방법을 보여줍니다.
## proto 정의
proto 파일들은 서로 다른 `go_package` 값을 사용합니다.
- `service.proto`: `go_package = "example.com/demo/pb"`
- `ext_protos/common/types.proto`: `go_package = "example.com/demo/pb/common"`
소스 레이아웃:
```
08-external-proto-diff-pkg/
├── ext_protos
│ └── common
│ └── types.proto # 외부 proto (go_package = "example.com/demo/pb/common")
├── service.proto # 서비스 정의 (go_package = "example.com/demo/pb")
├── README.md
├── README-cn.md
└── README-ko.md
```
- `types.proto``go_package = "example.com/demo/pb/common"`을 가지며, 이는 **다른** Go 패키지입니다.
- `service.proto``common.ExtReq` / `common.ExtReply`를 RPC 파라미터 타입으로 직접 사용합니다.
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다(`-I ./ext_protos`에 주목하세요).
```bash
goctl rpc protoc service.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I . -I ./ext_protos
```
생성되는 디렉터리 구조:
```
output/
├── dataservice
│ └── dataservice.go
├── etc
│ └── svc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ └── fetchlogic.go
│ ├── server
│ │ └── dataserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── common
│ │ └── types.pb.go
│ ├── service.pb.go
│ └── service_grpc.pb.go
└── svc.go
```
## 핵심 사항
- 외부 proto가 **다른** `go_package`를 가지면 goctl은 패키지 간 Go import를 자동으로 생성합니다.
- goctl은 import된 proto의 `go_package` 옵션을 파싱하여 proto `package` 이름(예: `common`)을 올바른 Go import 경로로 해결합니다.
- `service.proto``common.ExtReq` / `common.ExtReply`를 RPC 파라미터 타입으로 직접 사용합니다.

View File

@@ -1,5 +1,7 @@
# Example 08: External Proto — Different `go_package`
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates importing proto files from an external directory where the files have **different** `go_package` values, requiring cross-package imports in the generated Go code.
## Proto Definition
@@ -18,7 +20,8 @@ Source layout:
│ └── types.proto # External proto (go_package = "example.com/demo/pb/common")
├── service.proto # Service definition (go_package = "example.com/demo/pb")
├── README.md
── README-cn.md
── README-cn.md
└── README-ko.md
```
- `types.proto` has `go_package = "example.com/demo/pb/common"` — a **different** Go package.

View File

@@ -1,4 +1,6 @@
# 示例 09Google 类型作为 RPC 参数
# 示例 09Google 知名类型作为 RPC 参数
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示将 Google protobuf 知名类型**直接**用作 RPC 请求或响应类型(而不仅仅是消息字段)。

View File

@@ -0,0 +1,67 @@
# 예제 09: RPC 파라미터로 Google well-known types 사용
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 Google protobuf well-known types를 메시지 필드뿐 아니라 RPC 요청 또는 응답 타입으로 **직접** 사용하는 방법을 보여줍니다.
## proto 정의
`service.proto``google.protobuf.Empty``google.protobuf.Timestamp`를 RPC 요청/응답 타입으로 직접 사용합니다.
`go_package`는 전체 모듈 경로를 사용합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc service.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── healthsvc.yaml
├── go.mod
├── healthservice
│ └── healthservice.go
├── healthsvc.go
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── gettimelogic.go
│ │ └── pinglogic.go
│ ├── server
│ │ └── healthserviceserver.go
│ └── svc
│ └── servicecontext.go
└── pb
├── service.pb.go
└── service_grpc.pb.go
```
## 핵심 사항
- Google well-known types(`google.protobuf.Empty`, `google.protobuf.Timestamp`)를 메시지 필드뿐 아니라 RPC 요청/응답 타입으로 직접 사용합니다.
- goctl은 이를 Go 타입(`emptypb.Empty`, `timestamppb.Timestamp`)으로 올바르게 매핑하고 적절한 import를 생성합니다.
- well-known types를 메시지 필드로 사용하는 예제 06과는 다릅니다.

View File

@@ -1,4 +1,6 @@
# Example 09: Google Types as RPC Parameters
# Example 09: Google Well-Known Types as RPC Parameters
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates using Google protobuf well-known types **directly** as RPC request or response types (not just as message fields).

View File

@@ -1,5 +1,7 @@
# 示例 10流式 RPC
[English](README.md) | 中文 | [한국어](README-ko.md)
本示例演示 gRPC 的三种流式通信模式:服务端流、客户端流和双向流。
## Proto 定义
@@ -63,4 +65,4 @@ output/
- 支持三种流式模式:服务端流(响应带 `stream`)、客户端流(请求带 `stream`)和双向流(两端都带 `stream`)。
- goctl 为每个流式 RPC 方法生成独立的逻辑文件。
- 流式客户端代码不会自动生成,需直接使用 gRPC 客户端
- goctl 会生成流式客户端包装方法;请使用返回的 gRPC stream 发送和接收消息

View File

@@ -0,0 +1,68 @@
# 예제 10: 스트리밍 RPC
[English](README.md) | [中文](README-cn.md) | 한국어
이 예제는 서버 스트리밍, 클라이언트 스트리밍, 양방향 스트리밍이라는 세 가지 gRPC 스트리밍 패턴을 모두 보여줍니다.
## proto 정의
`stream.proto`는 각 스트리밍 패턴을 보여주는 세 개의 RPC 메서드를 정의합니다.
`go_package`는 전체 모듈 경로를 사용합니다.
```protobuf
option go_package = "example.com/demo/pb";
```
## 생성 명령
먼저 출력 디렉터리에 `go.mod`를 초기화합니다.
```bash
mkdir -p output && cd output && go mod init example.com/demo && cd ..
```
그런 다음 코드를 생성합니다.
```bash
goctl rpc protoc stream.proto \
--go_out=output \
--go-grpc_out=output \
--zrpc_out=output \
--go_opt=module=example.com/demo \
--go-grpc_opt=module=example.com/demo \
--module=example.com/demo \
-I .
```
생성되는 디렉터리 구조:
```
output/
├── etc
│ └── streamsvc.yaml
├── go.mod
├── internal
│ ├── config
│ │ └── config.go
│ ├── logic
│ │ ├── bidistreamlogic.go
│ │ ├── clientstreamlogic.go
│ │ └── serverstreamlogic.go
│ ├── server
│ │ └── streamserviceserver.go
│ └── svc
│ └── servicecontext.go
├── pb
│ ├── stream.pb.go
│ └── stream_grpc.pb.go
├── streamservice
│ └── streamservice.go
└── streamsvc.go
```
## 핵심 사항
- 세 가지 스트리밍 패턴을 지원합니다. 서버 스트리밍(응답에 `stream`), 클라이언트 스트리밍(요청에 `stream`), 양방향 스트리밍(양쪽 모두 `stream`).
- goctl은 각 스트리밍 RPC 메서드마다 별도의 logic 파일을 생성합니다.
- goctl은 스트리밍 클라이언트 래퍼 메서드를 생성합니다. 반환된 gRPC stream을 사용해 메시지를 송수신하세요.

View File

@@ -1,5 +1,7 @@
# Example 10: Streaming RPC
English | [中文](README-cn.md) | [한국어](README-ko.md)
This example demonstrates all three gRPC streaming patterns: server streaming, client streaming, and bidirectional streaming.
## Proto Definition
@@ -63,4 +65,4 @@ output/
- Supports three streaming patterns: server streaming (`stream` on response), client streaming (`stream` on request), and bidirectional streaming (`stream` on both).
- goctl generates separate logic files for each streaming RPC method.
- Streaming client code is not auto-generated; use the gRPC client directly.
- goctl generates streaming client wrapper methods; use the returned gRPC stream to send and receive messages.

View File

@@ -0,0 +1,47 @@
# RPC 示例
[English](README.md) | 中文 | [한국어](README-ko.md)
本目录包含所有 `goctl rpc` 代码生成场景的完整示例。
每个示例包含:
- `.proto` 源文件
- `README.md`(英文)、`README-cn.md`(中文)和 `README-ko.md`(한국어)文档
## 示例列表
| # | 目录 | 场景 | 关键标志 |
|---|------|------|---------|
| 01 | [01-basic](01-basic/) | 基础单服务,无导入 | — |
| 02 | [02-import-sibling](02-import-sibling/) | 导入同级 proto 文件 | `--proto_path=.` |
| 03 | [03-import-subdir](03-import-subdir/) | 导入子目录中的 proto | `--proto_path=.` |
| 04 | [04-transitive-import](04-transitive-import/) | 传递性导入A → B → C | `--proto_path=.` |
| 05 | [05-multiple-services](05-multiple-services/) | 单 proto 多服务 | `--multiple` |
| 06 | [06-wellknown-types](06-wellknown-types/) | 消息中使用 Google 标准类型 | — |
| 07 | [07-external-proto-same-pkg](07-external-proto-same-pkg/) | 外部 proto相同 `go_package` | `-I ./ext_protos` |
| 08 | [08-external-proto-diff-pkg](08-external-proto-diff-pkg/) | 外部 proto不同 `go_package` | `-I ./ext_protos` |
| 09 | [09-google-types-as-rpc](09-google-types-as-rpc/) | Google 标准类型作为 RPC 参数 | — |
| 10 | [10-streaming](10-streaming/) | 服务端/客户端/双向流 | — |
## 前置条件
- [Go](https://go.dev/) 1.22+
- [protoc](https://github.com/protocolbuffers/protobuf/releases)Protocol Buffers 编译器)
- [protoc-gen-go](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go) 和 [protoc-gen-go-grpc](https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc)
- [goctl](https://github.com/zeromicro/go-zero/tree/master/tools/goctl)
## 快速开始
```bash
# 安装 protoc 插件
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# 试试基础示例
cd 01-basic
mkdir -p output && cd output && go mod init example.com/demo && cd ..
goctl rpc protoc greeter.proto \
--go_out=output --go-grpc_out=output --zrpc_out=output \
--go_opt=module=example.com/demo --go-grpc_opt=module=example.com/demo \
--module=example.com/demo -I .
```

View File

@@ -0,0 +1,47 @@
# RPC 예제
[English](README.md) | [中文](README-cn.md) | 한국어
이 디렉터리에는 모든 `goctl rpc` 코드 생성 시나리오에 대한 완전한 예제가 포함되어 있습니다.
각 예제에는 다음이 포함됩니다.
- `.proto` 소스 파일
- `README.md`(영어), `README-cn.md`(중국어), `README-ko.md`(한국어) 문서
## 예제
| # | 디렉터리 | 시나리오 | 주요 플래그 |
|---|-----------|----------|-----------|
| 01 | [01-basic](01-basic/) | 기본 단일 서비스, import 없음 | — |
| 02 | [02-import-sibling](02-import-sibling/) | 같은 디렉터리의 proto 파일 import | `--proto_path=.` |
| 03 | [03-import-subdir](03-import-subdir/) | 하위 디렉터리의 proto import | `--proto_path=.` |
| 04 | [04-transitive-import](04-transitive-import/) | 전이 import(A → B → C) | `--proto_path=.` |
| 05 | [05-multiple-services](05-multiple-services/) | 하나의 proto에 여러 서비스 | `--multiple` |
| 06 | [06-wellknown-types](06-wellknown-types/) | 메시지에서 Google well-known types 사용 | — |
| 07 | [07-external-proto-same-pkg](07-external-proto-same-pkg/) | 외부 proto, 동일한 `go_package` | `-I ./ext_protos` |
| 08 | [08-external-proto-diff-pkg](08-external-proto-diff-pkg/) | 외부 proto, 다른 `go_package` | `-I ./ext_protos` |
| 09 | [09-google-types-as-rpc](09-google-types-as-rpc/) | RPC 파라미터로 Google well-known types 사용 | — |
| 10 | [10-streaming](10-streaming/) | 서버/클라이언트/양방향 스트리밍 | — |
## 사전 요구 사항
- [Go](https://go.dev/) 1.22+
- [protoc](https://github.com/protocolbuffers/protobuf/releases) (Protocol Buffers 컴파일러)
- [protoc-gen-go](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go) 및 [protoc-gen-go-grpc](https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc)
- [goctl](https://github.com/zeromicro/go-zero/tree/master/tools/goctl)
## 빠른 시작
```bash
# protoc 플러그인 설치
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# 기본 예제 실행
cd 01-basic
mkdir -p output && cd output && go mod init example.com/demo && cd ..
goctl rpc protoc greeter.proto \
--go_out=output --go-grpc_out=output --zrpc_out=output \
--go_opt=module=example.com/demo --go-grpc_opt=module=example.com/demo \
--module=example.com/demo -I .
```

View File

@@ -1,10 +1,12 @@
# RPC Examples
English | [中文](README-cn.md) | [한국어](README-ko.md)
This directory contains complete examples for all `goctl rpc` code generation scenarios.
Each example includes:
- `.proto` source files
- `README.md` (English) and `README-cn.md` (中文) documentation
- `README.md` (English), `README-cn.md` (中文), and `README-ko.md` (한국어) documentation
## Examples
@@ -15,10 +17,10 @@ Each example includes:
| 03 | [03-import-subdir](03-import-subdir/) | Import proto from subdirectory | `--proto_path=.` |
| 04 | [04-transitive-import](04-transitive-import/) | Transitive imports (A → B → C) | `--proto_path=.` |
| 05 | [05-multiple-services](05-multiple-services/) | Multiple services in one proto | `--multiple` |
| 06 | [06-wellknown-types](06-wellknown-types/) | Google well-known types in messages | `--proto_path=$PROTOC_INCLUDE` |
| 06 | [06-wellknown-types](06-wellknown-types/) | Google well-known types in messages | |
| 07 | [07-external-proto-same-pkg](07-external-proto-same-pkg/) | External proto, same `go_package` | `-I ./ext_protos` |
| 08 | [08-external-proto-diff-pkg](08-external-proto-diff-pkg/) | External proto, different `go_package` | `-I ./ext_protos` |
| 09 | [09-google-types-as-rpc](09-google-types-as-rpc/) | Google types as RPC parameters | `--proto_path=$PROTOC_INCLUDE` |
| 09 | [09-google-types-as-rpc](09-google-types-as-rpc/) | Google well-known types as RPC parameters | |
| 10 | [10-streaming](10-streaming/) | Server/client/bidirectional streaming | — |
## Prerequisites
@@ -43,51 +45,3 @@ goctl rpc protoc greeter.proto \
--go_opt=module=example.com/demo --go-grpc_opt=module=example.com/demo \
--module=example.com/demo -I .
```
---
# RPC 示例
本目录包含所有 `goctl rpc` 代码生成场景的完整示例。
每个示例包含:
- `.proto` 源文件
- `README.md`(英文)和 `README-cn.md`(中文)文档
## 示例列表
| # | 目录 | 场景 | 关键标志 |
|---|------|------|---------|
| 01 | [01-basic](01-basic/) | 基础单服务,无导入 | — |
| 02 | [02-import-sibling](02-import-sibling/) | 导入同级 proto 文件 | `--proto_path=.` |
| 03 | [03-import-subdir](03-import-subdir/) | 导入子目录中的 proto | `--proto_path=.` |
| 04 | [04-transitive-import](04-transitive-import/) | 传递性导入A → B → C | `--proto_path=.` |
| 05 | [05-multiple-services](05-multiple-services/) | 单 proto 多服务 | `--multiple` |
| 06 | [06-wellknown-types](06-wellknown-types/) | 消息中使用 Google 标准类型 | `--proto_path=$PROTOC_INCLUDE` |
| 07 | [07-external-proto-same-pkg](07-external-proto-same-pkg/) | 外部 proto相同 `go_package` | `-I ./ext_protos` |
| 08 | [08-external-proto-diff-pkg](08-external-proto-diff-pkg/) | 外部 proto不同 `go_package` | `-I ./ext_protos` |
| 09 | [09-google-types-as-rpc](09-google-types-as-rpc/) | Google 类型作为 RPC 参数 | `--proto_path=$PROTOC_INCLUDE` |
| 10 | [10-streaming](10-streaming/) | 服务端/客户端/双向流 | — |
## 前置条件
- [Go](https://go.dev/) 1.22+
- [protoc](https://github.com/protocolbuffers/protobuf/releases)Protocol Buffers 编译器)
- [protoc-gen-go](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go) 和 [protoc-gen-go-grpc](https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc)
- [goctl](https://github.com/zeromicro/go-zero/tree/master/tools/goctl)
## 快速开始
```bash
# 安装 protoc 插件
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# 试试基础示例
cd 01-basic
mkdir -p output && cd output && go mod init example.com/demo && cd ..
goctl rpc protoc greeter.proto \
--go_out=output --go-grpc_out=output --zrpc_out=output \
--go_opt=module=example.com/demo --go-grpc_opt=module=example.com/demo \
--module=example.com/demo -I .
```