SHA256
1
0
AnnNet/examples/hasflag.go
2025-08-28 07:38:42 -04:00

60 lines
1.1 KiB
Go

package main
import (
"fmt"
)
const anetNone uint8 = 0
const (
anetPreRel uint8 = 1 << iota
anetUnstable
anetExperiment
anetBeta = anetPreRel | anetUnstable
anetAlpha = anetBeta | anetExperiment
)
var (
// In Golang, a byte is exactly equivalent to a uint8.
// Use the same value extracted in the example `extractversion.go`.
// A value of 0x01 (1) indicates Pre-Release flag is set, with no other myFlags set.
myFlags byte = 0x01
)
func main() {
fmt.Printf("Flags:\t%d\t%#02x\n\n", myFlags, myFlags)
// Prints:
/*
Flags: 1 0x01
*/
for flag, flagNm := range map[uint8]string{
anetPreRel: "Pre-release",
anetUnstable: "Unstable",
anetExperiment: "Experimental",
anetBeta: "Beta release",
anetAlpha: "Alpha release",
} {
fmt.Printf(
"Has flag '%s' (%d, %#02x):\t%v\n\n",
flagNm, flag, flag, myFlags&flag == flag,
)
}
// Prints:
/*
Flags: 1 0x01
Has flag 'Pre-release' (1, 0x01): true
Has flag 'Unstable' (2, 0x02): false
Has flag 'Experimental' (4, 0x04): false
Has flag 'Beta release' (3, 0x03): false
Has flag 'Alpha release' (7, 0x07): false
*/
}