Back to blog

Solving my own routing problems with go-route-gen

2024-04-10

I got really tired of manually syncing my Go routes with my TypeScript frontend. It felt like I was doing the same work twice, and I kept making mistakes in the endpoint strings.

Scratching an itch

I built go-route-gen because I wanted to see if I could use Go's AST packages to find my routes automatically. I'm not an expert in compilers, but tinkering with the go/ast package taught me a lot about how code is actually structured.

Why I didn't use existing tools

I looked at things like tRPC, but they felt a bit too heavy for what I needed. I just wanted to keep using standard net/http handlers and Axios, but with some extra safety.

What happened

It started as a small script, but it worked well enough that I decided to publish it. Now I use it in all my Go projects. It's not perfect, but it saves me a lot of time and prevents those annoying "404 Not Found" errors that come from simple typos.

I'm still learning how to make it better, but it's been a fun experiment so far.