Skip to content
Discussion options

You must be logged in to vote

在mian.go加入以下代码:
defer func() { if r := recover(); r != nil { fmt.Println("捕获到 panic:", r) buf := make([]byte, 1<<16) // 64KB 缓冲 stackSize := runtime.Stack(buf, false) fmt.Printf("📌 调用栈:\n%s\n", string(buf[:stackSize])) os.Exit(2) } }()

从报错代码中我们得知是server模块下的server.go出错了,通过打印得知问题出在global.CONF.Conn.Port,这个port因为hook.go中settingRepo.GetValueByKey("ServerPort")被重新赋值为字符串port,因为我不知道 settingRepo.GetValueByKey("ServerPort")从什么地方取值,作用是什么,所以无法修改bug,我们只需要在server.go中对global.CONF.Conn.Port重新赋值即可解决

因为字符串不是真正的端口,所以会报错前面截图中的listen tcp4: lookup tcp4/port: unknown port

并且viper.go代码中的app.yaml路径被写死,导致无法读取配置文件,这也是导致无法本地运行的原因,可以使用以下代码动态获取app.yaml,以下代码是获取项目的根目录,可以进行后续拼接
func (u *SettingRepo) UpdateOrCreate(key,…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@chengjia604
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by chengjia604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #10082 on August 20, 2025 14:37.