From 774db25eaad95593d3efc5cc8e73861d9f4634f3 Mon Sep 17 00:00:00 2001 From: "daniel.w" Date: Tue, 20 Aug 2024 01:07:16 +0800 Subject: [PATCH] init project --- .gitignore | 20 +++++++++++ go.work | 4 +++ readme.md | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 go.work create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e52f815 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/go.work b/go.work new file mode 100644 index 0000000..09b6b3e --- /dev/null +++ b/go.work @@ -0,0 +1,4 @@ +go 1.22 + +use ./errors +use ./validator diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..436abb8 --- /dev/null +++ b/readme.md @@ -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 +```