前言:
一个go项目过后,有许多的精华部分、容易违犯go语言常规的部分,总结、记录,以供后续的学习、参考和大家探讨。
1 整体架构
1.1 包结构
三层结构包:model->service->controller
中间件包:middleware
工具包:util
传输对象包:view
相应对象包:response
2 部署
docker 部署
FROM golang:latest as build
ENV GOPROXY https://goproxy.io
ENV GO111MODULE on
WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
RUN go mod download
WORKDIR /go/release
ADD . .
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o imcs-design-go main.go
FROM scratch as prod
EXPOSE 8080
COPY --from=build /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=build /go/release/imcs-design-go /
COPY --from=build /go/release/application.yaml /
CMD ["./imcs-design-go"]