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

config file xxx, type mismatch for field "xxx", expect "string", actual "string" #3622

Closed
lee86 opened this issue Oct 13, 2023 · 2 comments · Fixed by #3625
Closed

config file xxx, type mismatch for field "xxx", expect "string", actual "string" #3622

lee86 opened this issue Oct 13, 2023 · 2 comments · Fixed by #3625
Assignees

Comments

@lee86
Copy link

lee86 commented Oct 13, 2023

Describe the bug
If the field "password" is configured as a string in config.go, when the field "password" is set to a pure number in config.yml, an error will be reported and exit

To Reproduce

  1. The config.yml is
    config.yml

    password: 123456
  2. The config.go is
    config.go

    type Config struct {
      Password   string   `json:"password"`
    }
  3. The main.go is
    main.go

    func main() {
     var sc Config
     conf.MustLoad("etc/config.yml", &sc)
    }
  4. The error is

    error: config file config.yml, type mismatch for field "password", expect "string", actual "string"
    

Expected behavior
The field "password" can be parsed correctly

Screenshots
image

Environments (please complete the following information):

  • OS: windows10 ltsc
  • go-zero version v1.5.5
  • goctl version 1.5.5 windows/amd64

More description

config.yml

password: "123456"

The field "password" can be parsed correctly......

@MarkJoyMa
Copy link
Collaborator

Yes, go-zero's configuration file and configuration-defined fields are similar to strong type matching. The same field is not supported for matching multiple types for the time being.

@kevwan
Copy link
Contributor

kevwan commented Oct 14, 2023

Fixed, and the error message is now:

type mismatch for field "password", expect "string", actual "number"

As you mentioned, the following is correct to parse 123456 as string.

password: "123456"

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

Successfully merging a pull request may close this issue.

3 participants