A little over two years ago, I started looking for a web framework like Django for Golang but to my surprise, I couldn’t find anything that even does the basic. My requirements were simple:
- A standard way of creating models and database schema migration
- Some basic UI features like foreign key, static lists, inlines and some front-end validation
- Auto generated UI that looks good enough for prototyping a concept and could be used for production.
I remembered at that point how Django was originally created where they were looking for something like Ruby on Rails for Python and they could not find so they created Django. So for the next 13 days I started writing a prototype under the code “eadmin” with the help of other developers doing UI, Golang reflection, database, … etc. We ended up with something that works. It didn’t have any of the cool features that Django has but it works and it was blazing fast. The most important feature that we got out of that is we had a way to quickly prototype an idea and ship it on a SCB (Single Board Computer) with an ARM CPU and 128–256 MB RAM.
Fast forward two years and our basic library is a developer’s wish list. Everyone on my team contributed code and found “a missing feature” from export to Excel to a built-in image cropping! This is too cool to stay as an in-house tool and we should open source it. I asked management if they are open to the idea and weirdly they didn’t mind it. Now I have to open source it but first I have to clean our code from all product specific code and replace it with generic features that could be used instead. We also decided to rename our library to uAdmin because the name was available on Github and none of us was clever enough to come up with something as cool as Django.
what is so special about uAdmin?
- Blazing fast
- Can run on minimum hardware requirements
- Pretty good security features (bcrypt hashing, 2FA)
- Clean and sharp UI
- Defaults for everything! but don’t worry, you can override them
So let’s jump into some code
To install uAdmin:
go get github.com/uadmin/uadmin/...
now you can start your first project:
$ mkdir -p ~/go/src/github.com/your_name/todo $ cd ~/go/src/github.com/your_name/todo $ uadmin prepare
Running uadmin prepare
will create a few new folders for you, templates, static, … etc. You don’t really have to worry about these for now. Let start writing code. Use any editor you like to create main.go
and put this code in it.
package main
import ( "github.com/uadmin/uadmin" "time" )
type Todo struct { uadmin.Model Name string Description string `uadmin:"html"` TargetDate time.Time Progress int `uadmin:"progress_bar"` }
func main() { uadmin.Register(Todo{}) uadmin.StartServer() }
To run this:
go build; ./todo
It will create a database and migrate your model and create a few more “system” models for authentication, permissions … etc. You should be able to check your project now at http://0.0.0.0:8080/
You can login with username admin
and password admin
and you will get the dashboard:
You can see that your model TODO
is already on your dashboard. Open that and add a task to your todo list:
That’s it. Congrats, you have built your first app with uAdmin. Now you have to know that everything in here is customizable a we will cover some more features in part 2 of this tutorial.