DEV Community

Hena Suvarnan
Hena Suvarnan

Posted on

Getting Started with GoFr: A Developer's Review & Tutorial

If you have ever developed microservices in Go, you understand the headache—configuring structured logging, dealing with configs, databus wiring, graceful shutdowns, and so on. That's where GoFr steps in: a minimal yet robust Go framework that helps make developing scalable microservices simpler, quicker, and neater.

In this article, I'll describe my experience trying out GoFr, lead you through a brief tutorial, and provide my honest opinion of where it excels.


???? Why GoFr?

GoFr is more than "yet another Go framework." It includes sane defaults, opinionated layout, and developer-centric tooling that assists you in:

  • ✅ Rapidly bootstrapping services with pre-spieced modules.

  • ✅ Have databases (MySQL, PostgreSQL, MongoDB, Redis, etc.) supported out of the box.

  • ✅ Use standardized logging, config management, metrics, and health checks.

  • ✅ Write cleaner, testable Go code thanks to its focus on dependency injection and interfaces.

  • ✅ Follow best practices without reinventing the wheel.
    Basically, GoFr is like having a well-organized toolbox that prevents the “spaghetti code” problem when your service grows.


⚡ Setting Up GoFr

First, install GoFr:


go get github.com/gofr-dev/gofr
Enter fullscreen mode Exit fullscreen mode

Now, create a simple main.go:


package main
import (

    "context"
    "github.com/gofr-dev/gofr/pkg/gofr"
)
func main() {

    app := gofr.New()
// Define a simple route

    app.GET("/hello", func(ctx *gofr.Context) (interface{}, error) {
        return "Hello, GoFr!", nil
    })
    app.Start()

}
Enter fullscreen mode Exit fullscreen mode

Run the app:


go run main.go
Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:8000/hello → ???? You’ll see "Hello, GoFr!".

That’s it—you just built your first microservice with structured logging, graceful shutdown, and config loading already wired in by GoFr.


???? Testing with GoFr

One of the best things about GoFr is its testing philosophy. It encourages you to maintain 100% test coverage for new code. Tests come naturally because of its minimal interfaces:


func TestHelloRoute(t *testing.T) {
    app := gofr.New()
    req, _ := http.NewRequest("GET", "/hello", nil)

    res := httptest.NewRecorder()
    app.ServeHTTP(res, req)

    assert.Equal(t, 200, res.Code)}

assert.Equal(t, `\"Hello, GoFr!\"`, res.Body.String())
Enter fullscreen mode Exit fullscreen mode

Boom ✅ Simple, clean, testable.


???? Working with Databases

GoFr has support for multiple databases built in. For instance, with MySQL:

db := app.DB("mysql")
rows, err := db.Query("SELECT * FROM users")
Enter fullscreen mode Exit fullscreen mode

Configs are injected via environment variables, so you don't hardcode credentials. Your app is production-ready on day one.


???? My Honest Thoughts

After experimenting with GoFr for a couple of days, here's my quick summary:

  • Pros:

  • ???? Lightning-fast setup.

    • ???? Integrated tools (logs, configs, metrics) save so much time.
    • ???? Multiple DBs & services supported (Kafka, Redis, etc.).
    • ✅ Testing-first approach feels invigorating.
  • Cons:

    • Still in development—community smaller than the giants like Gin or Echo.
    • Some functionality needs Docker setups (good for consistency, but bulkier for newbies). But overall? If you're developing production-grade microservices in Go, GoFr is definitely worth a look.

Final Thoughts

GoFr strikes a nice balance—it's opinionated enough to provide you with structure, but loose enough to allow you to do things your own way. If you're sick of wiring up the same boilerplate in each new service, GoFr will change your life.

Try it out here: https://gofr.dev

Happy coding! ✨

Top comments (0)