Go CLIs: Creating Subcommands and Flags

Adding Subcommands to Go CLIs Command Line Interfaces (CLIs) use subcommands and flags to enable different program features. A subcommand is a grouping of related features, and flags are options for controlling those features. The openssl command provides a great example of subcommands and flags. openssl rand -base64 8 will generate 8 random bytes of data with hexadecimal output. The subcommand is “rand” and “-base64” is the flag. Other openssl subcommands like “s_client” or “x509”, provide different features and each has their own options. ...

September 29, 2025 · 1265 words

Go Generics: A Real World Use Case

Until recently, I haven’t had many opportunities to use Go’s generics. I ran into a case where generics make sense. Best of all, this isn’t a contrived example. I’m working on a project and using openAPI to generate API contracts. One of the generated structs contains optional fields implemented as pointers. The only required field is Name. const ( Gzip PostPailsCompression = "gzip" None PostPailsCompression = "none" ) type PostPails struct { Compression *PostPailsCompression `json:"compression,omitempty"` // MaxArchiveSize Max size (bytes) before rotating to a new archive. MaxArchiveSize *int `json:"max_archive_size,omitempty"` // Name Name of the new pail Name string `json:"name"` } I need to populate the struct with values when writing unit tests. But dealing with pointers in Go test code usually results in using temporary variables. It’s not bad, but there’s some visual noise. ...

July 11, 2025 · 325 words

OpenAPI in Practice: Go Server + Python Client from Spec

OpenAPI is a specification for documenting HTTP APIs for both humans and machines to consume. As OpenAPI is a specification, it is language agnostic. OpenAPI relies on generators for translating the specification. There’s more than just documentation that’s generated. Generators also create language-specific interfaces, tooling, and contracts. In some ways the OpenAPI pattern reminds me of either protobuf with gRPC or ORM schema-first design. As a result, a declarative API is created by the tooling. ...

July 4, 2025 · 1149 words