Skip to content

Instantly share code, notes, and snippets.

@francoishill
Last active May 29, 2023 11:40
Show Gist options
  • Save francoishill/d7d74616e2945aeb91f3 to your computer and use it in GitHub Desktop.
Save francoishill/d7d74616e2945aeb91f3 to your computer and use it in GitHub Desktop.
Golang enums and checking if the value has a specific flag
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
}
@sikemullivan
Copy link

Thanks, not a whole lot of info out there on bitwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment