移除 APP_PORT,更新 Docker Compose 配置

This commit is contained in:
2025-04-21 13:57:57 +08:00
parent 91ef0b0ac5
commit 806dca928f
5 changed files with 24 additions and 16 deletions

4
.gitignore vendored
View File

@@ -1,11 +1,13 @@
.idea/
.vscode/
.vscode/*
!.vscode/launch.json
.env
.env.*
!.env.example
bin/
*.exe
*.pem
*.http

16
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "main",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/main",
"cwd": "${workspaceFolder}",
}
]
}

8
pkg/env/env.go vendored
View File

@@ -13,7 +13,6 @@ import (
var (
AppName = "platform"
AppPort string
)
func loadApp() {
@@ -21,13 +20,6 @@ func loadApp() {
if _AppName != "" {
AppName = _AppName
}
_AppPort := os.Getenv("APP_PORT")
if _AppPort != "" {
AppPort = _AppPort
} else {
panic("环境变量 APP_PORT 的值不能为空")
}
}
// endregion

View File

@@ -31,7 +31,7 @@ services:
- postgres
- redis
ports:
- ${APP_PORT}
- 8080:8080
env_file:
- ../../.env

View File

@@ -2,7 +2,6 @@ package web
import (
"net/http"
"platform/pkg/env"
g "platform/web/globals"
"runtime"
@@ -13,9 +12,9 @@ import (
"github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/google/uuid"
"github.com/jxskiss/base62"
)
import _ "net/http/pprof"
_ "net/http/pprof"
)
type Config struct {
Listen string
@@ -72,9 +71,8 @@ func (s *Server) Run() error {
}()
// listen
port := env.AppPort
slog.Info("Server started on :" + port)
err := s.fiber.Listen(":" + port)
slog.Info("Server started on :8080")
err := s.fiber.Listen(":8080")
if err != nil {
slog.Error("Failed to start server", slog.Any("err", err))
}