Discoverable functional options pattern

Hello. Today’s will be a quick post. Everyone knows and loves/hates functional options1 in Go. The biggest gripe people get with it is, that the options aren’t discoverable and that there is no IDE support for nicely auto-completing options. My thought about this was that, what if we would just hang it on a struct? Let’s see how that looks. Consider this normal server builder with options: type Server struct { Name string Address string Port int } func WithName(name string) ServerOptFn { return func(s *Server) { s....

July 1, 2024 · 2 min · hannibal

crd-to-yaml now supports HTML as an output format

Hello! Just wanted to give an update to my crd-to-sample-yaml tool. It, now, supports creating a standalone HTML output. Why, you may ask? Well, now you can host the generated content as a static page on your website. That’s pretty handy. Here is a sample output: Go and get it while it’s hot in version v0.4.0. That’s all. Thanks for reading!

May 9, 2024 · 1 min · hannibal

Generic dig for map key using typed parameters

Generic dig for map key using typed parameters Hello! I was fiddling with a way of getting out values from a map that is of format map[string]any. But I wanted my type safety as well. This was coming from digging out keys from a Metadata field. The metadata was in a JSON format. This is what I came up with: / FetchValueFromMetadata fetches a key from a metadata if it exists....

February 27, 2024 · 2 min · hannibal

CRD to YAML as WASM website

CRD to YAML as WASM website A while ago, I wrote about Generating Sample YAML files from CRDs. It’s a tool I created that lives here. It has a front-end service as well for convenience. I wrote it in a traditional client-server manner. It’s running from a Docker Swarm container. But, as I was thinking about it, nothing in this service requires interaction with a server. It gets some user input, processes it, and has some output....

December 1, 2023 · 5 min · hannibal

How to deploy a Go (Golang) backend with a React frontend separately on Kubernetes - Part One

Intro Welcome. This is a longer post about how to deploy a Go backend with a React frontend on Kubernetes as separate entities. Instead of the usual compiled together single binary Go application, we are going to separate the two. Why? Because usually a React frontend is just a “static” SPA app with very little requirements in terms of resources, while the Go backend does most of the leg work, requiring a lot more resources....

July 23, 2020 · 14 min · hannibal

How to do a good code review

Intro Hi folks. This time, I would like to talk a little bit about code reviews. How do you do code reviews? Don’t hesitate to share it in the comments. How do I do code reviews? Well read on if you would like to know. The Top Down approach If I’m dealing with a small code change, a couple of lines here and there in the odd file first, I’ll try to understand why the review is there?...

May 11, 2020 · 6 min · hannibal

How to Make SPA refresh work with a Go backend

Intro Hi folks. Today I would like to share a quick “fix” for a problem I’ve seen popping up here and there. That is, if you have a react frontend which is a SPA app but you still want refresh to work. What do I mean by that? Consider the following… The problem You have a SPA app with a react router which navigates the user around. The app calls to a backend api which serves content of some kind....

February 17, 2020 · 4 min · hannibal

Summary of Practical Go workshop from Dave Cheney

Intro Hi folks. So there is this workshop from Dave Cheney. And I thought I’d draw a sort of summary of that workshop. Right-click->Open Image for higher resolution. Cheers, Gergely.

October 10, 2019 · 1 min · hannibal

Efferent and Afferent metrics in Go

Intro Hi folks! Today I would like to write about a metric that I read in a book called Clean Architecture from Robert Cecil Martin ( Uncle Bob ). Abstract The metrics I mean are Efferent and Afferent coupling in packages. So you, dear reader, don’t have to navigate away from this page, here are the descriptions pasted in: Afferent couplings (Ca): The number of classes in other packages that depend upon classes within the package is an indicator of the package’s responsibility....

April 21, 2019 · 6 min · hannibal

Go SSH with Host Key Verification

Hi folks. Following a long search and reading lots of debates and possibilities of doing SSH within Go, I was shocked to see that not a great many tools and people use SSH with host key verification. What I usually see is this: HostKeyCallback: ssh.InsecureIgnoreHostKey() This is terrible. Now, I realise that doing HostKeyVerification can be tedious, but don’t fear. It’s actually easy now that the Go team provided the knownhosts subpackage in their crypto SSH package located here: KnownHosts....

February 17, 2019 · 2 min · hannibal