How I published my first package...

Deepak Choudhary
4 min readMar 31, 2021

“The first time you do a thing is always exciting.” -Agatha Christie

As lines of code overshadow the fleeting sense of time and space for us developers, there comes a time when we contribute back to the world in the form of a package. This article is going to tell you a tale for just that.

There’s always a first time for everything. A first time for your bike ride, a first time for heartbreak and definitely a first time for a package you write which will someday be used by other developers.

Setting the scene for a breakthrough…

The requirement was for an solution which would handle authentication and authorization for other applications on the machine. The solution needs to be locally deployed on the system and should be able to store authentication and authorization related data in a relational database. Since the systems were going to be fairly limited on memory the choice of server side language was Go. Go being the light weight, memory friendly, concurrency spitting language it is was a straightforward choice.

When it came to databases however, the fairly limited system memory was a road block for using a DB like PostgreSQL or MySQL.

Enter SQLite…

SQLite is a extremely low footprint relational databases around currently. Written in C, this small packet big bang DB is present almost everywhere. If you haven’t heard about it, check your phone and most probably it’ll be there. SQLite is an extremely lightweight (~600Kb), entirely self contained, portable database which requires no prior configuration/installation.

Another problem raises it’s ugly head…

We were not sure if the individual deployments will forever be the scenario and in the future we might have to switch to a centralized deployment or support multiple databases. This usually means you go with an ORM. However, Go being the way it is. It’s difficult to have an ORM in it’s true sense for it. Time to make the best out of what we had, we decided to use GORM.

GORM: The fantastic ORM library for Golang is one of the most famous ones out there.

SQLite !! Are you sure ? You know we need that encryption

SQLite by default does not have encryption and all your data will be stored in plain text in the database file. In addition to that, the default SQLite driver that GORM provides does not work with encrypted SQLite databases.

How do you solve it you ask ?

You get on the internet and find someone who has implemented the encryption logic. Post hours of looking for a solution and countless repositories, the solution was simple.

The gorm SQLite driver uses another package at it’s core to interact with the SQLite database. If I could just improve upon it and use another package which can interact with an encrypted SQLite DB it should work.

EUREKA !!!

Thank you to the guys at Mute Communications Ltd. I found a Go driver which could interact with an encrypted SQLite database file. All I had to do was replace the driver and make sure it worked and alas! My package was ready to publish.

You can find the package here.

“With great power comes great responsibility”- Uncle Ben(Spiderman)

Future Work, Improvements…

As of the time of this writing, I have not been able to test all the operations and features of GORM. The code could also do with some additional features like choice of encryption. Currently the package used provides AES-256 as the only encryption available. It would help to have other encryption logics available for user selection as well.

However, that is part and parcel of any open source code. There’s always something that can be improved.

If you like what I put on paper and would like to read more of my articles, show some love in the form of claps and responses.

Keep learning, keep growing.

--

--

Deepak Choudhary

Technology evangelist engineering solutions on weekdays and exploring life on the weekends. The joy of life lies in the gray zone.