go-zero
go-zero copied to clipboard
Better loading of configuration
- [x] update json tags
- [ ] Update goctl template
Redis only works if specified from yml like this
Redis:
Host: redis:6379
or
Redis:
- Host: redis:6379
someone take a look at this prob
also default tag loading is working as expected for rest config but for redis config we have to specify manually each and every field in yaml. Otherwise they are filled with default null values
config.yml
Redis:
Host: redis:6379
config output
```json
{
...
{
"Redis": [
{
"Host": "redis:6379",
"Type": "",
"Pass": "",
"Tls": false,
"Weight": 0
}
]
}
...
}
type, weight, have default values but not loaded
specifying explicitly like this working great.
Redis:
Host: redis:6379
Type: node
Weight: 100
someone fix this to load default from tags. @kevwan can you take a look at this
i think goctl template needs to be changed with this
main.go
```go
import "github.com/num30/config"
func main() {
var c cfg.Config
// search for config file in the etc folder without caring for the file extension
// Prority: flags > env > config file
err := config.NewConfReader("config").WithSearchDirs("etc", ".").Read(&c)
if err != nil {
log.Fatalf("error reading config: %v", err)
}
// ....
}
also it would be nice if goctl generates a config.yml file instead of <servicename>.yaml file
I don't think the change works well for the existing code.
I don't think the change works well for the existing code.
why not? only thing to change is just the tags and main.go code. Everything works just as before
@kevwan can you explain what is the usage of optional=CertFile.
CertFile string `json:",optional"`
CertKeyFile string `json:",optional=CertFile"`
CACertFile string `json:",optional=CertFile"`
@kevwan can you explain what is the usage of
optional=CertFile.CertFile string `json:",optional"` CertKeyFile string `json:",optional=CertFile"` CACertFile string `json:",optional=CertFile"`
It means that if CertFile has value, then CertKeyFile and CACertFile have values.
@kevwan can you explain what is the usage of
optional=CertFile.CertFile string `json:",optional"` CertKeyFile string `json:",optional=CertFile"` CACertFile string `json:",optional=CertFile"`It means that if CertFile has value, then CertKeyFile and CACertFile have values.
So, If I provide certfile, then certkeyfile and cacertfile are also mandatory or optional.
@kevwan Fixed linux lint error. Please try and run the workflow again
@kevwan this is complete
@kevwan please take a look
This PR is important for "12 Twelve Factor" compliance. Please approve this PR or close it, so I know whether I can adopt this framework. 谢谢
@kevwan please try to merge it in the next release. I've been waiting for a month for better config loading