+
Skip to content

Custom value matchers #15

@tomakado

Description

@tomakado

I think sometimes there are cases where you have enum-like fields based on integers:

type Task struct {
  // ...
  Status MyStatusType
  // ...
}

type MyStatusType uint8

const (
  StatusTodo MyStatusType = iota
  StatusInProgress
  StatusDone
)

However, you might want to match these with human-friendly values such as todo, in progress, done, etc.

For such cases, it would be handy to have the possibility to define a custom value matcher. To keep it simple, we can assume that these custom values are stored as strings. In that scenario, we can simply try to call the String() method on the field (for example, by checking if the value implements fmt.Stringer) before performing the actual matching. Alternatively, to make it more predictable and handy, we could expect a separate method that performs the same function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载