forked from fortio/fortio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynstring.go
27 lines (22 loc) · 808 Bytes
/
dynstring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2015 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.
package dflag
import (
"flag"
"fmt"
"regexp"
)
type DynStringValue = DynValue[string] // For backward compatibility
// DynString creates a `Flag` that represents `string` which is safe to change dynamically at runtime.
func DynString(flagSet *flag.FlagSet, name string, value string, usage string) *DynStringValue {
return Dyn(flagSet, name, value, usage)
}
// ValidateDynStringMatchesRegex returns a validator function that checks all flag's values against regex.
func ValidateDynStringMatchesRegex(matcher *regexp.Regexp) func(string) error {
return func(value string) error {
if !matcher.MatchString(value) {
return fmt.Errorf("value %v must match regex %v", value, matcher)
}
return nil
}
}