tinygodriver

module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 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
sqlite github.com/shibukawa/tinygodriver/database/sql/sqlite SQLite database/sql driver, backend chosen at build time
pgxstdlib github.com/shibukawa/tinygodriver/database/sql/pgxstdlib PostgreSQL database/sql driver built on pgx, TLS included
mysql github.com/shibukawa/tinygodriver/database/sql/mysql MySQL and MariaDB database/sql driver built on go-sql-driver, TLS included
storage/s3 github.com/shibukawa/tinygodriver/storage/s3 S3 client (SigV4), where aws-sdk-go-v2 does not build

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
S3 object storage examples/s3demo Put, get, range-read, list, and delete against any S3-compatible endpoint

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

  • storage/s3: supported operations, configuration, and limitations

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

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

  • netdev TLS (IPPROTO_TLS): Secure Transport on macOS and Schannel on Windows, neither of which needs a package manager. TinyGo on Linux returns ErrProtocolNotSupported; host-Go Linux uses OpenSSL 3 (libssl-dev on Debian/Ubuntu). The https package needs none of this.

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
go get github.com/shibukawa/tinygodriver/storage/s3@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/mysql
Package mysql provides a MySQL and MariaDB database/sql driver that works under both TinyGo and standard Go.
Package mysql provides a MySQL and MariaDB database/sql driver that works under both TinyGo and standard Go.
sql/mysql/tinygomysql
Package mysql provides a MySQL driver for Go's database/sql package.
Package mysql provides a MySQL driver for Go's database/sql package.
sql/pgxstdlib
Package pgxstdlib provides a PostgreSQL database/sql driver that works under both TinyGo and standard Go.
Package pgxstdlib provides a PostgreSQL database/sql driver that works under both TinyGo and standard Go.
sql/pgxstdlib/internal/pgx
Package pgx is a PostgreSQL database driver.
Package pgx is a PostgreSQL database driver.
sql/pgxstdlib/internal/pgx/internal/iobufpool
Package iobufpool implements a global segregated-fit pool of buffers for IO.
Package iobufpool implements a global segregated-fit pool of buffers for IO.
sql/pgxstdlib/internal/pgx/internal/pgio
Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol.
Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol.
sql/pgxstdlib/internal/pgx/internal/stmtcache
Package stmtcache is a cache for statement descriptions.
Package stmtcache is a cache for statement descriptions.
sql/pgxstdlib/internal/pgx/pgconn
Package pgconn is a low-level PostgreSQL database driver.
Package pgconn is a low-level PostgreSQL database driver.
sql/pgxstdlib/internal/pgx/pgconn/internal/bgreader
Package bgreader provides a io.Reader that can optionally buffer reads in the background.
Package bgreader provides a io.Reader that can optionally buffer reads in the background.
sql/pgxstdlib/internal/pgx/pgproto3
Package pgproto3 is an encoder and decoder of the PostgreSQL wire protocol version 3.
Package pgproto3 is an encoder and decoder of the PostgreSQL wire protocol version 3.
sql/pgxstdlib/internal/pgx/pgtype
Package pgtype converts between Go and PostgreSQL values.
Package pgtype converts between Go and PostgreSQL values.
sql/pgxstdlib/internal/pgx/pgxpool
Package pgxpool is a concurrency-safe connection pool for pgx.
Package pgxpool is a concurrency-safe connection pool for pgx.
sql/pgxstdlib/internal/pgx/stdlib
Package stdlib is the compatibility layer from pgx to database/sql.
Package stdlib is the compatibility layer from pgx to database/sql.
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.
pgxdemo command
s3demo command
Command s3demo exercises the storage/s3 client against any S3-compatible endpoint: it uploads an object, reads it back whole and by range, lists the bucket, and deletes what it created.
Command s3demo exercises the storage/s3 client against any S3-compatible endpoint: it uploads an object, reads it back whole and by range, lists the bucket, and deletes what it created.
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.
internal
schannel
Package schannel wraps the Windows Schannel provider.
Package schannel wraps the Windows Schannel provider.
securetransport
Package securetransport wraps macOS Secure Transport.
Package securetransport wraps macOS Secure Transport.
Package netdev implements a host OS Netdever for TinyGo.
Package netdev implements a host OS Netdever for TinyGo.
storage
s3
Package s3 is an S3 client that builds with TinyGo.
Package s3 is an S3 client that builds with TinyGo.

Jump to

Keyboard shortcuts

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