Go Bitwise Flags and Bitmasks: Configuration Pattern Guide

TL;DR AI
2 min readKey summary
ConfigFlags is an int type used for configuration flags.
iota can automatically generate bit positions in a constant block.
Example flags include EnableCompression = 1 << iota, SkipValidation = 2, and LogQueries = 4.
OR combines flags, AND checks them, XOR toggles them, and &^ clears them.
Another example uses 1, 2, 4, and 8 for DumpHeaders, DumpBodies, DumpRequests, and DumpResponses; Red is 0b00000001.
