[protoc 세팅] MAC protoc-gen-go 설정

2022. 2. 8. 17:58Dev/Golang

 

protobuf 설치하기

먼저 golang이 설치되어있어야한다.

gRPC + golang을 이용하기 위해 proto파일을 컴파일하는 protoc-gen-go를 설정해야한다.

protoc-gen-go를 설치해야하는데, 2가지를 설치해줘야 한다.

먼저 설치해야 할 것은 protobuf 패키지.

2가지 방법 중 하나로 하면 된다.

 

1. 공식 홈페이지에서 다운로드 받기

https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.4

 

Release Protocol Buffers v3.19.4 · protocolbuffers/protobuf

Python Make libprotobuf symbols local on OSX to fix issue #9395 (#9435) Ruby Fixed a data loss bug that could occur when the number of optional fields in a message is an exact multiple of 32. (#...

github.com

 

2. brew 이용하기

brew install protoc-gen-go
brew install protoc-gen-go-grpc

 

나는 brew를 이용했다.

 

proto-gen-go 설치하기

go install을 이용해 아래의 패키지를 다운로드 받는다.

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

 

protoc 이용하기

아래와 같은 형태로 .proto파일을 변환한다.

Makefile을 이용하면 편함

PROTOC = protoc -I=. \
	--go_out . --go_opt paths=source_relative \
	--go-grpc_out . --go-grpc_opt paths=source_relative $(프로토파일 경로)

 


Reference

https://developers.google.com/protocol-buffers/docs/gotutorial

 

Protocol Buffer Basics: Go  |  Protocol Buffers  |  Google Developers

Protocol Buffer Basics: Go This tutorial provides a basic Go programmer's introduction to working with protocol buffers, using the proto3 version of the protocol buffers language. By walking through creating a simple example application, it shows you how t

developers.google.com

 

'Dev > Golang' 카테고리의 다른 글

[Golang + gRPC] gRPC를 사용하기 위해 필요한 패키지 정리  (0) 2022.02.04
[Golang] Go Routine 정리  (0) 2022.01.26