Goyave: A new framework for web development using Golang

SystemGlitch
Dec 8, 2019 · 4 min read

Go is a programming language that is slowly growing in popularity. In one year (2018 to 2019), it grew by 1.1%, according to the StackOverflow Developer Survey. Its score of 8.2% puts it in the 13th place of the most popular technologies, versus 16th last year. A pretty good score considering the total amount of languages. Moreover, Go is the top-paying language of 2019 according to the Dice Tech Salary Report.

This is why, without surprises, we see new frameworks and libraries emerge, fleshing out the Go environment even more.


In this article, we are going to talk about the new-born Goyave. A web framework aimed at making development easy and enjoyable. It has a philosophy of cleanliness and conciseness to make programs more elegant, easier to maintain and more focused.

Most golang frameworks for web development don’t have a strong directory structure nor conventions to make applications have a uniform architecture and limit redundancy. This makes it difficult to work with them on different projects. In companies, having a well-defined and documented architecture helps new developers integrate projects faster, and reduces the time needed for maintaining them. For open source projects, it helps newcomers understanding the project and makes it easier to contribute.

Although Goyave has many things to offer, this is its most important aspect, and what makes it really different from other frameworks. When you think about well-established technologies such as PHP Laravel and Symfony, they offer a clearly defined architecture and have conventions. Most of their applications have, as a result, better code quality and consistency.

In the Go environment, web frameworks are more like tool kits. They offer many features and help development, but they let you the freedom of structuring the program however you want, which is not necessarily a bad thing. However, that means that there is no consistency, unless the developers are very rigorous. As we all know, in the corporate world, because of time constraints and unclear specifications, this is hard to take care of these aspects as much.

The design of Goyave always keeps that in mind and tries to let developers focus on the business logic of their applications, without compromising on their freedom of code.


Apart from this core aspect, what does Goyave bring to the table? Let’s make a quick rundown of its main features.

First, the most important feature: routing. Any web framework needs routing. Middleware are also a thing. The difference with other frameworks lies in the fact that Goyave has a very powerful built-in validator.

With very little code, you can validate complex requests. That works transparently for both JSON and URL-encoded requests.

var StoreProduct validation.RuleSet = validation.RuleSet{
"name": {"required", "string", "between:3,50"},
"price": {"required", "numeric", "min:0.01"},
"image": {"nullable", "file", "image", "max:2048", "count:1"},
}

The validator converts all the data in the correct types for you, based on the rules applied to them. For example, if a field must be numeric, and a string such as “1.42” is provided, it will be automatically converted to a float64.

Validating arrays is also a breeze, even if they are n-dimensional. In the following example, we are validating a three-dimensional array of numeric values. The second dimension must be made of arrays with a size of 3 or less. The third dimension must contain numbers inferior or equal to 4.

var arrayValidation = RuleSet{
"array": {"required", "array", ">array", ">>array:numeric", ">max:3", ">>>max:4"},
}

Validation works flawlessly with the localization feature. That means that all validation error messages can be customized very easily, by editing a config file. You can add support for any language without any additional code. Of course, localization can be (and should be) used for every message sent to the user.

There are also many helpers and built-in functions but we are not going to cover them in this article. The framework is in active development, and great things are planned, such as integrated testing functions, an authentication system, and more!


If you’re convinced and you want to try it, nothing easier. Ensure you have Go 1.13 or higher installed, and Go Modules enabled, then install the template project using the following command:

On Linux or MacOS:

$ curl https://raw.githubusercontent.com/System-Glitch/goyave/master/install.sh | bash -s my-project

On Windows (with Powershell):

> & ([scriptblock]::Create((curl "https://raw.githubusercontent.com/System-Glitch/goyave/master/install.ps1").Content)) -projectName my-project

This project has a complete directory structure already set up for you, so you can start coding right away! In fact, if you run the project, there is already a route that you can try.

$ curl http://localhost:8080/hello
Hi!

I highly advise you to read the extensive documentation, which explains everything you need to know to make a Goyave application.

If you really like the project, contributions are welcome.

The Startup

SystemGlitch

Written by

Craftsman, student at ESGI | Full-stack, Blockchain-related tech

The Startup

Medium's largest active publication, followed by +568K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade