移除 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/ .idea/
.vscode/ .vscode/*
!.vscode/launch.json
.env .env
.env.* .env.*
!.env.example !.env.example
bin/ bin/
*.exe
*.pem *.pem
*.http *.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 ( var (
AppName = "platform" AppName = "platform"
AppPort string
) )
func loadApp() { func loadApp() {
@@ -21,13 +20,6 @@ func loadApp() {
if _AppName != "" { if _AppName != "" {
AppName = _AppName AppName = _AppName
} }
_AppPort := os.Getenv("APP_PORT")
if _AppPort != "" {
AppPort = _AppPort
} else {
panic("环境变量 APP_PORT 的值不能为空")
}
} }
// endregion // endregion

View File

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

View File

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