14.4 系统配置
在本项目的系统配置模块中,需要设置系统端口号和代理服务地址。
14.4.1 基本配置
配置系统Web端口号、代理信息、时区信息,主要实现代码如下所示。
# 配置goproxy
RUN go env -w GOPROXY=https://goproxy.cn,direct
ARG VERSION
RUN echo "Version: ${VERSION}"
# 编译应用程序
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'xyhelper-web/config.Version=${VERSION}'" -a -installsuffix cgo -o xyhelper-web .
# 使用 alpine 作为基础镜像
FROM alpine:latest
# 将时区设置为 Asia/Shanghai
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apk del tzdata
# 将应用程序复制到容器内
COPY --from=build /app/xyhelper-web /usr/local/bin/xyhelper-web
# 设置环境变量
ENV PORT=8089
ENV GIN_MODE=release
# 暴露端口
EXPOSE $PORT
# 启动应用程序
CMD ["xyhelper-web"]
14.4.2 第三方库
安装系统需要的第三方库,在文件go.mod中保存了本项目需要的第三方库的信息,建议读者严格按照文件中的版本号进行安装。
require (
github.com/gabriel-vasile/mimetype v1.4.2
github.com/gin-gonic/gin v1.9.0
github.com/gogf/gf/v2 v2.3.3
github.com/xyhelper/chatgpt-go v1.0.4
)
require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/bytedance/sonic v1.8.7 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/clbanning/mxj/v2 v2.5.5 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/launchdarkly/eventsource v1.7.1 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)