library-go/readme.md

100 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# golang-common
## Current modules
| module | latest version |
|--------------------------------------------------------|----------------|
| [error](errors) | v1.0.0 |
## 如何新增Module
假設新增一個module叫 monitoring/grafana
- init
```bash
mkdir -p monitoring/grafana
cd ./monitoring/grafana
go mod init yt.com/backend/common.git/monitoring/grafana
go work use ./monitoring/grafana
```
- befor commit
建議測試覆蓋率盡量達到80%
```bash
before-commit-check
```
- commit
```bash
git add ./monitoring/grafana
git commit -m "feat: add monitoring/grafana module"
git tag "monitoring/grafana/v1.0.0"
git push origin monitoring/grafana/v1.0.0
```
- launch merge request and codereview
## 如何使用私有Module
強制git使用ssh方式而不是https:
```bash
git config --global --add url."git@code.30cm.net:".insteadOf "https://code.30cm.net/"
# 檢查語法
vim ~/.gitconfig
```
設定go env
```bash
export GOPRIVATE="code.30cm.net"
```
產生ssh-key
請參考 [github ssh](https://docs.github.com/en/authentication/connecting-to-github-with-ssh) , [gitlab ssh](https://docs.gitlab.com/ee/user/ssh.html)
add ssh key to the ssh-agent
請參考 [Adding your SSH key to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)
```bash
$ eval "$(ssh-agent -s)"
> Agent pid 59566
```
```bash
$ touch ~/.ssh/config
```
```
Host code.30cm.net
Hostname code.30cm.net
User Daniel.W
IdentityFile ~/.ssh/id_rsa
```
```bash
$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519
```
使用 yt.com domain git clone repo
```bash
git clone git@code.30cm.net:backend/layout-template.git
```
在自己repo底下執行:
```bash
go clean -modcache
go mod tidy
or
go get -x yt.com/backend/common.git/transport/http/health@1.0.0
```