You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
1.6 KiB

4 years ago
package flag
//go:generate stringer -type=Flag -linecomment
type Flag int
const (
String Flag = 0 // string
Required Flag = 1 << iota // required
Array // array
Int // int
Int64 // int64
Uint // uint
Uint64 // uint64
Float64 // float64
Bool // bool
Duration // duration
Time // time
Any // any
)
func (i Flag) With(v Flag) Flag {
return i | v
4 years ago
}
func (i Flag) IsString() bool {
return i|Required|Array^Required^Array == 0
4 years ago
}
func (i Flag) IsRequired() bool {
return i&Required > 0
4 years ago
}
func (i Flag) IsArray() bool {
return i&Array > 0
4 years ago
}
func (i Flag) IsInt() bool {
return i&Int > 0
4 years ago
}
func (i Flag) IsInt64() bool {
return i&Int64 > 0
4 years ago
}
func (i Flag) IsUint() bool {
return i&Uint > 0
4 years ago
}
func (i Flag) IsUint64() bool {
return i&Uint64 > 0
4 years ago
}
func (i Flag) IsFloat64() bool {
return i&Float64 > 0
4 years ago
}
func (i Flag) IsBool() bool {
return i&Bool > 0
4 years ago
}
func (i Flag) IsDuration() bool {
return i&Duration > 0
4 years ago
}
func (i Flag) IsTime() bool {
return i&Time > 0
4 years ago
}
func (i Flag) IsAny() bool {
return i&Any > 0
4 years ago
}
//nolint:cyclop
func (i Flag) Type() Flag {
4 years ago
switch {
case i.IsInt():
4 years ago
return Int
case i.IsInt64():
4 years ago
return Int64
case i.IsUint():
4 years ago
return Uint
case i.IsUint64():
4 years ago
return Uint64
case i.IsFloat64():
4 years ago
return Float64
case i.IsBool():
4 years ago
return Bool
case i.IsDuration():
4 years ago
return Duration
case i.IsTime():
4 years ago
return Time
case i.IsAny():
4 years ago
return Any
default:
return String
}
}