Web/GoLang

[golang] grpc 윈도우에서 사용하기 위한 wsl (리눅스 환경 설정)

벨포트조던 2022. 10. 18. 16:03
반응형

배경

go 에서 grpc를 사용하려 함.

기존 windows 에서도 사용 가능하긴한데... 기존 프로젝트가 macOS 기반으로 생성되어 있어서, 만들어진 룰을 따르려면... 리눅스 환경의 명령어가 필요함..

  • 이미 구성된 환경에 따라 약간의 차이가 발생할 수 있음

 

필요 패키지 및 명령어

make, buf, brew, find 등

 

- homebrew 설치 방법

터미널에 아래 명령어 실행

 

구성 가이드

  • 리눅스 명령어 사용가능한 환경 추천
    • 방법 1 - WSL2 설치
    • 방법 2 - 초콜라티 이용 ( 미테스트 )

 

 

  1. WSL2 설치 완료
  2. WSL 설치 후 오류발생 가능성 높음 → BOIS 에서 CPU 가상화 설정 ON
    참고 : https://gallery-k.tistory.com/311
    WSL 사용방법 : https://tutorialpost.apptilus.com/code/posts/tools/windows-subsystem-linux/
    go 설치 확인 ( 1.19 이상 )
  3. homebrew, make, buf 설치
    더보기
     
    • Golang 설치
      • 사이트 : https://go.dev/dl/
      • 설치 방법 : 터미널에 아래 명령어 실행 (윈도우는 위 사이트에서 다운로드 후 설치)
      • $ brew install go
      • 설치 확인
      • $ go version go1.17.6 darwin/arm64
      • Go 환경설정
      • $ go env -w GOPRIVATE=gitlab.om
    • buf 설치
      • 설치 방법 : 터미널에 아래 명령어 실행
      • $ brew install bufbuild/buf/buf
      • 설치 확인
      • $ buf --version 1.4.0
    • grpc 패키지 설치
      • $ go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
      • $ go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
      • $ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
      • $ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
  4. grpc 패키지 설치
  5. 더보기
    // 패키지가 잘 설치 안됬을때 ... 
    brew install bufbuild/buf/buf 

    go install \
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest \  github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest \  google.golang.org/protobuf/cmd/protoc-gen-go@latest \
    google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
  6. 위 설정후... go 위치와 grpc 설치한 위치(bin) 이 동일한지 확인
  7. 이후 grpc 동작 안할 경우 ( path 설정 )

    1. Run vim ~/.bash_profile
    2. Add:
    3. export GO_PATH=~/go export PATH=$PATH:/$GO_PATH/bin
    4. Run source ~/.bash_profile
    5. 참고 : https://stackoverflow.com/questions/57700860/error-protoc-gen-go-program-not-found-or-is-not-executable

 

 

7. makefile 변경 ( 이건 나만 해당 테스트일 경우 )

// from line3
find ./protos -name "*.pb.go" -exec sed -i "" 's/,omitempty//g' {} \;
// to line3
find ./protos -name "*.pb.go" -exec sed -i 's/,omitempty//g' {} \;

 

 

--- 트러블 슈팅

https://stackoverflow.com/questions/57700860/error-protoc-gen-go-program-not-found-or-is-not-executable

위에걸로 테스트해보다가... 

sudo apt install protobuf-compiler

컴파일러를 설치했었다. 컴파일러가 이상하게 동작해서... 에러발생. 지우고 go path 설정하니 잘 설정됨

반응형