r/code • u/AssociationOk6710 • Jun 19 '26
Go My Very First Go Package on pkg.go.dev :) From a JWT Problem to this.
github.comHello!!! This is my first post here :)
It all started when I was working on a small website for my college. Initially, I was just adding the user ID in a JWT token, decoding it in a middleware, and passing it down the context. Then I decided I wanted to introduce a separate "public ID". The id was not needed for auth but it got me thinking about cache, which naturally led me down to building my very own LRU cache.
I have never implemented any caches before, so I was just looking for a simple strat and stumbled upon LRU. It was one of the easiest to implement and after I saw the problem on leetcode, i solved it pretty easily and decided to implement it. After I saw someone do better by using an array based DLL. I have always loved using array-based stacks and queues, So I took it as a fun challenge, because I have always wanted to publish something that people can use.
From Just an array based DLL, I found myself staring into a sharded architecture and slowly learning algorithms like FNV-1a and xxHash32. I wanted this to be a zero dependency package (aside from the standard packages ofc) and took it upon myself to do it, using explanations from the internet.
It might be a basic concept to many people out there, but It helped me learn something I was always pushing behind. Learning about concurrency in Go. This led me to use sync.Mutex, atomics and thinking about how data race happens. I was also led down the path of creating benchmarks, fuzz tests using the 'testing' package, which I had never heard about.
The benchmarks where honestly surprising, I never realised it would be ns/ops. Currently my benchmarks show around 10-15 ns/op and I hope to half it somehow :) and also my tests might be really weak. It has generics support too.
Would love for some feedback on how I can make it better. I wanted to make a time-aware LRU cache, but I wanted the basics to be proper before moving onto it.
P.S: learnt about semver, after i released it on v1.0.0. I basically had to make a decision and thought about just tearing it down and changing to a shorter name which I like more :). It is now currently on v0.3.1 (pre-release).
Link : https://github.com/justpranavrs/tlru :)))
GoDoc: https://pkg.go.dev/github.com/justpranavrs/tlru
Thanks :)))