Skip to content

Commit

Permalink
refactor: 配置文件补充port和debug字段,新增makefile文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Penryn committed Oct 31, 2024
1 parent ab7c28e commit 43691fa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
server:
port: "8080"
debug: true

database:
name: 4u_db
host: "127.0.0.1"
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"4u-go/app/midwares"
"4u-go/app/utils/log"
"4u-go/config/config"
"4u-go/config/database"
"4u-go/config/router"
"4u-go/config/session"
Expand All @@ -13,6 +14,10 @@ import (
)

func main() {
// 如果配置文件中开启了调试模式
if !config.Config.GetBool("server.debug") {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
r.Use(cors.Default())
r.Use(midwares.ErrHandler())
Expand All @@ -30,7 +35,7 @@ func main() {
}
router.Init(r)

err := r.Run()
err := r.Run(":" + config.Config.GetString("server.port"))
if err != nil {
zap.L().Fatal(err.Error())
}
Expand Down
30 changes: 30 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 设置环境变量
CGO_ENABLED=0
GOOS=linux
GOARCH=amd64

# Go 文件
TARGET=main

# 默认目标
all: build

# 构建目标
build:
@echo "Building $(TARGET)..."
go build -o $(TARGET) $(TARGET).go

# 编译为 Linux 目标
build-linux:
@echo "Building $(TARGET) for $(GOOS)/$(GOARCH)..."
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -o $(TARGET) $(TARGET).go

# 清理生成的文件
clean:
@echo "Cleaning up..."
rm -f $(TARGET)

# 运行程序
run: build
@echo "Running $(TARGET)..."
./$(TARGET)

0 comments on commit 43691fa

Please sign in to comment.