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

RegFunc中支持返回string的custom type吗 #80

Open
byteneco opened this issue Apr 5, 2024 · 0 comments
Open

RegFunc中支持返回string的custom type吗 #80

byteneco opened this issue Apr 5, 2024 · 0 comments

Comments

@byteneco
Copy link

byteneco commented Apr 5, 2024

场景

对自定义枚举值想调用自己的validate method

比如

type Status string

func (s Status) Validate() error { ... }

type Entity struct {
    Status Status `vd:"evalfn($)"`
}

type ValidateFn interface {
	Validate() error
}

func useValidateFn(args ...interface{}) error {
	target, ok := args[0].(ValidateFn)
	if !ok {
		return fmt.Errorf("evalfn need struct implement ValidateFn interface")
	}
	return target.Validate()
}

这里args[0]的值类型会是string

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

1 participant