I'm a Laravel dev, I stumbled on Goravel and discovered Go

· · 2 min read

Lire cet article en français

I work with Laravel, and one day I stumbled, a bit by chance, on Goravel. It's a Go framework that mirrors Laravel's structure almost exactly. You find the folders, the facades, and method names you recognize right away.

I had never written any Go. But seeing everything I'm used to in Laravel carried over to another language made me curious. I wanted to take a look.

You feel at home straight away

The first route reads fine without knowing Go:

facades.Route().Get("/ping", func(ctx http.Context) http.Response {
	return ctx.Response().Success().Json(http.Json{
		"status": "in the saddle",
	})
})

A facade for the router, a closure that returns JSON. http.Json is just a map, the equivalent of the array you would pass to response()->json().

The rest follows. Controllers, route parameters with ctx.Request().Route("firstName"), validation with required|in:…, route groups with Prefix("/api"), middleware, and the query builder:

err := facades.DB().Table("deliveries").Where("district", district).OrderBy("id").Get(&result)

A Laravel developer can read that without translating.

Underneath, it really is Go

What changes is the language. And that is exactly what I was after: Goravel let me discover Go while leaning on what I already knew.

There is no public or private: whether a name starts with a capital letter decides if it is visible outside its package. There are no exceptions either. A function that can fail returns its value and an error, and you check it right after the call.

validator, err := ctx.Request().Validate(rules)
if err != nil {
	return ctx.Response().Json(http.StatusInternalServerError, http.Json{"error": err.Error()})
}

That if err != nil shows up everywhere.

I'm still skeptical

Goravel is a good way in for a Laravel developer, I can believe that. But I'm not sure that means I'll leave the PHP world. I have a hard time with the way you write things in Go.

What about you, what do you think of Go? Do you use it in production, or did you try it and put it aside?

Make up your own mind

If you want to try it without installing anything, I created a free course: Discover Goravel. Thirteen exercises where you build the API of a bike courier cooperative in Lyon. Goravel actually runs in the browser, compiled to WebAssembly, and Go tests check each exercise.

No Go knowledge is required: each exercise introduces the small bit of the language it needs. All you need is a free account.

← All articles