tinygodriver

module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0

README

tinygodriver

Networking additions that make TinyGo's standard-library HTTP stack more useful on desktop hosts.

The repository provides a host network driver plus TinyGo-compatible versions of newer HTTP APIs that are not yet fully available in TinyGo. The packages also build with standard Go, which makes it possible to share application code and tests between both compilers.

Packages

Package Import Description
netdev github.com/shibukawa/tinygodriver/netdev Host TCP/IP Netdever (BSD sockets + optional OpenSSL TLS)
httpmux github.com/shibukawa/tinygodriver/httpmux Go 1.22-style ServeMux patterns for TinyGo
httprevproxy github.com/shibukawa/tinygodriver/httprevproxy TinyGo-compatible subset of net/http/httputil.ReverseProxy

Quick start

Blank-import netdev before using net or net/http on a desktop TinyGo build. Use httpmux when the application needs method-aware patterns or path wildcards:

package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/shibukawa/tinygodriver/httpmux"
	_ "github.com/shibukawa/tinygodriver/netdev"
)

func main() {
	mux := httpmux.NewServeMux()
	mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "user=%s\n", r.PathValue("id"))
	})
	addr := os.Getenv("ADDR")
	if addr == "" {
		addr = ":8080"
	}
	fmt.Println("listening on", addr)
	http.ListenAndServe(addr, mux)
}
Run the example

The included server exercises netdev, httpmux, and httprevproxy together. Its /proxy/{path...} route forwards requests to UPSTREAM_URL (default http://127.0.0.1:8081).

tinygo build -o server ./examples/httpserver
./server
# curl http://127.0.0.1:8080/healthz
# curl http://127.0.0.1:8080/proxy/users/42

Standard go run also works. In a standard Go build, netdev registration is a no-op and httpmux.ServeMux is an alias of net/http.ServeMux.

go run ./examples/httpserver
Explicit netdev registration
import "github.com/shibukawa/tinygodriver/netdev"

func main() {
	netdev.Use(netdev.New())
	// ...
}

Examples

Example Path Description
HTTP server and reverse proxy examples/httpserver Method-aware routes, host netdev, and a configurable reverse proxy

Platform notes

See the package READMEs for detailed API behavior and limitations:

  • netdev: TLS (OpenSSL), DNS, and platform notes

  • httpmux: supported patterns and implementation selection

  • httprevproxy: proxy features and unsupported protocols

  • IPv4 only (matches TinyGo’s net port).

  • TLS (IPPROTO_TLS): OpenSSL 3 on macOS (and standard Go on Linux). TinyGo on Linux and Windows currently return ErrProtocolNotSupported for TLS.

  • OpenSSL 3 is required for TLS builds (openssl@3 via Homebrew on macOS, libssl-dev on Debian/Ubuntu).

Install

Install only the packages an application uses, for example:

go get github.com/shibukawa/tinygodriver/netdev@latest
go get github.com/shibukawa/tinygodriver/httpmux@latest
go get github.com/shibukawa/tinygodriver/httprevproxy@latest

Requires TinyGo for TinyGo builds. Compatible with the Netdever interface in tinygo-org/drivers/netdev.

License

Apache License 2.0

Directories

Path Synopsis
compress
zstd
Package zstd writes RFC 8878 Zstandard frames and calculates cache metadata over the encoded representation while it is emitted.
Package zstd writes RFC 8878 Zstandard frames and calculates cache metadata over the encoded representation while it is emitted.
database
cgosqlite
Package cgosqlite provides a small database/sql driver backed by the statically linked, official SQLite amalgamation.
Package cgosqlite provides a small database/sql driver backed by the statically linked, official SQLite amalgamation.
sqlite
Package sqlite selects a database/sql SQLite backend appropriate for the active Go toolchain.
Package sqlite selects a database/sql SQLite backend appropriate for the active Go toolchain.
examples
httpserver command
Command httpserver is a minimal HTTP server that works with both TinyGo and standard Go.
Command httpserver is a minimal HTTP server that works with both TinyGo and standard Go.
Package httpmux provides an HTTP request multiplexer with the Go 1.22+ net/http ServeMux pattern syntax.
Package httpmux provides an HTTP request multiplexer with the Go 1.22+ net/http ServeMux pattern syntax.
Package httprevproxy provides a TinyGo-compatible subset of net/http/httputil's reverse proxy API.
Package httprevproxy provides a TinyGo-compatible subset of net/http/httputil's reverse proxy API.
Package netdev implements a host OS Netdever for TinyGo.
Package netdev implements a host OS Netdever for TinyGo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL