This is a library that simplifies the implementation and integration of a control server for Tailscale into your Go application.
This project is not affiliated with Tailscale or Tailscale Inc., and it is not an official Tailscale or Tailscale Inc. project.
You can install the library using the go get
command:
go get github.com/loft-sh/tunnel
There are two main ways to use this library: as a standalone library in your Go code, or as an in-memory coordinator for end-to-end testing.
To use the library in your Go code, you'll need to import it and implement the Tailscale coordinator interface.
package main
import (
"net/http"
"github.com/loft-sh/tunnel"
"github.com/loft-sh/tunnel/handlers"
)
func main() {
coordinator := NewCoordinator()
router := http.NewServeMux()
router.Handle("/", handlers.CoordinatorHandler(coordinator))
if err := http.ListenAndServe(":3000", router); err != nil {
panic(err)
}
}
func NewCoordinator() tunnel.Coordinator {
// Your coordinator implementation gets instantiated here
// ...
}
We also provide an in-memory control server, which is useful for running end-to-end tests in a continuous integration or test environment. This server comes with pre-configured profiles and nodes.
You can find an example of this server in the examples/coordinator/ directory.
To configure the server, edit the config file. Then, run the server with the following commands:
cd examples/coordinator
go run server.go
This project was inspired by open-source Tailscale control server implementations such as Headscale and Ionscale.