The genjwt tool is a code generator used to create JWT (JSON Web Token) related Go code. It generates interfaces, structs, constructors, getters, and methods like Has, Get, Set, Remove, UnmarshalJSON, MarshalJSON, Keys, and a Claims iterator.
Key technical characteristics of the generated code include:
- Multi-package support: It can target both
jwt and openid packages. If targeting openid, it prepends jwt. to cross-package type references. - Specialized Marshaling: It handles specific JWT field types with custom logic:
audience: Uses json.MarshalAudience with flattening options.types.NumericDate: Converted to a Unix timestamp via .Unix().[]byte: Encoded as a Base64 string.- Other types: Standard JSON marshaling.
- Claims Iteration: Uses Go 1.22+
iter.Seq2 for the Claims() method.