Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: 修改config/local.yml的MySQL 数据库连接, 然后使用 nunu run ,报错, 只有使用 go run ./cmd/server -conf=config/prod.yml 才能正确启动 #26

Closed
formal-you opened this issue Aug 30, 2023 · 2 comments

Comments

@formal-you
Copy link

我在使用 [nunu-layout-advanced]模板后,修改了 conf/local.yml, conf/prod.yml 的 MySQL 数据库连接, 并修改了 internal/repository/repository.go:30

	db, err := gorm.Open(mysql.Open(conf.GetString("data.mysql.nunu")), &gorm.Config{})// 使用我自己创建数据库

随后使用 nunu run 命令启动 报错:

 D:/LeetCode/Golang/Go-Web/github.com/formal-you/nunu-hello/internal/repository/repository.go:30
[error] failed to initialize database, got error dial tcp 127.0.0.1:3306: connectex: No connection could be made because the 
target machine actively refused it.
panic: dial tcp 127.0.0.1:3306: connectex: No connection could be made because the target machine actively refused it.

goroutine 1 [running]:
github.com/formal-you/nunu-hello/internal/repository.NewDB(0x0?)
        D:/LeetCode/Golang/Go-Web/github.com/formal-you/nunu-hello/internal/repository/repository.go:32 +0x134        
main.newApp(0xc00005ff20?, 0xc00000a100)
        D:/LeetCode/Golang/Go-Web/github.com/formal-you/nunu-hello/cmd/server/wire_gen.go:28 +0x1b5
main.main()
        D:/LeetCode/Golang/Go-Web/github.com/formal-you/nunu-hello/cmd/server/main.go:16 +0x5c
exit status 2

但当我改为使用 go run ./cmd/server -conf=config/prod.yml

D:\LeetCode\Golang\Go-Web\github.com\formal-you\nunu-hello>go run ./cmd/server -conf=config/prod.yml
load conf file: config/prod.yml
{"level":"info","ts":1693402524.6552145,"caller":"server/main.go:20","msg":"server start","host":"http://172.27.32.1:8000"}  

能够正常启动, conf/local.yml, conf/prod.yml 我都同步修改了MySQL 数据库连接. 按说 使用 go run ./cmd/server -conf=config/local.yml 不会报错, 但同样会报上面的错误.

@codingcn
Copy link
Member

如果想指定nunu run时的配置文件路径,当前不支持通过命令行的方式指定。

我们暂时可以用过环境变量指定配置文件:

linux or macos

APP_CONF=./config/prod.yml nunu run

windows(注意两个命令需分开执行)

$env:APP_CONF="./config/prod.yml"

nunu run

@formal-you
Copy link
Author

我说的是: nunu run 默认加载 ./config/local.yml, 但我的 conf/local.yml, conf/prod.yml 我都同步修改了MySQL 数据库连接, 我想知道到, nunu run , go run ./cmd/server -conf=config/local.yml 这两个为什么都会报错.

@formal-you formal-you changed the title error: 修改config/local.yml的MySQL 数据库连接, 然后使用 nunu run ,报错, 使用 go run ./cmd/server -conf=config/.yml 才能正确启动 error: 修改config/local.yml的MySQL 数据库连接, 然后使用 nunu run ,报错, 只有使用 go run ./cmd/server -conf=config/prod.yml 才能正确启动 Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants