tinygodriver

module
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 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 + OS-native 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
httpserver github.com/shibukawa/tinygodriver/httpserver Serves net/http handlers that hijack, which TinyGo's own server cannot
websocket github.com/shibukawa/tinygodriver/websocket Drop-in gorilla/websocket fork that builds under TinyGo
fasthttp github.com/shibukawa/tinygodriver/fasthttp Drop-in valyala/fasthttp fork that builds under TinyGo, plaintext only
fasthttprouter github.com/shibukawa/tinygodriver/fasthttprouter Drop-in fasthttp/router fork that routes for the fasthttp fork
fasthttpwebsocket github.com/shibukawa/tinygodriver/fasthttpwebsocket Drop-in fasthttp/websocket fork; WebSocket on fasthttp, with no demultiplexer needed
sqlite github.com/shibukawa/tinygodriver/database/sql/sqlite SQLite database/sql driver, backend chosen at build time
pgx github.com/shibukawa/tinygodriver/database/pgx pgx-native PostgreSQL API: Batch, CopyFrom, LISTEN/NOTIFY; TLS included
pgx/pgxpool github.com/shibukawa/tinygodriver/database/pgx/pgxpool Concurrency-safe pool of native pgx connections
pgx/stdlib github.com/shibukawa/tinygodriver/database/pgx/stdlib PostgreSQL database/sql driver built on pgx
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
nosql/dynamodb github.com/shibukawa/tinygodriver/nosql/dynamodb DynamoDB client, JSON protocol, retries and pooled connections
nosql/datastore github.com/shibukawa/tinygodriver/nosql/datastore Firestore in Datastore mode client, where neither Google Go client builds
cloud/aws github.com/shibukawa/tinygodriver/cloud/aws SigV4 signing and credentials, shared by the AWS clients
cloud/google github.com/shibukawa/tinygodriver/cloud/google Google credentials and bearer tokens, RSA signed by the OS on TinyGo
jwt github.com/shibukawa/tinygodriver/jwt Bounded signed JWT subset, HS256 and RS256

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
WebSocket server examples/websocketserver Echo and server-push endpoints beside ordinary HTTP routes, on one port
fasthttp server examples/fasthttpserver Routes, content negotiation, chunked streaming, a WebSocket echo, and graceful shutdown on fasthttp
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
DynamoDB examples/dynamodbdemo Table lifecycle, conditional writes, batches, and paged queries
Datastore examples/datastoredemo Typed round trip, ancestor query over two pages, and a transaction

Platform notes

See the package READMEs for detailed API behavior and limitations:

  • netdev: TLS, DNS, and platform notes

  • https: HTTPS client backends, configuration, and limitations

  • httpmux: supported patterns and implementation selection

  • httpserver: why Hijack deadlocks, what the demultiplexer does, and when the package stops being needed

  • websocket: the two patch sites, reaching wss://, and what is verified

  • httprevproxy: proxy features and unsupported protocols

  • fasthttp: build tags, why TLS and HTTP/2 cannot work, and how dropping zstd halves the binary

  • fasthttprouter: why the router needs a fork of its own, and what it costs

  • fasthttpwebsocket: why FastHTTPUpgrader works on TinyGo where net/http's Hijack deadlocks

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

  • nosql/dynamodb: attribute values, pagination, retries and what a retry can deliver twice

  • nosql/datastore: values, keys, queries, conditional writes and contention

  • cloud/aws: signing another AWS service with this signer

  • cloud/google: token sources, clock skew, and where the RSA code goes

  • 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, Schannel on Windows and crypto/tls on host-Go Linux, none of which needs a package manager. TinyGo on Linux returns ErrProtocolNotSupported. The https package needs none of this.

  • A TinyGo net/http server cannot hijack a connection. It starts a background read before every handler and cancels it by moving the read deadline into the past, which netdev cannot do to a recv() already in flight, so Hijack never returns and a protocol upgrade hangs silently. Serve through httpserver, which routes upgrades around net/http and keeps a real http.Server for everything else, on one port.

  • websocket serves plaintext only. Its client reaches wss:// through Dialer.NetDialTLSContext; a server cannot terminate TLS, for the same reason fasthttp cannot.

  • fasthttp serves plaintext only. TinyGo defines no tls.Server, so terminating TLS is impossible and the fork refuses rather than serving cleartext on the TLS port; HTTP/2 cannot work either, because ALPN is unobservable. Its client reaches HTTPS through a custom Dial.

  • On the fasthttp stack, WebSocket needs no demultiplexer. RequestCtx.Hijack is a synchronous handoff — response written, reading stopped, handler called on the same goroutine — so the deadlock above never arises and fasthttpwebsocket upgrades from an ordinary route. Two routes to the same place: websocket + httpserver for net/http applications, fasthttpwebsocket for fasthttp ones.

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
go get github.com/shibukawa/tinygodriver/nosql/dynamodb@latest

Requires Go 1.27 or later, which is the module's go directive, and TinyGo 0.42 or later for TinyGo builds. TinyGo 0.41 refuses a Go 1.27 toolchain outright — requires go version 1.19 through 1.26 — so the two floors move together. Compatible with the Netdever interface in tinygo-org/drivers/netdev.

License

Apache License 2.0

Directories

Path Synopsis
cloud
aws
Package aws holds what every AWS service client in this repository needs: SigV4 signing, credentials, environment resolution, and the HTTP client the build selects.
Package aws holds what every AWS service client in this repository needs: SigV4 signing, credentials, environment resolution, and the HTTP client the build selects.
google
Package google holds what every Google Cloud client in this repository needs: credentials, bearer tokens, and the HTTP client the build selects.
Package google holds what every Google Cloud client in this repository needs: credentials, bearer tokens, and the HTTP client the build selects.
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
internal/pgx
Package pgx is a PostgreSQL database driver.
Package pgx is a PostgreSQL database driver.
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.
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.
internal/pgx/internal/stmtcache
Package stmtcache is a cache for statement descriptions.
Package stmtcache is a cache for statement descriptions.
internal/pgx/pgconn
Package pgconn is a low-level PostgreSQL database driver.
Package pgconn is a low-level PostgreSQL database driver.
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.
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.
internal/pgx/pgtype
Package pgtype converts between Go and PostgreSQL values.
Package pgtype converts between Go and PostgreSQL values.
internal/pgx/pgxpool
Package pgxpool is a concurrency-safe connection pool for pgx.
Package pgxpool is a concurrency-safe connection pool for pgx.
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.
pgx
Package pgx provides the pgx-native PostgreSQL API under both TinyGo and standard Go.
Package pgx provides the pgx-native PostgreSQL API under both TinyGo and standard Go.
pgx/pgxpool
Package pgxpool provides the pgx-native connection pool under both TinyGo and standard Go.
Package pgxpool provides the pgx-native connection pool under both TinyGo and standard Go.
pgx/stdlib
Package stdlib adapts database/pgx to database/sql, mirroring upstream pgx's stdlib package, and works under both TinyGo and standard Go.
Package stdlib adapts database/pgx to database/sql, mirroring upstream pgx's stdlib package, and works under both TinyGo and standard Go.
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/sqlbatch
Package sqlbatch sends several SQL statements per network round trip through a database/sql handle.
Package sqlbatch sends several SQL statements per network round trip through a database/sql handle.
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.
encoding
cbor
Package cbor implements a bounded, reflection-free subset of RFC 8949.
Package cbor implements a bounded, reflection-free subset of RFC 8949.
examples
datastoredemo command
Command datastoredemo exercises nosql/datastore against the Datastore emulator, or against a real project when credentials are present.
Command datastoredemo exercises nosql/datastore against the Datastore emulator, or against a real project when credentials are present.
dynamodbdemo command
Command dynamodbdemo exercises the nosql/dynamodb client against DynamoDB or DynamoDB Local: it creates a table, writes items one by one and in a batch, reads them back, queries a partition, and cleans up after itself.
Command dynamodbdemo exercises the nosql/dynamodb client against DynamoDB or DynamoDB Local: it creates a table, writes items one by one and in a batch, reads them back, queries a partition, and cleans up after itself.
fasthttpserver command
Command fasthttpserver is a fasthttp server that works with both TinyGo and standard Go, routing through the fasthttprouter fork.
Command fasthttpserver is a fasthttp server that works with both TinyGo and standard Go, routing through the fasthttprouter fork.
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
pgxnativedemo command
pgxpooldemo 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.
websocketserver command
Command websocketserver shows a WebSocket endpoint living alongside ordinary HTTP routes on one port, under both compilers.
Command websocketserver shows a WebSocket endpoint living alongside ordinary HTTP routes on one port, under both compilers.
Package fasthttp provides fast HTTP server and client API.
Package fasthttp provides fast HTTP server and client API.
fasthttputil
Package fasthttputil provides utility functions for fasthttp.
Package fasthttputil provides utility functions for fasthttp.
stackless
Package stackless provides functionality that may save stack space for high number of concurrently running goroutines.
Package stackless provides functionality that may save stack space for high number of concurrently running goroutines.
Package router is a trie based high performance HTTP request router.
Package router is a trie based high performance HTTP request router.
Package websocket implements the WebSocket protocol defined in RFC 6455.
Package websocket implements the WebSocket protocol defined in RFC 6455.
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.
Package httpserver serves net/http handlers on TinyGo when one of them needs to take over the connection.
Package httpserver serves net/http handlers on TinyGo when one of them needs to take over the connection.
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.
rsasign
Package rsasign computes RSASSA-PKCS1-v1_5 signatures over a SHA-256 digest, through crypto/rsa on host Go and through the OS on TinyGo builds.
Package rsasign computes RSASSA-PKCS1-v1_5 signatures over a SHA-256 digest, through crypto/rsa on host Go and through the OS on TinyGo builds.
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.
syncx
Package syncx holds the one synchronization primitive this repository cannot take from the standard library on every compiler.
Package syncx holds the one synchronization primitive this repository cannot take from the standard library on every compiler.
jwt
Package jwt strictly parses, signs, and verifies a bounded signed JWT subset.
Package jwt strictly parses, signs, and verifies a bounded signed JWT subset.
internal/authn
Package authn contains the bounded parsing primitives the jwt package shares.
Package authn contains the bounded parsing primitives the jwt package shares.
Package netdev implements a host OS Netdever for TinyGo.
Package netdev implements a host OS Netdever for TinyGo.
nosql
dynamodb
Package dynamodb is a DynamoDB client that builds with TinyGo.
Package dynamodb is a DynamoDB client that builds with TinyGo.
storage
s3
Package s3 is an S3 client that builds with TinyGo.
Package s3 is an S3 client that builds with TinyGo.
Package websocket implements the WebSocket protocol defined in RFC 6455.
Package websocket implements the WebSocket protocol defined in RFC 6455.

Jump to

Keyboard shortcuts

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