본문 바로가기
728x90
반응형

go4

[Go] Publishing modules - pkg.go.dev 에 package 올리기 현재 개발된 go module을 다른 프로젝트에서 import하여 사용해야할 경우가 있다. 이때 개발된 go module을 github repo에 푸시하고 pkg.go.dev에 publish하여 이를 다른 프로젝트에서 import해서 사용하는 방법을 알아보자. 1. Go Module 생성 Go Module을 아직 만들지 않았다면 아래와 같이 생성 $ mkdir greetings $ cd greetings init module $ go mod init gihub.com/guru-corp/greetings go: creating new go.mod: module gihub.com/guru-corp/greetings $ cat go.mod module gihub.com/guru-corp/greetings go.. 2022. 6. 21.
[Go] defer / panic 함수 1. defer defer 함수는 지연실행 함수로 특정 함수를 나중에 실행하게 하도록 하는 함수이며 이 호출 시점은 defer를 호출하는 함수가 리턴하기 직전에 호출이 됩니다. 예제 package main import "fmt" func main() { fmt.Println("function start") defer func() { fmt.Println("First print of defer") }() defer func() { fmt.Println("Second print of defer") }() fmt.Println("function end") } 확인 $ go run main.go function start function end Second print of defer First print of .. 2022. 5. 23.
[Go] grpc connection timeout 추가 grpc connection timeout을 추가하기 1. Dial 사용 Dial은 주어진 주소로 client connection을 생성합니다. Dial 함수의 구현부를 보면 DialContext를 호출하기 때문에 Dial 함수는 deprecated되었고 DialContext를 통해 구현하는것이 좋습니다. // Dial 구현부 func Dial(target string, opts ...DialOption) (*ClientConn, error) { return DialContext(context.Background(), target, opts...) } grpc.WithTimeout 사용 connection, err := grpc.Dial(address, grpc.WithInsecure(), grpc.Wi.. 2022. 5. 23.
[Go] Go 설치 for Mac Go 설치하기 https://go.dev/doc/install 에서 Mac용 설치 파일을 다운로드. 다운로드한 파일을 클릭 후 설치 진행. 설치 완료 후 go 명령어를 사용해서 버전 확인. $go version go version go1.17.2 darwin/amd64 brew를 통해 설치 brew install go 를 통해 go 설치 $brew install go ==> Downloading https://ghcr.io/v2/homebrew/core/go/manifests/1.17.2 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebre.. 2021. 12. 9.
728x90
반응형