init project

This commit is contained in:
daniel.w 2024-08-20 01:07:16 +08:00
commit 774db25eaa
3 changed files with 123 additions and 0 deletions

20
.gitignore vendored Normal file
View File

@ -0,0 +1,20 @@
.idea/
go.sum
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# IDE config
.idea
.vscode
bench.txt

4
go.work Normal file
View File

@ -0,0 +1,4 @@
go 1.22
use ./errors
use ./validator

99
readme.md Normal file
View File

@ -0,0 +1,99 @@
# golang-common
## Current modules
| module | latest version |
|---------------------|----------------|
| [error](errors) | v1.0.0 |
| [validator](validator) | 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
```