Go is such a new language that even more established frameworks can have interesting quirks. One of the key issues learning the Go framework is the availability of useful documentation. Unfortunately, Go framework maintainers don’t always prioritize writing the documentation necessary to get new programmers up to speed on their frameworks. The five frameworks below, however, have usable documentation and are straightforward to use.
1. Martini
Getting started with Martini is painless (which may explain why it's one of the most popular Go frameworks). The framework was designed to be simple and work with other Go packages—or, as the maintainers describe it, a "classy" web framework. If you’re just getting started with Go, Martini may be the best framework to use for your projects. Out of the box, Martini has the features you’ll need on most early projects. It’s also modular, which means adding functionality is easy. Keep in mind that Martini isn't idiomatic Go, though; it's not wrong, but you may face some trouble switching back and forth.
# Martini looks a little like Sinatra
m.Get("/", func() string {
return "hello world" // HTTP 200 : "hello world"
})
2. Gorilla
Technically speaking, Gorilla is a web toolkit, rather than a web framework. However, packages within Gorilla will make your projects easier to launch. Gorilla Mux, for example, is an especially powerful URL router and dispatcher. Gorilla also has packages for saving sessions, authenticating and encrypting cookies and websockets. In addition to the documentation on the Gorilla site, there's a strong community able to provide some support. You can also easily use Gorilla in conjunction with other frameworks.
# Mux isn't a web framework, but it has tools for routing, sessions
# and other things you need to make a web app.
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
r.HandleFunc("/products", ProductsHandler)
r.HandleFunc("/articles", ArticlesHandler)
http.Handle("/", r)
3. Echo
If you’ve used Echo in the past, you may not be a big fan—the maintainers rebased the whole code base recently. Annoying as that may be, the framework has a lot to offer, especially if you’re coming to Echo fresh. Echo’s performance is impressive and handles garbage collection efficiently. If speed is a concern on your project, Echo is your best option. You may find a few points in the Echo documentation listed as a "work in progress," but Echo’s maintainers have posted numerous recipes to get programmers going.
# Echo also looks kind of like Sinatra. I'm sensing a pattern.
blog := echo.New()
blog.Use(mw.Logger())
blog.Use(mw.Recover())
hosts["blog.localhost:1323"] = blog
blog.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Blog")
})
4. web.go
web.go claims to be "the simplest way to write web applications in Go." Whether or not that’s accurate, web.go is one of the easiest web frameworks for writing backend web services. If you’ve worked with a higher-level web framework like web.py or Sinatra, you can get up to speed with web.go almost immediately. While web.go’s quickstart guide may be enough for more experienced programmers, the framework’s tutorial and API docs are thorough.
func hello(val string) string {
return "hello " + val
}
func main() {
web.Get("/(.*)", hello)
web.Run("0.0.0.0:9999")
}
5. Beego
Looking for a framework that guarantees high performance? Beego is worth trying out. The framework is designed for full-stack web development and it's modular. There’s also the bee tool within Beego as a bonus. The Bee tool auto-compiles, reloads, tests and deploys Beego applications efficiently. Beego has a huge amount of documentation and demos, though some are difficult to understand the first time through—set aside a little extra time for the documentation. You can also see a number of web applications using Beego in production.
If you’re looking for a more specialized web framework, check out Awesome Go’s in-depth list of actively maintained frameworks and other tools. Open source contributors are launching new Go projects every day, so make sure you stay up to date—you may even find a Go library you can contribute to yourself.