octolab / config

🎛 Configuration toolkit.
https://go.octolab.org/toolkit/config
MIT License
0 stars 0 forks source link

input: Regexp type for kelseyhightower/envconfig integration #4

Open kamilsk opened 2 years ago

kamilsk commented 2 years ago

Motivation: extend flag types.

Draft

type Regexp regexp.Regexp

func (reg *Regexp) Decode(value string) error {
    raw, err := regexp.Compile(fmt.Sprintf(`^%s$`, value))
    if err != nil {
        return err
    }

    *reg = Regexp(*raw)
    return nil
}

func (reg *Regexp) Matcher() *regexp.Regexp {
    return (*regexp.Regexp)(reg)
}

See https://github.com/kelseyhightower/envconfig#custom-decoders.