zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.42k stars 3.97k forks source link

打包生成Linux执行文件.总是报错:config file etc/****.yaml, field "Host" is not set 2024/07/01 #4223

Open zenghnn opened 5 months ago

zenghnn commented 5 months ago

如题,本机环境为windows11。 本地debug、打包成.exe文件执行均正常 但是打包成Linux程序时,总是报错: config file etc/****.yaml, field "Host" is not set 2024/07/01 配置添加了Host也不行。升级成1.6.6之后还是报错: 16:29:18 error: config file etc/centerrpc.yaml, field "Cache[1].Host" is not set

换成mac进行打包也不行。最后打开源码找到了/stores/redis/conf.go文件,发现Conf定义如下: // A RedisConf is a redis config. RedisConf struct { Host string Type string json:",default=node,options=node|cluster" Pass string json:",optional" Tls bool json:",optional" NonBlock bool json:",default=true" // PingTimeout is the timeout for ping redis. PingTimeout time.Duration json:",default=1s" }

怀疑Host没有添加tag而导致的错误,到本地进行修改: Host string json:",default=127.0.0.1" 打包,上传,执行,成功!

足足让我折腾了三天 你们这也太坑了,怎么还能漏这个?

kevwan commented 5 months ago

Not the problem, you add json:",default=127.0.0.1" is just using default value.

You need to set Host value in your config file.

Would you please show me the content of your centerrpc.yaml? Or is your path correct?

Owen-Zhang commented 5 months ago

其实up主的意思就是 Host必填,其它要不可选或者使用默认, 不过提示信息应该更准确一些(包含一些上下文信息)

Issues-translate-bot commented 5 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In fact, the main meaning of up is that Host is required. Others should be optional or use the default. However, the prompt information should be more accurate (including some contextual information)

zenghnn commented 4 months ago

Not the problem, you add json:",default=127.0.0.1" is just using default value.

You need to set Host value in your config file.

Would you please show me the content of your centerrpc.yaml? Or is your path correct?

这是我的配置文件内容: Name: center-rpc Host: 0.0.0.0 ListenOn: 0.0.0.0:1002 Mode: dev Timeout: 60000

我是使用标准模板生成的项目工程,所以每个.yaml配置文件我都肯定填写了Host地址,而且修改了好几次(因为提示确实一开始就指向了Host的配置):0.0.0.0或者127.0.0.1 不过解决了就好,希望大家都不会再有这个问题

JackGod001 commented 2 months ago

16:29:18 error: config file etc/centerrpc.yaml, field "Cache[1].Host" is not set

这个行数应该说的是你cache 缓存配置那里没写host 吧? 如果模板生成的应该是第二行默认给了值的

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


16:29:18 error: config file etc/centerrpc.yaml, field "Cache[1].Host" is not set

This number of lines should mean that you did not write host in the cache configuration, right? If the template generates it, it should be the value given by default in the second line.