From a82a843b7620033c57456242a71f5b3d22246421 Mon Sep 17 00:00:00 2001 From: shenchangbin Date: Wed, 11 Nov 2026 17:49:38 +0800 Subject: [PATCH] init project --- .gitignore | 1 + Dockerfile | 10 +++++++--- README.md | 5 +++-- cmd/api/main.go | 2 +- configs/config.yaml | 3 +++ go.mod | 4 +--- go.sum | 2 ++ internal/config/config.go | 2 +- internal/service/user_service.go | 2 +- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b454925..9c66adb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .env .env.local .DS_Store +*.local.yaml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1e9a212..5bad33c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ FROM golang:1.27.3-alpine AS builder +RUN apk add --no-cache git openssh-client +ENV GOPRIVATE=git.vitatech.com.cn +RUN git config --global url."ssh://git@git.vitatech.com.cn:12222/".insteadOf "https://git.vitatech.com.cn/" \ + && mkdir -p -m 0700 /root/.ssh WORKDIR /src -COPY proto/go.mod proto/go.sum ./proto/ COPY gin_layout/go.mod gin_layout/go.sum ./gin_layout/ WORKDIR /src/gin_layout -RUN go mod download -COPY proto /src/proto +RUN --mount=type=ssh,required=true \ + --mount=type=secret,id=git_known_hosts,target=/root/.ssh/known_hosts,required=true \ + go mod download COPY gin_layout /src/gin_layout RUN CGO_ENABLED=0 go build -trimpath -o /out/api ./cmd/api diff --git a/README.md b/README.md index 50b5f5b..efb6918 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ service 接收标准库 `context.Context`,不依赖 Gin。 在项目根目录执行: -本项目通过本地 `../proto` 模块调用 `../micro_layout`,请先按[父目录 README](../README.md) -启动 etcd 和 Micro。三个目录需要保持同级。 +本项目通过远程模块 `git.vitatech.com.cn/leo/proto.git` 调用 Micro,无需克隆 proto。 +先按 proto 仓库的 README +配置私有模块和 SSH,再按[父目录 README](../README.md)启动 etcd 和 Micro。 ```sh go mod download diff --git a/cmd/api/main.go b/cmd/api/main.go index f9b1fea..9169b0e 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -11,7 +11,7 @@ import ( "strconv" "syscall" - "example.com/layout/proto/micro_layout/client" + "git.vitatech.com.cn/leo/proto.git/micro_layout/client" "gin_layout/internal/config" "gin_layout/internal/router" diff --git a/configs/config.yaml b/configs/config.yaml index 330e24a..d17d7b5 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -2,6 +2,9 @@ app: name: gin_layout env: local +auth: + token: "local-dev-token" + server: port: 8080 mode: debug diff --git a/go.mod b/go.mod index 94b8958..51adf75 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,8 @@ module gin_layout go 1.27.3 -replace example.com/layout/proto => ../proto - require ( - example.com/layout/proto v0.0.0 + git.vitatech.com.cn/leo/proto.git v0.0.0-20261111072135-44f7964733ab github.com/gin-gonic/gin v1.12.0 github.com/spf13/viper v1.21.0 google.golang.org/grpc v1.85.0 diff --git a/go.sum b/go.sum index 6b336d4..9a98dcd 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +git.vitatech.com.cn/leo/proto.git v0.0.0-20261111072135-44f7964733ab h1:mpsW3H4YwNEx0HJxNa2UPIt1Ds4P+PpVgSJtPrOV4WQ= +git.vitatech.com.cn/leo/proto.git v0.0.0-20261111072135-44f7964733ab/go.mod h1:KHJCeohHC1l3iVDq/IbmN85OqcqY8fS2LV9MKP4jPi8= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= diff --git a/internal/config/config.go b/internal/config/config.go index 06d7a37..81df6ed 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "example.com/layout/proto/discovery" + "git.vitatech.com.cn/leo/proto.git/discovery" "github.com/spf13/viper" ) diff --git a/internal/service/user_service.go b/internal/service/user_service.go index b4eb0f0..e920b64 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -5,8 +5,8 @@ import ( "errors" "time" - "example.com/layout/proto/micro_layout/proto/user" "gin_layout/enum" + "git.vitatech.com.cn/leo/proto.git/micro_layout/proto/user" "google.golang.org/grpc/codes" "google.golang.org/grpc/status"