Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

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

@byteneco

Description

@byteneco

场景

对自定义枚举值想调用自己的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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions