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

how to set slice value in env #4250

Open
leavest opened this issue Jul 16, 2024 · 1 comment
Open

how to set slice value in env #4250

leavest opened this issue Jul 16, 2024 · 1 comment
Assignees

Comments

@leavest
Copy link

leavest commented Jul 16, 2024

package main

import (
	"flag"
	"fmt"
	"os"

	"github.com/zeromicro/go-zero/core/conf"
)

type Config struct {
	User []string `json:"user,default=abc,env=USER"`
}

func main() {
	os.Setenv("USER", "abc")
	var c3 Config
	err := conf.FillDefault(&c3)
	fmt.Println(c3, err) // {[]} type mismatch for field "user", expect "slice", actual "number"
}

if not set env, it works fine
when set env it return err
how to set slice value in env

@leavest
Copy link
Author

leavest commented Jul 16, 2024

I think more examples should be added to the config documentation

@kevwan kevwan self-assigned this Jul 19, 2024
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

No branches or pull requests

2 participants