go-zero
go-zero copied to clipboard
how to deal $ in config file
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior, if applicable:
-
The code is
Price: '$1.0' -
The error is
Price .0
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Environments (please complete the following information):
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]
More description Add any other context about the problem here.
Use the latest version. It works for "$1.0" in config.
使用1.8.3版本还是有问题
main.go
package main
import (
"flag"
"fmt"
"github.com/zeromicro/go-zero/core/conf"
)
type Config struct {
Price string
}
var configFile = flag.String("f", "config.yaml", "the config file")
func main() {
flag.Parse()
var c Config
conf.MustLoad(*configFile, &c)
fmt.Println(c.Price)
}
config.yaml
Price: '$1'
No problem here. You can check it.
conf.MustLoad(*configFile, &c, conf.UseEnv())
os.ExpandEnv() doesn't support escaping $ char. So if you want to use $ char, don't use conf.UseEnv().