Operating System Ubuntu

Tango for Go Is Archived: Build the Same Service with net/http on Ubuntu 26.04

Tango, the Go micro web framework, is archived. Here is its status and how to build the same routed service with Go's net/http on Ubuntu 26.04.

Tango was a small, pluggable web framework for Go with flexible routing, middleware ("handlers") and dependency injection. It is no longer developed, so it should not be used for new projects. This page explains its status and shows how to get the same result, a routed HTTP service with middleware, using only Go's standard library on Ubuntu 26.04 LTS or 24.04 LTS. Ubuntu 14.04 is long out of support.

Project status

  • The GitHub repository lunny/tango was archived by its owner on 3 February 2021 and is read-only. Its description says it is only a mirror and that the project moved to gitea.com/lunny/tango.
  • On Gitea, the latest release is still v0.5.0 from April 2016. The most recent commit, from April 2023, only changes the build automation.
  • There has been no release in ten years, so do not expect fixes for bugs or security problems.

Existing applications that import Tango will keep compiling as long as the module can be fetched, but they are frozen on an unmaintained dependency. Plan to move them to the standard library or a maintained router.

What to use instead

Much of what Tango added is now part of Go itself. Since Go 1.22 the standard net/http router matches HTTP methods and path wildcards, so a pattern such as GET /users/{name} needs no third-party package. Middleware is an ordinary function that wraps an http.Handler. If you want a larger framework with parameter binding and validation, actively maintained projects such as Gin, Echo and chi fill that role; check each project's own documentation for installation.

Install Go on Ubuntu

Ubuntu packages Go in its main repository. Ubuntu 26.04 provides Go 1.26 and Ubuntu 24.04 provides Go 1.22, and both are new enough for the routing used below.

sudo apt update
sudo apt install golang-go
go version

If you need a newer Go than your release offers, install the official archive from go.dev/dl instead.

Write a small routed service

Create a project directory and initialise a module. Unlike in the GOPATH days, the directory can be anywhere.

mkdir ~/hello && cd ~/hello
go mod init example.com/hello

Create main.go:

package main

import (
	"fmt"
	"log"
	"net/http"
	"time"
)

// logging is a middleware: it wraps another handler and logs each request.
func logging(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		next.ServeHTTP(w, r)
		log.Printf("%s %s %s", r.Method, r.URL.Path, time.Since(start))
	})
}

func main() {
	mux := http.NewServeMux()

	mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "Hello from Go")
	})

	mux.HandleFunc("GET /users/{name}", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %s\n", r.PathValue("name"))
	})

	log.Fatal(http.ListenAndServe(":8000", logging(mux)))
}

What the patterns mean:

  • A leading method such as GET restricts the route to that method (GET also matches HEAD). Other methods on the same path get a 405 Method Not Allowed response.
  • {name} matches one path segment, and r.PathValue("name") returns it. {path...} at the end of a pattern matches the rest of the path.
  • /{$} matches only the root path, so unknown URLs return 404 instead of falling through to the home page.

Run and test it

go run .

From a second terminal on the server:

curl http://localhost:8000/
curl http://localhost:8000/users/deploy
curl -i -X POST http://localhost:8000/users/deploy

The first two return the greetings, and the third returns 405 Method Not Allowed. To reach the service from outside, open the port in your firewall, for example sudo ufw allow 8000/tcp, and browse to http://203.0.113.10:8000/.

Build a binary and run it as a service

Compile the program into a single executable and install it:

go build -o hello .
sudo install -m 755 hello /usr/local/bin/hello

Create /etc/systemd/system/hello.service so that it starts at boot under an unprivileged, temporary user:

[Unit]
Description=Hello Go web service
After=network.target

[Service]
ExecStart=/usr/local/bin/hello
DynamicUser=yes
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now hello
systemctl status hello

Request logs from the middleware appear in journalctl -u hello. For a public site, put a reverse proxy such as Nginx or Caddy in front to handle TLS and forward requests to port 8000. The routing rules are described in the net/http ServeMux documentation.

Frequently asked questions

Can I still install Tango with go get?

The source is still published at gitea.com/lunny/tango and on the archived GitHub mirror, so Go can download it. It is the same code as in 2016, with no maintenance, which is a poor base for anything exposed to the internet.

How do I port Tango handlers to net/http?

A Tango route that returned a string becomes a handler function that writes to the http.ResponseWriter. Route parameters come from r.PathValue, and Tango middleware becomes a function that takes and returns an http.Handler, as in the logging example. Group routes by registering them on a separate ServeMux and mounting it under a prefix.

Do I need a framework at all?

For small services and APIs the standard library is usually enough since Go 1.22, and it has no third-party dependencies to keep updated. A framework starts to pay off when you want built-in request binding, validation or a large collection of ready-made middleware.

Share story:

Continue reading other guides on How VPS.