목록go (2)
이야기박스
Go린이로써 가끔 git에서 context의 key로 빈 struct{}를 사용하는 것을 보고 궁금한 점이 늘 있었습니다. 그래서 오늘은 이 내용에 관한 포스팅을 작성해보려고 합니다. type key struct{} ctx = context.WithValue(ctx, key{}, "my value") // Set value myValue, ok := ctx.Value(key{}).(string) // Get value 이번 포스팅은 아래의 문서를 가져와 작성하였습니다. https://gist.github.com/ww9/4ad7b2ddfb94816a30dfdf2218e02f48 Why use empty struct{} and not int or string for context.Value() key typ..
gRPC는 java로만 개발을 해봤었는데, 이번에 go로도 사용할 기회가 생겨 테스트 코드 진행 겸 포스트를 남겨봅니다. 이번 포스팅은 아래의 gRPC 공식 문서의 Quick start를 바탕으로 작성되었습니다. Quick start This guide gets you started with gRPC in Go with a simple working example. grpc.io 사전 준비 우선 protocol buffer 파일을 이용하여 코드를 생성하기 위해 아래 라이브러리를 설치합니다. go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1..