Building a Go web "framework"

November 14, 2022

Maximilian Patterson


What is GoWeb?

This article has been updated a few times and a lot of progress has been made. I plan on writing a new article soon once I get some more essential features done. I keep the checklist updated, so you can see what I’ve done so far, alternatively check the Git repo! - Feb 14, 2023

Currently, my largest and most interesting project (GoWeb) is a web “framework” made purely in Go and its standard library. I mean framework in a loose sense, in reality, it’s a boilerplate project including some packages for helping with things like CSRF protection and user authentication. I also plan to create a helper utility set of utilities built into a user’s website to generate a new project with and without desired functionality help with migrations and things (see checklist). Here is the current file structure of the base project you’ll see when creating a new project in GoWeb:

Check out the repo here!

Feb 14, 2023 UPDATED file tree:

│   main.go
├───app
│       app.go
├───config
│       config.go
├───controllers
│       getController.go
│       postController.go
├───database
│       databaseConnection.go
│       migrate.go
├───logs
│       example.log
├───models
│       migrations.go
│       user.go
├───routes
│       getRoutes.go
│       postRoutes.go
├───security
│       csrf.go
├───static
│       test.log
├───templates
│   │   base.html
│   │
│   └───pages
│           home.html
│           login.html
│           register.html
└───templating
        templateHelper.go

Why?

I have roughly a year of Laravel work under my belt, I love how clean the projects are structured, things like having all your routes in one place, are extremely useful. To my knowledge, some things like this already exist in the Go ecosystem like Echo and Gin but do not provide a boilerplate project, and rely heavily on non-standard packages, which are outside the scope of Go’s compatibility promise and not-necessarily going to receive the epic performance boosts that we see with different packages in the standard library. So my goal with all of this is to keep it vanilla while still providing a clean and easy-to-use project structure akin to Laravel. When using GoWeb, you’ll be able to create a new project with a single command, and then you’ll be able to start writing your code in the controllers and models folders, and the rest of the project will be handled by GoWeb, just like Laravel. And if you want to dip your toes into some other packages that GoWeb provides, you can do that too, and you’ll be able to see how they work and modify them in your projects.

Current state of the project and future plans

Here’s what I’ve accomplished so far:

Here’s what I plan to accomplish by the end of the year eventually:

Longer-term goals:

Final thoughts

Currently, the repo is not public. There are some things I’d like to finish and clean up first, but I expect to have it public by the end of this year. If you have any suggestions based on the information given here, specifically the file structure, or any questions, feel free to email me (linked on the side). I’m always looking to improve, and it’s very important to me that I get everything right. Thanks for reading!