본문 바로가기
Programming/Go

[Go] Publishing modules - pkg.go.dev 에 package 올리기

by guru_k 2022. 6. 21.
728x90
반응형

현재 개발된 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 1.18

2. Update modules and run test

$ go mod tidy

$ $ go test ./...
ok      github.com/guru-corp/greetings       0.015s

3. Push repo

$ git add .
$ git commit -m 'feat: update moduels'
$ git push origin

4. Tag version number

version 을 위한 tag를 git tag를 생성하여 업데이트 해준다.

이때 Go 에서 사용되는 버전 넘버링 규칙은 https://go.dev/doc/modules/version-numbers 에서 확인 가능

$ git tag v0.0.0
$ git push origin v0.0.0

5. Publish module

$ GOPROXY=proxy.golang.org go list -m github.com/guru-corp/greetings@v0.0.0
github.com/guru-corp/greetings v0.0.0

6. Get module 

$ go get github.com/guru-corp/grettings@v0.0.0
728x90
반응형

'Programming > Go' 카테고리의 다른 글

[Go] defer / panic 함수  (0) 2022.05.23
[Go] grpc connection timeout 추가  (0) 2022.05.23

댓글