46 lines
627 B
Go
46 lines
627 B
Go
/*
|
|
Package bitmask handles a flag-like opt/bitmask system.
|
|
|
|
See https://yourbasic.org/golang/bitmask-flag-set-clear/ for more information.
|
|
|
|
To use this, set constants like thus:
|
|
|
|
package main
|
|
|
|
import (
|
|
"r00t2.io/goutils/bitmask"
|
|
)
|
|
|
|
const OPTNONE types.MaskBit = 0
|
|
const (
|
|
OPT1 types.MaskBit = 1 << iota
|
|
OPT2
|
|
OPT3
|
|
// ...
|
|
)
|
|
|
|
var MyMask *MaskBit
|
|
|
|
func main() {
|
|
MyMask = types.NewMaskBit
|
|
|
|
MyMask.AddFlag(OPT1)
|
|
MyMask.AddFlag(OPT3)
|
|
|
|
_ = MyMask
|
|
}
|
|
|
|
This would return true:
|
|
|
|
MyMask.HasFlag(OPT1)
|
|
|
|
As would this:
|
|
|
|
MyMask.HasFlag(OPT3)
|
|
|
|
But this would return false:
|
|
|
|
MyMask.HasFlag(OPT2)
|
|
*/
|
|
package bitmask
|