Last active
May 29, 2023 11:40
-
-
Save francoishill/d7d74616e2945aeb91f3 to your computer and use it in GitHub Desktop.
Golang enums and checking if the value has a specific flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type verbosityEnum int | |
const ( | |
NoneVerbosity verbosityEnum = 1 << iota | |
ErrorVerbosity verbosityEnum = 2 | |
WarningVerbosity verbosityEnum = 4 | |
InfoVerbosity verbosityEnum = 8 | |
AllVerbosity verbosityEnum = 16 | |
) | |
func (this verbosityEnum) HasFlag(flag verbosityEnum) bool { | |
return this|flag == this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, not a whole lot of info out there on bitwise.