tinygodriver

module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 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)
https github.com/shibukawa/tinygodriver/https net/http-compatible HTTPS client using the OS TLS stack
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
HTTPS client examples/httpsclient https.Get over the OS TLS stack, with an optional custom CA
HTTPS platform demo examples/httpsdemo One source, every platform: verifies trust, refusal behavior, and deadlines

Platform notes

See the package READMEs for detailed API behavior and limitations:

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

  • https: HTTPS client backends, configuration, and limitations

  • httpmux: supported patterns and implementation selection

  • httprevproxy: proxy features and unsupported protocols

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

  • HTTPS client (https): Network.framework on macOS and vendored mbedTLS on Linux, both with no external TLS library to install. Other TinyGo targets return ErrPlatformNotSupported; standard Go builds delegate to net/http.

  • netdev TLS (IPPROTO_TLS): OpenSSL 3 on macOS (and standard Go on Linux). TinyGo on Linux and Windows currently return ErrProtocolNotSupported for TLS. This path still requires OpenSSL 3 (openssl@3 via Homebrew on macOS, libssl-dev on Debian/Ubuntu); the https package does not.

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
sql/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.
sql/sqlite/tinygosqlite
Package tinygosqlite provides a small database/sql driver backed by the statically linked, official SQLite amalgamation.
Package tinygosqlite provides a small database/sql driver backed by the statically linked, official SQLite amalgamation.
examples
httpsclient command
Command httpsclient fetches an HTTPS URL using the https package, which performs TLS through the host OS stack.
Command httpsclient fetches an HTTPS URL using the https package, which performs TLS through the host OS stack.
httpsdemo command
Command httpsdemo exercises the https package and reports what the current platform does.
Command httpsdemo exercises the https package and reports what the current platform does.
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 https provides a net/http-compatible HTTPS client for TinyGo.
Package https provides a net/http-compatible HTTPS client for TinyGo.
internal/mbedtls
Package mbedtls wraps a vendored mbedTLS for the TinyGo Linux HTTPS backend.
Package mbedtls wraps a vendored mbedTLS for the TinyGo Linux HTTPS backend.
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