Skip to content

how to deal $ in config file #4870

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

Open
lvphpwb opened this issue May 19, 2025 · 5 comments
Open

how to deal $ in config file #4870

lvphpwb opened this issue May 19, 2025 · 5 comments
Assignees
Labels
answered Marks an issue as answered

Comments

@lvphpwb
Copy link

lvphpwb commented May 19, 2025

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

    Price: '$1.0'
  2. 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.

@kevwan kevwan self-assigned this May 19, 2025
@kevwan
Copy link
Contributor

kevwan commented May 19, 2025

Use the latest version. It works for "$1.0" in config.

@kevwan kevwan added the fixed Indicates an issue that has been fixed in latest version label May 19, 2025
@lvphpwb
Copy link
Author

lvphpwb commented May 20, 2025

使用1.8.3版本还是有问题

@kevwan
Copy link
Contributor

kevwan commented May 20, 2025

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.

@lvphpwb
Copy link
Author

lvphpwb commented May 21, 2025

conf.MustLoad(*configFile, &c, conf.UseEnv())

@kevwan
Copy link
Contributor

kevwan commented May 24, 2025

os.ExpandEnv() doesn't support escaping $ char. So if you want to use $ char, don't use conf.UseEnv().

@kevwan kevwan added answered Marks an issue as answered and removed fixed Indicates an issue that has been fixed in latest version labels May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Marks an issue as answered
Projects
None yet
Development

No branches or pull requests

2 participants