Standard Library Packages
This document defines the complete set of standard library packages for Run, their purpose, key types/functions, dependencies, and implementation priority.
Design Principles
Section titled “Design Principles”- Batteries-included — Ship everything needed to build servers, CLI tools, and systems software
- Return errors, don’t panic — Use
!Tfor fallible operations, sum types for error categories - Small interfaces — Many small interfaces (
Reader,Writer,Closer) over few large ones - Explicit cleanup —
deferfor resource cleanup, no implicit finalization - No generics — Built-in collections (
[]T,map[K]V,chan[T]) are the polymorphic containers - Go-familiar — A Go developer should feel at home, but leverage Run’s error unions, sum types, and generational references where they improve the API
- Minimal surface — Start with the 80% use case per package, extend later
Priority Tiers
Section titled “Priority Tiers”| Tier | Meaning | Milestone |
|---|---|---|
| P0 | Core — everything depends on these | M10 |
| P1 | Essential utilities — needed by most programs | M11 |
| P2 | Important ecosystem — needed for real applications | M12 |
| P3 | Advanced/specialized — systems programming power | M13 |
P0 — Core Packages
Section titled “P0 — Core Packages”fmt — Formatting and Printing
Section titled “fmt — Formatting and Printing”Purpose: String formatting, printing to stdout/stderr, and the Stringer interface.
Key types and functions:
Stringer interface — types that can format themselves as stringsprintln(args) — print with spaces and newline to stdoutprint(args) — print without separator or newlineprintf(format, args) — formatted print with verbs (%d, %s, %v, %f, %x, %o, %b)eprintln(args) — print to stderrsprintf(format, args) string — format to stringsprint(args) string — concatenate to stringsprintln(args) string — concatenate with spaces and newlineDependencies: io (for Writer interface)
Status: Stub exists
io — I/O Interfaces and Utilities
Section titled “io — I/O Interfaces and Utilities”Purpose: Core I/O interfaces that all I/O types implement. Buffered wrappers. Utility functions for copying, limiting, and composing streams.
Key types and functions:
Reader interface — read(buf []byte) !intWriter interface — write(data []byte) !intCloser interface — close() !Seeker interface — seek(offset int, whence SeekWhence) !intReadWriter interface — Reader + WriterReadCloser interface — Reader + CloserWriteCloser interface — Writer + CloserReadWriteCloser interface — Reader + Writer + CloserReadSeeker interface — Reader + Seeker
SeekWhence sum type — .start | .current | .endIoError sum type — .unexpectedEof | .brokenPipe | .timeout | .closed
BufferedReader struct — wraps Reader with internal bufferBufferedWriter struct — wraps Writer with internal buffer
read_all(Reader) ![]byte — read everything until EOFcopy(Writer, Reader) !int — stream copycopy_n(Writer, Reader, int) !int — copy exactly n byteslimit_reader(Reader, int) Reader — reader that stops after n bytesdiscard Writer — writer that discards all dataDependencies: None (leaf package) Status: Stub exists
os — Operating System Interface
Section titled “os — Operating System Interface”Purpose: File system operations, environment variables, process control, and path manipulation. Path utilities live here (not a separate package).
Key types and functions:
File struct — open file handle (implements io.Reader, io.Writer, io.Closer, io.Seeker)FileInfo struct — file metadata (name, size, is_dir, mode, mod_time)DirEntry struct — directory entry (name, is_dir, type)FileMode sum type — .regular | .directory | .symlink | .socket | .pipe | .deviceFileError sum type — .notFound | .permissionDenied | .alreadyExists | .isDirectory | .notDirectory | .diskFull | .tooManyOpen
open(path) !File — open for readingcreate(path) !File — create/truncate for writingopen_file(path, flags, mode) !File — open with full controlstat(path) !FileInfo — file metadatalstat(path) !FileInfo — metadata without following symlinksread_file(path) ![]byte — read entire filewrite_file(path, data) ! — write entire fileread_dir(path) ![]DirEntry — list directory contentsmkdir(path) ! — create directorymkdir_all(path) ! — create directory treeremove(path) ! — remove file or empty directoryremove_all(path) ! — remove treerename(old, new) ! — rename/movesymlink(target, link) ! — create symlinkread_link(path) !string — read symlink targetchmod(path, mode) ! — change permissionschown(path, uid, gid) ! — change ownershiptemp_dir() string — OS temp directorycreate_temp(prefix) !File — create temp filetemp_file(prefix) !File — backward-compatible alias for create_temp
// Path utilities (no separate path package)join_path(parts []string) string — join path componentsbase(path) string — last element of pathdir(path) string — all but last elementext(path) string — file extensionclean(path) string — clean/normalize pathabs(path) !string — absolute pathis_abs(path) bool — is path absolutesplit_path(path) (string, string) — split into dir and fileglob(pattern) ![]string — match file pattern
// Process and environmentargs() []string — command-line argumentsgetenv(key) string? — get environment variablesetenv(key, value) ! — set environment variableunsetenv(key) ! — remove environment variableenviron() []string — all environment variables as KEY=VALUEexit(code) — terminate processgetpid() int — current process IDhostname() !string — machine hostnamecwd() !string — current working directorygetwd() !string — backward-compatible alias for cwdchdir(path) ! — change working directoryuser_home_dir() !string — user home directory
// stdin, stdout, stderr as package-level File valuesDependencies: io
Status: Stub exists
errors — Error Creation, Wrapping, Inspection
Section titled “errors — Error Creation, Wrapping, Inspection”Purpose: Create, wrap, and inspect error chains. Run has !T error unions but needs a standard way to build and traverse error values.
Key types and functions:
Error interface — message() stringWrapper interface — unwrap() Error?SimpleError struct — basic error with message stringWrappedError struct — error that wraps another with context
new(msg string) Error — create a simple errorwrap(err Error, msg string) Error — wrap error with contextwrap_f(err Error, fmt string, args...) Error — wrap with formatted contextunwrap(err Error) Error? — get inner erroris(err Error, target Error) bool — walk chain checking matchas(err Error, target &any) bool — type-narrow within chainjoin(errs []Error) Error? — combine multiple errorsDependencies: None (leaf package) Status: Stub exists
P1 — Essential Utility Packages
Section titled “P1 — Essential Utility Packages”strings — String Manipulation
Section titled “strings — String Manipulation”Purpose: Functions for searching, splitting, joining, trimming, and transforming strings.
Key types and functions:
Builder struct — efficient string concatenation
contains(s, substr) boolhas_prefix(s, prefix) boolhas_suffix(s, suffix) boolindex_of(s, substr) int?last_index_of(s, substr) int?count(s, substr) intsplit(s, sep) []stringsplit_n(s, sep, n) []stringfields(s) []string — split on whitespacejoin(parts, sep) stringreplace(s, old, new) stringreplace_n(s, old, new, n) stringtrim(s) stringtrim_left(s) stringtrim_right(s) stringtrim_prefix(s, prefix) stringtrim_suffix(s, suffix) stringtrim_chars(s, cutset) stringto_upper(s) stringto_lower(s) stringto_title(s) stringrepeat(s, count) stringequal_fold(a, b) bool — case-insensitive comparisonDependencies: None Status: Stub exists
bytes — Byte Slice Utilities
Section titled “bytes — Byte Slice Utilities”Purpose: Functions that operate on []byte, mirroring strings where applicable. Includes a Buffer type for growable byte buffers.
Key types and functions:
Buffer struct — growable byte buffer (implements io.Reader, io.Writer) write_string(s string) !int write_byte(b byte) ! bytes() []byte string() string reset() len() int cap() int
contains(b, sub []byte) boolindex(b, sub []byte) int?split(b, sep []byte) [][]bytejoin(parts [][]byte, sep []byte) []bytetrim(b []byte) []byteequal(a, b []byte) boolhas_prefix(b, prefix []byte) boolhas_suffix(b, suffix []byte) boolrepeat(b []byte, count int) []byteto_lower(b []byte) []byteto_upper(b []byte) []byteDependencies: io
math — Mathematical Functions
Section titled “math — Mathematical Functions”Purpose: Math constants, floating-point and integer arithmetic functions.
Key types and functions:
// Constants: pi, e, phi, sqrt2, ln2, ln10, max_f64, min_f64, max_int, min_int, inf, nan
abs(x f64) f64abs_int(x int) intmin(a, b f64) f64max(a, b f64) f64min_int(a, b int) intmax_int(a, b int) intfloor(x f64) f64ceil(x f64) f64round(x f64) f64trunc(x f64) f64sqrt(x f64) f64cbrt(x f64) f64pow(base, exp f64) f64log(x f64) f64log2(x f64) f64log10(x f64) f64exp(x f64) f64exp2(x f64) f64sin(x f64) f64cos(x f64) f64tan(x f64) f64asin(x f64) f64acos(x f64) f64atan(x f64) f64atan2(y, x f64) f64sinh(x f64) f64cosh(x f64) f64tanh(x f64) f64hypot(x, y f64) f64fma(x, y, z f64) f64 — fused multiply-addmod(x, y f64) f64remainder(x, y f64) f64is_nan(x f64) boolis_inf(x f64) boolis_finite(x f64) boolclamp(x, lo, hi f64) f64clamp_int(x, lo, hi int) intcopysign(x, y f64) f64Dependencies: None Status: Stub exists
math/rand — Pseudo-Random Number Generation
Section titled “math/rand — Pseudo-Random Number Generation”Purpose: Fast, non-cryptographic PRNG for simulations, testing, and general use.
Key types and functions:
Rand struct — PRNG state (xoshiro256**)
new(seed int) Rand — create seeded PRNGint() int — random intint_n(n int) int — random int in [0, n)f64() f64 — random float in [0.0, 1.0)bool() bool — random booleanshuffle(s []any) — in-place shufflechoice(s []any) any — random elementDependencies: math
testing — Test Framework
Section titled “testing — Test Framework”Purpose: Test context, composable assertion operators, table-driven tests, fuzzing, and benchmarking.
Uses the test and bench language keywords — tests are first-class language constructs.
Assertion operators inspired by go-testdeep.
Language constructs:
test "name" (t) { body } — unit test blockfor test "name" in ["case" :: {}, ...] (t) { body } — table-driven testfor test "name" in [...] as { fields } (t) { body } — table-driven with destructuringtest "name" fuzz(params) (t) { body } — fuzz testtest "name" fuzz(params) seed [...] (t) { body } — fuzz test with seed corpusbench "name" (b) { body } — benchmark blockfor bench "name" in ["case" :: {}, ...] (b) { body } — table-driven benchmarktest beforeAll { } — file-level setuptest afterAll { } — file-level teardowntest beforeEach { } — per-test setuptest afterEach { } — per-test teardownKey types and functions:
Operator struct — comparison operator for t.expect
T struct — test context (explicit `t` parameter) expect(got, operator) — single assertion method log(msg) — log message (shown on failure or -v) logf(format, args) — formatted log fail() — mark failed, continue failNow() — mark failed, stop error(msg) — log + fail errorf(format, args) — formatted log + fail fatal(msg) — log + fail + stop fatalf(format, args) — formatted log + fail + stop skip(reason) — skip this test run(name) (t) { } — launch a subtest parallel() — mark safe for parallel execution name() string — current test name deadline() int — timeout deadline tempDir() string — auto-cleaned temp directory
// Operator methods (return Operator for use with t.expect) eq(want) — deep equality ne(want) — not equal gt(bound), gte(bound) — greater than / greater or equal lt(bound), lte(bound) — less than / less or equal between(lo, hi) — range [lo, hi] isTrue(), isFalse() — boolean checks isNil(), notNil() — null checks isErr(), isOk() — error union checks hasPrefix(s), hasSuffix(s) — string prefix/suffix contains(v) — substring or element containment matches(pattern) — regex match hasLen(n), hasCap(n) — length/capacity isEmpty(), notEmpty() — emptiness containsAll(items...) — all items present containsAny(items...) — at least one present all(ops...), any(ops...) — AND / OR composition none(ops...), not(op) — NOR / negation approx(want, tol) — approximate equality typeOf(name) — type check
B struct — benchmark context (explicit `b` parameter) n int — iteration count (set by framework) resetTimer() — exclude setup from timing startTimer() — resume timing stopTimer() — pause timing reportMetric(name, val, unit) — custom metric bytesPerOp(n) — for throughput calculation run(name) (b) { } — sub-benchmark
F struct — fuzz context add(args) — add seed corpus entry
TestResult struct — test run summary passed int failed int skipped int fuzzed int benched int total() int ok() boolDependencies: fmt, strings
Status: Stub exists (redesigned)
time — Time, Duration, and Timers
Section titled “time — Time, Duration, and Timers”Purpose: Wall clock time, monotonic time, durations, formatting/parsing, timers, and tickers for periodic events.
Key types and functions:
Time struct — point in time (wall + monotonic)Duration struct — time interval in nanosecondsMonth sum type — .january | .february | ... | .decemberWeekday sum type — .sunday | .monday | ... | .saturdayLocation struct — timezone
// Duration constantsnanosecond, microsecond, millisecond, second, minute, hour Duration
now() Time — current timesince(t Time) Duration — time elapsed since tuntil(t Time) Duration — time remaining until tsleep(d Duration) — pause current green thread
// Time methods(t @Time) add(d Duration) Time(t @Time) sub(other Time) Duration(t @Time) before(other Time) bool(t @Time) after(other Time) bool(t @Time) equal(other Time) bool(t @Time) unix() int — seconds since epoch(t @Time) unix_milli() int — milliseconds since epoch(t @Time) unix_nano() int — nanoseconds since epoch(t @Time) year() int(t @Time) month() Month(t @Time) day() int(t @Time) hour() int(t @Time) minute() int(t @Time) second() int(t @Time) weekday() Weekday(t @Time) format(layout string) stringparse(layout, value string) !Time
// Timers and TickersTimer struct — one-shot timer with channelTicker struct — repeating ticker with channelnew_timer(d Duration) Timernew_ticker(d Duration) Ticker(t &Timer) stop()(t &Timer) reset(d Duration)(tk &Ticker) stop()Dependencies: None (uses compiler builtins for clock)
log — Structured Logging
Section titled “log — Structured Logging”Purpose: Leveled, structured logging with configurable output.
Key types and functions:
Level sum type — .debug | .info | .warn | .errorLogger struct — configurable loggerHandler interface — custom log output backend
new(handler Handler) Loggerdefault() Logger — package-level default logger
// Package-level functions (use default logger)debug(msg, fields...)info(msg, fields...)warn(msg, fields...)error(msg, fields...)
// Logger methods(l &Logger) debug(msg, fields...)(l &Logger) info(msg, fields...)(l &Logger) warn(msg, fields...)(l &Logger) error(msg, fields...)(l &Logger) with(fields...) Logger — create child logger with preset fields(l &Logger) set_level(level Level)
// Built-in handlersTextHandler struct — human-readable text outputJsonHandler struct — structured JSON outputDependencies: io, time, fmt
iter — Iterator Protocol and Combinators
Section titled “iter — Iterator Protocol and Combinators”Purpose: Lazy iteration abstraction with functional combinators. Uses any types; see run gen for type-safe specializations.
Key types and functions:
Iterator interface — next() any?
from_slice(s []any) Iterator — iterate over slice elementsrange(start, end int) Iterator — iterate over integer rangemap(it Iterator, f fun(any) any) Iterator — apply f to each elementfilter(it Iterator, f fun(any) bool) Iterator — yield only matching elementsreduce(it Iterator, init any, f fun(acc, item any) any) any — foldtake(it Iterator, n int) Iterator — yield at most n elementsskip(it Iterator, n int) Iterator — skip first n elementszip(a, b Iterator) Iterator — combine element-wisechain(a, b Iterator) Iterator — concatenate sequentiallyenumerate(it Iterator) Iterator — yield (index, item) pairscollect(it Iterator) []any — consume into slicecount(it Iterator) int — count remaining elementsany_match(it Iterator, f fun(any) bool) bool — true if any matchall_match(it Iterator, f fun(any) bool) bool — true if all matchfor_each(it Iterator, f fun(any)) — apply f for side effectsflat_map(it Iterator, f fun(any) Iterator) Iterator — map and flattentake_while(it Iterator, f fun(any) bool) Iteratorskip_while(it Iterator, f fun(any) bool) IteratorDependencies: None Status: Stub exists
slices — Slice Utilities
Section titled “slices — Slice Utilities”Purpose: Common operations on slices: search, sort, transform, compare.
Key types and functions:
contains(s []any, v any) bool — membership testindex(s []any, v any) int? — first index of vlast_index(s []any, v any) int? — last index of vcompact(s []any) []any — remove consecutive duplicatessort_func(s []any, cmp fun(a, b any) int) — sort in-placeis_sorted_func(s []any, cmp fun(a, b any) int) boolreverse(s []any) — reverse in placegrow(s []any, n int) []any — increase capacityinsert(s []any, i int, v any) []any — insert at indexdelete(s []any, i int) []any — remove at indexclone(s []any) []any — shallow copyequal(a, b []any) bool — element-wise equalitymin_func(s []any, cmp fun) any — minimum by comparatormax_func(s []any, cmp fun) any — maximum by comparatorbinary_search_func(s []any, target any, cmp fun) int?chunk(s []any, size int) [][]any — split into chunksconcat(slices [][]any) []any — concatenate slicesDependencies: None Status: Stub exists
maps — Map Utilities
Section titled “maps — Map Utilities”Purpose: Common operations on maps: key/value extraction, comparison, copying.
Key types and functions:
keys(m map[any]any) []any — all keys as slicevalues(m map[any]any) []any — all values as sliceclone(m map[any]any) map[any]any — shallow copyequal(a, b map[any]any) bool — key/value equalityequal_func(a, b map[any]any, eq fun) bool — equality with custom comparatordelete_func(m map[any]any, f fun(key, value any) bool) — conditional deletecopy(dst, src map[any]any) — copy all entries from src to dsthas(m map[any]any, key any) bool — key membership testDependencies: None Status: Stub exists
cmp — Comparison and Ordering
Section titled “cmp — Comparison and Ordering”Purpose: Comparison interfaces and ordering utilities.
Key types and functions:
Ordering sum type — .less | .equal | .greaterOrdered interface — compare(other any) Ordering
compare(a, b any) Ordering — generic comparisonmin(a, b any) any — smaller of two valuesmax(a, b any) any — larger of two valuesclamp(val, lo, hi any) any — constrain to rangemin_int(a, b int) int — integer minmax_int(a, b int) int — integer maxclamp_int(val, lo, hi int) int — integer clampmin_float(a, b f64) f64 — float minmax_float(a, b f64) f64 — float maxDependencies: None Status: Stub exists
math/bits — Bit Manipulation
Section titled “math/bits — Bit Manipulation”Purpose: Bit counting, rotation, reversal, and extended arithmetic operations.
Key types and functions:
leading_zeros(x int) int — count leading zerostrailing_zeros(x int) int — count trailing zerosones_count(x int) int — population countrotate_left(x int, k int) int — rotate left by k bitsrotate_right(x int, k int) int — rotate right by k bitsreverse(x int) int — reverse bit orderreverse_bytes(x int) int — byte swaplen(x int) int — bit lengthadd(x, y, carry int) int — extended add with carrysub(x, y, borrow int) int — extended sub with borrowmul(x, y int) int — full-width multiplyleading_zeros32(x int) int — 32-bit leading zerostrailing_zeros32(x int) int — 32-bit trailing zerosones_count32(x int) int — 32-bit popcountDependencies: None Status: Stub exists
path — OS-Independent Path Manipulation
Section titled “path — OS-Independent Path Manipulation”Purpose: Clean path manipulation using forward slashes, independent of OS. For OS-specific paths use os package path functions.
Key types and functions:
join(parts ...string) string — join path elementsbase(p string) string — last path elementdir(p string) string — all but last elementext(p string) string — file extensionclean(p string) string — shortest equivalent pathis_abs(p string) bool — absolute path checksplit(p string) string — directory + file componentsmatch(pattern, name string) !bool — shell pattern matchrel(base, target string) !string — relative pathDependencies: None Status: Stub exists
P2 — Application Packages
Section titled “P2 — Application Packages”net — Networking
Section titled “net — Networking”Purpose: TCP/UDP sockets, DNS resolution, IP address types. Foundation for all network protocols.
Key types and functions:
Addr interface — network addressTcpAddr struct — TCP address (ip + port)UdpAddr struct — UDP address (ip + port)Ip struct — IP address (v4 or v6)Listener struct — TCP listener (implements io.Closer)Conn struct — network connection (implements io.Reader, io.Writer, io.Closer)UdpConn struct — UDP connection
NetError sum type — .connectionRefused | .connectionReset | .timeout | .addressInUse | .hostUnreachable | .networkUnreachable | .dnsNotFound
listen(network, address string) !Listener — start TCP listener(l &Listener) accept() !Conn — accept connectiondial(network, address string) !Conn — connect to addressdial_timeout(network, address string, timeout Duration) !Connresolve_ip(host string) ![]Ip — DNS lookup
(c &Conn) read(buf []byte) !int(c &Conn) write(data []byte) !int(c &Conn) close() !(c &Conn) set_deadline(t Time) !(c &Conn) set_read_deadline(t Time) !(c &Conn) set_write_deadline(t Time) !(c @Conn) local_addr() Addr(c @Conn) remote_addr() AddrDependencies: io, time, os
net/http — HTTP Client and Server
Section titled “net/http — HTTP Client and Server”Purpose: HTTP/1.1 client and server with high-performance routing, middleware, and streaming support. The built-in router uses a radix tree (Patricia trie) for O(k) route matching (where k is path length), similar to chi/httprouter. No need for third-party routers.
Key types and functions:
// ServerServer struct — HTTP serverHandler interface — fun serve_http(w &ResponseWriter, r @Request)Middleware type — fun(next Handler) HandlerResponseWriter struct — write HTTP responses (implements io.Writer)
listen_and_serve(addr string, handler Handler) !listen_and_serve_tls(addr, cert_file, key_file string, handler Handler) !
// Router — Patricia trie based, chi-styleRouter struct — radix tree request routernew_router() Router
// Route registration — supports path parameters and wildcards(r &Router) get(pattern string, handler Handler)(r &Router) post(pattern string, handler Handler)(r &Router) put(pattern string, handler Handler)(r &Router) delete(pattern string, handler Handler)(r &Router) patch(pattern string, handler Handler)(r &Router) head(pattern string, handler Handler)(r &Router) options(pattern string, handler Handler)(r &Router) handle(pattern string, handler Handler) — any method(r &Router) handle_func(pattern string, fun(&ResponseWriter, @Request))(r &Router) method(method, pattern string, handler Handler) — custom method
// Route groups and middleware (chi-style)(r &Router) group(fn fun(sub &Router)) — inline group(r &Router) route(prefix string, sub Handler) — mount sub-router at prefix(r &Router) use(middlewares ...Middleware) — apply middleware to group(r &Router) with(middlewares ...Middleware) Router — return new router with middleware
// Path parameters — extracted from {name} segments// Pattern: "/users/{id}/posts/{post_id}"// Pattern: "/files/{path...}" (wildcard catch-all)url_param(r @Request, name string) string
// Request/ResponseRequest struct — HTTP request method string url Url header Header body io.ReadCloserResponse struct — HTTP response status int status_text string header Header body io.ReadCloserHeader struct — HTTP headers (wraps map[string][]string)Url struct — parsed URLCookie struct — HTTP cookie
// ResponseWriter helpers(w &ResponseWriter) write_header(status_code int)(w &ResponseWriter) set_header(key, value string)(w &ResponseWriter) write_json(status int, value any) !(w &ResponseWriter) redirect(url string, code int)
// ClientClient struct — HTTP client with timeouts and redirectsget(url string) !Responsepost(url, content_type string, body io.Reader) !Responsehead(url string) !Response(c &Client) do(req @Request) !Response
// Built-in middlewarelog_middleware() Middleware — request loggingrecover_middleware() Middleware — panic recoverytimeout_middleware(d Duration) Middlewarecors_middleware(opts CorsOptions) Middlewaremetrics_middleware(opts MetricsOptions) Middleware — Prometheus metrics per route
// MetricsOptions for metrics middlewaretype MetricsOptions struct { set &metrics.Set? — custom Set, nil = default set request_counter string — counter name (default: "http_requests_total") duration_histogram string — histogram name (default: "http_request_duration_seconds") in_flight_gauge string — gauge name (default: "http_requests_in_flight") response_size string — counter name (default: "http_response_bytes_total")}// Labels added automatically: method, path, status
// Status codes as constantsstatus_ok, status_created, status_not_found, status_internal_server_error, ...Router design notes:
- Patricia trie stores compressed path segments for memory efficiency
- Route conflicts are detected at registration time, not at request time
{param}matches a single path segment,{param...}matches the rest of the path- Method-specific trees — each HTTP method has its own trie for zero-allocation matching
- Middleware stacks are chi-style:
Use()for group-level,With()for inline
Example:
package main
use "net/http"
pub fun main() { r := http.new_router()
// Middleware r.use(http.log_middleware()) r.use(http.recover_middleware())
// Routes r.get("/", index_handler) r.route("/api", fun(api &http.Router) { api.use(auth_middleware()) api.get("/users/{id}", get_user) api.post("/users", create_user) api.get("/files/{path...}", serve_file) })
http.listen_and_serve(":8080", r)}
fun get_user(w &http.ResponseWriter, r @http.Request) { id := http.url_param(r, "id") // ...}Dependencies: net, io, fmt, strings, time, context, metrics
net/http2 — HTTP/2 Protocol
Section titled “net/http2 — HTTP/2 Protocol”Purpose: HTTP/2 framing, multiplexed streams, flow control, and HPACK header compression. Used directly by net/http for h2 connections and as the transport layer for gRPC.
Key types and functions:
Transport struct — HTTP/2 client transport (implements http round-tripper)Server struct — HTTP/2 server (used automatically by net/http when TLS is configured)
Frame sum type — .data | .headers | .priority | .rst_stream | .settings | .push_promise | .ping | .goaway | .window_update | .continuationStream struct — single HTTP/2 stream within a connection
// Most users don't interact with net/http2 directly.// net/http uses it automatically for HTTP/2 connections.// grpc uses it as its transport layer.
configure_server(srv &http.Server) ! — enable HTTP/2 on existing HTTP serverconfigure_transport(t &http.Transport) !Dependencies: net, net/http, io, sync, crypto/tls
net/grpc — gRPC Client and Server
Section titled “net/grpc — gRPC Client and Server”Purpose: Full gRPC support — unary RPCs, server streaming, client streaming, and bidirectional streaming. Integrates with Run’s green threads for natural concurrency and channels for streaming patterns.
Key types and functions:
// ServerServer struct — gRPC serverServiceDesc struct — service descriptor (generated from .proto)MethodDesc struct — method descriptorStreamDesc struct — streaming method descriptor
new_server(opts ...ServerOption) Server(s &Server) register_service(desc @ServiceDesc, impl any)(s &Server) serve(listener net.Listener) !(s &Server) graceful_stop()(s &Server) stop()
ServerOption sum type — .max_recv_msg_size(int) | .max_send_msg_size(int) | .max_concurrent_streams(int) | .keepalive(KeepaliveParams) | .creds(Credentials) | .interceptor(UnaryServerInterceptor) | .stream_interceptor(StreamServerInterceptor)
// ClientClientConn struct — gRPC client connectiondial(target string, opts ...DialOption) !ClientConn(cc &ClientConn) close() !
DialOption sum type — .insecure | .block | .timeout(Duration) | .creds(Credentials) | .keepalive(KeepaliveParams) | .interceptor(UnaryClientInterceptor) | .stream_interceptor(StreamClientInterceptor) | .default_service_config(string)
// RPC invocation (used by generated code)invoke(cc &ClientConn, method string, req any, reply &any, opts ...CallOption) !new_stream(cc &ClientConn, desc @StreamDesc, method string, opts ...CallOption) !ClientStream
// Streaming interfacestype ServerStream interface { send(msg any) ! recv(msg &any) ! send_header(Metadata) ! set_trailer(Metadata)}type ClientStream interface { send(msg any) ! recv(msg &any) ! close_send() ! header() !Metadata trailer() Metadata}
// Status and errorsStatus struct — gRPC status (code + message + details)Code sum type — .ok | .cancelled | .unknown | .invalid_argument | .deadline_exceeded | .not_found | .already_exists | .permission_denied | .resource_exhausted | .failed_precondition | .aborted | .out_of_range | .unimplemented | .internal | .unavailable | .data_loss | .unauthenticated
new_status(code Code, msg string) Status(s @Status) err() error(s @Status) code() Code(s @Status) message() stringfrom_error(err error) Status
// Metadata (request/response headers)Metadata struct — key-value pairs attached to RPCsnew_metadata(pairs ...string) Metadata(md &Metadata) get(key string) []string(md &Metadata) set(key string, values ...string)(md &Metadata) append(key string, values ...string)
// InterceptorsUnaryServerInterceptor type — fun(ctx Context, req any, info @UnaryServerInfo, handler UnaryHandler) !anyStreamServerInterceptor type — fun(srv any, stream ServerStream, info @StreamServerInfo, handler StreamHandler) !UnaryClientInterceptor type — fun(ctx Context, method string, req any, reply &any, cc &ClientConn, invoker UnaryInvoker, opts ...CallOption) !StreamClientInterceptor type — fun(ctx Context, desc @StreamDesc, cc &ClientConn, method string, streamer Streamer, opts ...CallOption) !ClientStream
// Credentialstype Credentials interface { require_transport_security() bool}insecure_credentials() Credentialstls_credentials(config @tls.Config) Credentials
// Keepalivetype KeepaliveParams struct { time Duration — ping interval when idle timeout Duration — wait for ping ack permit_without_stream bool — ping even with no active RPCs}
// Health checkingHealthServer struct — standard gRPC health check service (grpc.health.v1)(hs &HealthServer) set_status(service string, status ServingStatus)ServingStatus sum type — .unknown | .serving | .not_servingDesign notes:
- gRPC streaming maps naturally to Run’s channels — a bidirectional stream can be bridged to
chan[Request]/chan[Response]pairs - Green threads mean each RPC handler runs concurrently without callback complexity
context.Contextcarries deadlines and cancellation across RPC boundaries- Interceptors provide middleware for auth, logging, metrics, and tracing
- Protocol Buffers serialization is handled by
encoding/proto; service stubs are generated by aprotoc-gen-runtool
Dependencies: net, net/http2, encoding/proto, context, time, sync, crypto/tls
encoding/proto — Protocol Buffers
Section titled “encoding/proto — Protocol Buffers”Purpose: Protocol Buffers binary serialization (proto3). Encode and decode protobuf messages. Foundation for gRPC wire format.
Key types and functions:
Message interface — types that can be serialized as protobuf proto_marshal() ![]byte proto_unmarshal(data []byte) !
marshal(msg Message) ![]byte — encode message to wire formatunmarshal(data []byte, msg &Message) ! — decode wire format into messagesize(msg @Message) int — encoded size in bytes
// Wire types (used by generated code and reflection)WireType sum type — .varint | .fixed64 | .length_delimited | .fixed32
// Field descriptors (for reflection / dynamic messages)type FieldDescriptor struct { number int name string wire_type WireType repeated bool}
// Encoding helpers (used by generated code)encode_varint(buf &bytes.Buffer, v int) !encode_bytes(buf &bytes.Buffer, data []byte) !encode_fixed32(buf &bytes.Buffer, v u32) !encode_fixed64(buf &bytes.Buffer, v u64) !decode_varint(data []byte, offset int) !(int, int)decode_bytes(data []byte, offset int) !([]byte, int)Design notes:
- Run structs with field tags (e.g.,
@proto(1)) map to protobuf fields protoc-gen-rungenerates Run struct definitions + marshal/unmarshal from.protofiles- No reflection-based encoding — generated code is fast and type-safe
Dependencies: bytes, io
encoding/json — JSON Encoding/Decoding
Section titled “encoding/json — JSON Encoding/Decoding”Purpose: Encode Run values to JSON and decode JSON into Run values. Struct field tags control serialization.
Key types and functions:
Value sum type — .null | .bool(bool) | .int(int) | .float(f64) | .string(string) | .array([]Value) | .object(map[string]Value)JsonError sum type — .syntaxError | .unexpectedToken | .overflow | .missingField
marshal(value any) ![]byte — encode to JSON bytesmarshal_indent(value any, indent string) ![]byteunmarshal(data []byte, target &any) ! — decode into targetmarshal_string(value any) !string — encode to JSON string
// StreamingEncoder struct — streaming JSON encoder (wraps io.Writer)Decoder struct — streaming JSON decoder (wraps io.Reader)new_encoder(w io.Writer) Encodernew_decoder(r io.Reader) Decoder(e &Encoder) encode(value any) !(d &Decoder) decode(target &any) !
// Value manipulationparse(data []byte) !Value — parse to dynamic Value tree(v @Value) get(key string) Value?(v @Value) index(i int) Value?(v @Value) as_string() string?(v @Value) as_int() int?(v @Value) as_float() f64?(v @Value) as_bool() bool?Dependencies: io, strings, bytes, fmt
encoding/csv — CSV Encoding/Decoding
Section titled “encoding/csv — CSV Encoding/Decoding”Purpose: Read and write CSV files with configurable delimiters.
Key types and functions:
Reader struct — CSV reader (wraps io.Reader)Writer struct — CSV writer (wraps io.Writer)
new_reader(r io.Reader) Readernew_writer(w io.Writer) Writer
(r &Reader) read() ![]string — read one record(r &Reader) read_all() ![][]string — read all records(w &Writer) write(record []string) !(w &Writer) write_all(records [][]string) !(w &Writer) flush() !Dependencies: io, strings, bytes
encoding/base64 — Base64 Encoding
Section titled “encoding/base64 — Base64 Encoding”Purpose: Standard and URL-safe base64 encoding/decoding.
Key types and functions:
Encoding struct — encoding configuration
std_encoding Encoding — standard base64 (RFC 4648)url_encoding Encoding — URL-safe base64raw_std_encoding Encoding — no paddingraw_url_encoding Encoding — URL-safe, no padding
encode(src []byte) stringdecode(s string) ![]byte(enc @Encoding) encode(src []byte) string(enc @Encoding) decode(s string) ![]byteencoded_len(n int) intdecoded_len(n int) intDependencies: None
encoding/hex — Hexadecimal Encoding
Section titled “encoding/hex — Hexadecimal Encoding”Purpose: Hex encoding/decoding and hex dump utilities.
Key types and functions:
encode(src []byte) stringdecode(s string) ![]bytedump(data []byte) string — hex dump with offsets and ASCIIDependencies: bytes
crypto — Cryptographic Primitives
Section titled “crypto — Cryptographic Primitives”Purpose: Cryptographically secure random numbers and the Hash interface.
Key types and functions:
Hash interface — write([]byte) !int, sum() []byte, reset(), size() int, block_size() intrand_bytes(n int) ![]byte — cryptographically secure random bytesrand_int() !int — cryptographically secure random intDependencies: io
crypto/sha256 — SHA-256
Section titled “crypto/sha256 — SHA-256”Purpose: SHA-256 hash function.
Key types and functions:
Digest struct — implements crypto.Hashnew() Digestsum(data []byte) []byte — one-shot hashDependencies: crypto
crypto/sha512 — SHA-512
Section titled “crypto/sha512 — SHA-512”Purpose: SHA-512 hash function.
Key types and functions:
Digest struct — implements crypto.Hashnew() Digestsum(data []byte) []byteDependencies: crypto
crypto/hmac — HMAC
Section titled “crypto/hmac — HMAC”Purpose: Keyed-hash message authentication codes.
Key types and functions:
new(hash_fn fun() crypto.Hash, key []byte) crypto.Hashequal(a, b []byte) bool — constant-time comparisonDependencies: crypto
crypto/aes — AES Encryption
Section titled “crypto/aes — AES Encryption”Purpose: AES block cipher.
Key types and functions:
Cipher struct — AES cipher blocknew(key []byte) !Cipher(c @Cipher) encrypt(dst, src []byte)(c @Cipher) decrypt(dst, src []byte)block_size() intDependencies: crypto
crypto/tls — TLS
Section titled “crypto/tls — TLS”Purpose: TLS client and server support for secure connections.
Key types and functions:
Config struct — TLS configurationConn struct — TLS connection (implements net.Conn, io.ReadWriteCloser)
dial(network, addr string, config @Config) !Connlisten(network, addr string, config @Config) !net.ListenerDependencies: crypto, crypto/sha256, crypto/aes, net, io
sync — Synchronization Primitives
Section titled “sync — Synchronization Primitives”Purpose: Mutexes, read-write locks, wait groups, atomics, and once-initialization for shared-memory concurrency.
Key types and functions:
Mutex struct — mutual exclusion lock lock() unlock() try_lock() bool
RwMutex struct — read-write lock read_lock() read_unlock() write_lock() write_unlock()
WaitGroup struct — wait for goroutine completion add(delta int) done() wait()
Once struct — run initialization exactly once do(f fun())
Atomic struct — atomic integer operations load() int store(val int) add(delta int) int swap(new int) int compare_and_swap(old, new int) boolDependencies: None (uses compiler builtins for atomics)
unsafe — Low-Level Operations
Section titled “unsafe — Low-Level Operations”Purpose: Raw pointer manipulation, type layout introspection, and escape hatches from the safety model. Importing unsafe signals that a file does low-level operations.
Key types and functions:
Pointer struct — raw untyped pointer
ptr(ref &any) Pointer — convert typed ref to raw pointercast(type, p Pointer) &type — convert raw pointer to typed refsizeof(type) int — size of type in bytesalignof(type) int — alignment of type in bytesoffsetof(type, field) int — field offset in bytesslice(ptr Pointer, len int) []byte — create slice from raw pointerDependencies: None
Status: Design exists in docs/unsafe.md
sort — Sorting
Section titled “sort — Sorting”Purpose: Sorting slices of concrete types and custom sort via a comparator interface.
Key types and functions:
Less interface — fun less(i, j int) bool
ints(s []int) — sort int slice ascendingfloats(s []f64) — sort f64 slice ascendingstrings_sort(s []string) — sort string slice ascendingsort(s []any, cmp fun(a, b any) int) — sort with comparatoris_sorted(s []any, cmp fun(a, b any) int) boolreverse(s []any) — reverse slice in placesearch(s []any, target any, cmp fun(a, b any) int) int? — binary searchDependencies: None
strconv — String Conversions
Section titled “strconv — String Conversions”Purpose: Convert between strings and basic types (int, float, bool).
Key types and functions:
ParseError sum type — .invalidSyntax | .outOfRange
parse_int(s string, base int) !intparse_float(s string) !f64parse_bool(s string) !boolformat_int(i int, base int) stringformat_float(f f64, fmt byte, prec int) stringformat_bool(b bool) stringatoi(s string) !int — shorthand for parse_int(s, 10)itoa(i int) string — shorthand for format_int(i, 10)quote(s string) string — add quotes and escapeunquote(s string) !string — remove quotes and unescapeDependencies: strings
regex — Regular Expressions
Section titled “regex — Regular Expressions”Purpose: Regular expression matching and replacement.
Key types and functions:
Regex struct — compiled regular expressionMatch struct — match result with captures
compile(pattern string) !Regexmust_compile(pattern string) Regex — panics on invalid pattern
(re @Regex) is_match(s string) bool(re @Regex) find(s string) Match?(re @Regex) find_all(s string) []Match(re @Regex) replace(s, replacement string) string(re @Regex) replace_all(s, replacement string) string(re @Regex) split(s string) []string
(m @Match) text() string(m @Match) start() int(m @Match) end() int(m @Match) group(n int) string?Dependencies: strings
hash — Hash Function Interfaces
Section titled “hash — Hash Function Interfaces”Purpose: Non-cryptographic hash functions (FNV, xxhash) for hash maps and checksums.
Key types and functions:
Hash32 interface — sum32() u32Hash64 interface — sum64() u64
fnv32() Hash32fnv64() Hash64xxhash64() Hash64Dependencies: None
compress/gzip — Gzip Compression
Section titled “compress/gzip — Gzip Compression”Purpose: Gzip compression and decompression (RFC 1952).
Key types and functions:
Reader struct — decompression reader (implements io.Reader)Writer struct — compression writer (implements io.WriteCloser)
new_reader(r io.Reader) !Readernew_writer(w io.Writer) Writernew_writer_level(w io.Writer, level int) WriterDependencies: io, compress/flate
compress/flate — DEFLATE Compression
Section titled “compress/flate — DEFLATE Compression”Purpose: Raw DEFLATE compression/decompression (RFC 1951). Foundation for gzip and zip.
Key types and functions:
Reader struct — implements io.ReaderWriter struct — implements io.WriteCloser
new_reader(r io.Reader) Readernew_writer(w io.Writer) Writernew_writer_level(w io.Writer, level int) WriterDependencies: io
compress/zlib — Zlib Compression
Section titled “compress/zlib — Zlib Compression”Purpose: Zlib format compression/decompression (RFC 1950).
Key types and functions:
Reader struct — implements io.ReaderWriter struct — implements io.WriteCloser
new_reader(r io.Reader) !Readernew_writer(w io.Writer) WriterDependencies: io, compress/flate
archive/tar — Tar Archives
Section titled “archive/tar — Tar Archives”Purpose: Read and write tar archives.
Key types and functions:
Reader struct — tar archive readerWriter struct — tar archive writerHeader struct — file header (name, size, mode, mod_time)
new_reader(r io.Reader) Readernew_writer(w io.Writer) Writer(r &Reader) next() !Header?(r &Reader) read(buf []byte) !int(w &Writer) write_header(hdr @Header) !(w &Writer) write(data []byte) !int(w &Writer) close() !Dependencies: io, os, time
archive/zip — Zip Archives
Section titled “archive/zip — Zip Archives”Purpose: Read and write zip archives.
Key types and functions:
Reader struct — zip archive readerWriter struct — zip archive writerFile struct — file within archive
open_reader(path string) !Reader(r @Reader) files() []File(f &File) open() !io.ReadClosernew_writer(w io.Writer) Writer(w &Writer) create(name string) !io.Writer(w &Writer) close() !Dependencies: io, os, compress/flate, time
bufio — Buffered I/O Convenience
Section titled “bufio — Buffered I/O Convenience”Purpose: Scanner for line-by-line or token-by-token reading. Higher-level than io.BufferedReader.
Key types and functions:
Scanner struct — read input by lines or tokensSplitFunc type — custom tokenizer function
new_scanner(r io.Reader) Scanner(s &Scanner) scan() bool(s &Scanner) text() string(s &Scanner) bytes() []byte(s &Scanner) err() error?(s &Scanner) split(f SplitFunc)
scan_lines SplitFunc — split by newline (default)scan_words SplitFunc — split by whitespacescan_bytes SplitFunc — split by byteDependencies: io, bytes
flag — Command-Line Flag Parsing
Section titled “flag — Command-Line Flag Parsing”Purpose: Parse command-line flags and arguments with subcommand support.
Key types and functions:
FlagSet struct — set of defined flagsFlagError sum type — .undefinedFlag | .invalidValue | .helpRequested | .missingRequired | .unknownCommandCommand struct — subcommand with its own flag setFlagInfo struct — metadata about a defined flag
new(name string) FlagSetnew_with_description(name, description string) FlagSet
// Flag definition (with defaults)(fs &FlagSet) string_flag(name, default, usage string) &string(fs &FlagSet) int_flag(name string, default int, usage string) &int(fs &FlagSet) bool_flag(name string, default bool, usage string) &bool(fs &FlagSet) float_flag(name string, default f64, usage string) &f64(fs &FlagSet) duration_flag(name string, default time.Duration, usage string) &time.Duration
// Required flags (no default, parse fails if missing)(fs &FlagSet) string_flag_required(name, usage string) &string(fs &FlagSet) int_flag_required(name, usage string) &int(fs &FlagSet) bool_flag_required(name, usage string) &bool(fs &FlagSet) float_flag_required(name, usage string) &f64(fs &FlagSet) duration_flag_required(name, usage string) &time.Duration
// Subcommands(fs &FlagSet) add_command(name, description string) &FlagSet(fs @FlagSet) command() &FlagSet? — matched subcommand after parse(fs @FlagSet) command_name() string — matched subcommand name
// Parsing and inspection(fs &FlagSet) parse(args []string) !(fs &FlagSet) set_description(desc string)(fs @FlagSet) args() []string — non-flag arguments(fs @FlagSet) n_arg() int(fs @FlagSet) arg(i int) string(fs @FlagSet) n_flag() int(fs @FlagSet) is_set(name string) bool(fs @FlagSet) usage() — print usage to stderr(fs @FlagSet) help_text() string — return usage as string(fs @FlagSet) flag_info(name string) FlagInfo?(fs @FlagSet) visit_flags(visitor fun(info FlagInfo))
// Package-level (default FlagSet)string_flag(name, default, usage) &stringint_flag(name, default, usage) &intbool_flag(name, default, usage) &boolfloat_flag(name, default, usage) &f64duration_flag(name, default, usage) &time.Durationstring_flag_required(name, usage) &stringint_flag_required(name, usage) &intbool_flag_required(name, usage) &boolfloat_flag_required(name, usage) &f64duration_flag_required(name, usage) &time.Durationadd_command(name, description) &FlagSetparse() !args() []stringusage()command() &FlagSet?command_name() stringDependencies: os, fmt, strconv, time
cli — Command-Line Application Framework
Section titled “cli — Command-Line Application Framework”Purpose: Build CLI applications with command trees, lifecycle hooks, argument validation, and auto-generated help. Composes the flag package for flag parsing while providing higher-level orchestration — analogous to Cobra in Go.
Key types and functions:
CliError sum type — .unknownCommand(string) | .invalidArgs(string) | .flagError(string) | .silentErrorRunFunc type — fun(cmd &Command, args []string) !ArgsValidator type — fun(cmd @Command, args []string) !Command struct — CLI command with flags, subcommands, and hooks
new(name string) Command
// Builder-style configuration (return &Command for chaining)(c &Command) set_short(desc string) &Command(c &Command) set_long(desc string) &Command(c &Command) set_example(example string) &Command(c &Command) set_version(version string) &Command(c &Command) set_deprecated(msg string) &Command(c &Command) set_hidden(hidden bool) &Command(c &Command) set_run(f RunFunc) &Command(c &Command) set_pre_run(f RunFunc) &Command(c &Command) set_post_run(f RunFunc) &Command(c &Command) set_args_validator(v ArgsValidator) &Command(c &Command) set_silence_errors(v bool) &Command(c &Command) set_silence_usage(v bool) &Command
// Command tree(c &Command) add_command(sub &Command)(c &Command) add_commands(subs ...&Command)(c &Command) remove_command(name string)(c @Command) has_subcommands() bool(c @Command) parent() &Command?(c @Command) root() &Command(c @Command) find_command(args []string) struct { cmd &Command, remaining []string }
// Flag access (local + persistent + inherited)(c &Command) flags() &flag.FlagSet(c &Command) persistent_flags() &flag.FlagSet(c @Command) inherited_flags() []flag.FlagInfo(c @Command) all_flags(visitor fun(info flag.FlagInfo))(c @Command) has_flags() bool(c @Command) has_persistent_flags() bool(c @Command) has_inherited_flags() bool
// Execution(c &Command) execute() ! — main entry point, parses os.args()(c &Command) execute_with(args []string) ! — testable variant
// Help and usage(c @Command) help()(c @Command) help_text() string(c @Command) usage()(c @Command) usage_text() string(c @Command) full_name() string(c @Command) name_and_aliases() string(c @Command) is_runnable() bool
// Built-in argument validatorsno_args() ArgsValidatorexact_args(n int) ArgsValidatormin_args(n int) ArgsValidatormax_args(n int) ArgsValidatorrange_args(min, max int) ArgsValidatorarbitrary_args() ArgsValidatorvalid_args(valid []string) ArgsValidator
// Package-level (default app)add_command(sub &Command)execute() !set_version(version string)Dependencies: flag, fmt, os, strings
context — Cancellation and Deadlines
Section titled “context — Cancellation and Deadlines”Purpose: Carry deadlines, cancellation signals, and request-scoped values across API boundaries and between green threads.
Key types and functions:
Context interface — deadline() Time?, done() chan[void], err() error?, value(key string) any?
background() Context — empty, never-cancelled root contexttodo() Context — placeholder for undecided contextswith_cancel(parent Context) (Context, CancelFunc)with_timeout(parent Context, timeout Duration) (Context, CancelFunc)with_deadline(parent Context, deadline Time) (Context, CancelFunc)with_value(parent Context, key string, val any) Context
CancelFunc type — fun()Dependencies: time
metrics — Application Metrics (VictoriaMetrics-style)
Section titled “metrics — Application Metrics (VictoriaMetrics-style)”Purpose: Lightweight, high-performance application metrics with Prometheus exposition format. Ported from VictoriaMetrics/metrics — the same zero-allocation, lock-free design philosophy. Counters, gauges, histograms, and summaries with automatic Prometheus-compatible output. No separate exposition library needed.
Key types and functions:
// ─── Set (metric registry) ───────────────────────────────────────
Set struct — collection of named metrics (concurrent-safe)
new_set() Setdefault_set() &Set — package-level default registry
(s &Set) write_prometheus(w io.Writer) ! — write all metrics in Prometheus exposition format(s &Set) unregister(name string) bool(s &Set) unregister_all()(s &Set) list_metric_names() []string(s &Set) register_metrics_writer(f fun(w io.Writer)) — custom metrics callback
// Register a Set for inclusion in global write_prometheus outputregister_set(s &Set)unregister_set(s &Set)
// ─── Counter ─────────────────────────────────────────────────────
Counter struct — monotonically increasing integer counter (atomic)
// Create via Set or package-level (default set)(s &Set) new_counter(name string) &Counter(s &Set) get_or_create_counter(name string) &Counternew_counter(name string) &Counterget_or_create_counter(name string) &Counter
(c &Counter) inc()(c &Counter) dec()(c &Counter) add(n int)(c &Counter) set(n int)(c @Counter) get() int
// ─── FloatCounter ────────────────────────────────────────────────
FloatCounter struct — monotonically increasing float counter (atomic)
(s &Set) new_float_counter(name string) &FloatCounter(s &Set) get_or_create_float_counter(name string) &FloatCounternew_float_counter(name string) &FloatCounterget_or_create_float_counter(name string) &FloatCounter
(c &FloatCounter) add(n f64)(c @FloatCounter) get() f64
// ─── Gauge ───────────────────────────────────────────────────────
Gauge struct — float64 value that can go up and down (atomic)
// Optional callback: if provided, gauge value comes from calling f()(s &Set) new_gauge(name string, f fun() f64) &Gauge(s &Set) get_or_create_gauge(name string, f fun() f64) &Gaugenew_gauge(name string, f fun() f64) &Gaugeget_or_create_gauge(name string, f fun() f64) &Gauge
(g &Gauge) set(v f64)(g &Gauge) inc()(g &Gauge) dec()(g &Gauge) add(v f64)(g @Gauge) get() f64
// ─── Histogram ───────────────────────────────────────────────────
Histogram struct — value distribution with auto-generated log-scale buckets (VictoriaMetrics vmrange-style, better compression than cumulative)
(s &Set) new_histogram(name string) &Histogram(s &Set) get_or_create_histogram(name string) &Histogramnew_histogram(name string) &Histogramget_or_create_histogram(name string) &Histogram
(h &Histogram) update(v f64)(h &Histogram) update_duration(start time.Time) — record elapsed time since start(h &Histogram) reset()(h &Histogram) merge(src @Histogram)(h @Histogram) visit_non_zero_buckets(f fun(vmrange string, count int))
// Standard Prometheus histogram (cumulative buckets) when neededPrometheusHistogram struct — traditional cumulative bucket histogram
(s &Set) new_prometheus_histogram(name string) &PrometheusHistogram(s &Set) new_prometheus_histogram_ext(name string, upper_bounds []f64) &PrometheusHistogram(s &Set) get_or_create_prometheus_histogram(name string) &PrometheusHistogram
(ph &PrometheusHistogram) update(v f64)(ph &PrometheusHistogram) update_duration(start time.Time)
// ─── Summary ─────────────────────────────────────────────────────
Summary struct — streaming quantile estimation over a time window
(s &Set) new_summary(name string) &Summary(s &Set) new_summary_ext(name string, window time.Duration, quantiles []f64) &Summary(s &Set) get_or_create_summary(name string) &Summary(s &Set) get_or_create_summary_ext(name string, window time.Duration, quantiles []f64) &Summarynew_summary(name string) &Summarynew_summary_ext(name string, window time.Duration, quantiles []f64) &Summaryget_or_create_summary(name string) &Summaryget_or_create_summary_ext(name string, window time.Duration, quantiles []f64) &Summary
(sm &Summary) update(v f64)(sm &Summary) update_duration(start time.Time)
// Default quantiles: 0.5, 0.9, 0.97, 0.99, 1.0// Default window: 5 minutes
// ─── Global exposition ───────────────────────────────────────────
write_prometheus(w io.Writer, expose_process_metrics bool) !write_process_metrics(w io.Writer) ! — memory, CPU, FDs, green thread count
// Metric names follow Prometheus conventions:// "http_requests_total"// "http_request_duration_seconds{method=\"GET\",path=\"/api\"}"// Labels are embedded in the metric name string, not as separate args
// ─── Push gateway support ────────────────────────────────────────
type PushOptions struct { extra_labels string — "key=value,key2=value2" appended to all metrics headers map[string]string — custom HTTP headers disable_compression bool}
init_push(url string, interval time.Duration, extra_labels string) !init_push_with_options(ctx context.Context, url string, interval time.Duration, opts @PushOptions) !push_metrics(url string, extra_labels string) !
(s &Set) init_push(url string, interval time.Duration, extra_labels string) !(s &Set) push_metrics(url string, extra_labels string) !
// ─── Metadata control ────────────────────────────────────────────
expose_metadata(enabled bool) — toggle TYPE/HELP lines in Prometheus output
// ─── Write helpers (for custom metrics writers) ──────────────────
write_counter_int(w io.Writer, name string, value int) !write_counter_float(w io.Writer, name string, value f64) !write_gauge_int(w io.Writer, name string, value int) !write_gauge_float(w io.Writer, name string, value f64) !Design notes:
- Ported from VictoriaMetrics/metrics — same philosophy: metric names are strings with embedded labels, no label-builder API, zero-allocation hot paths
- All metric types are concurrent-safe using atomic operations (no mutexes on the hot path)
- Histogram uses VictoriaMetrics vmrange-style log-scale buckets by default (better compression, no cumulative overhead), with traditional Prometheus cumulative histogram available via
PrometheusHistogram - Summary uses a sliding time window for quantile estimation
get_or_create_*is the primary API — idempotent, safe to call from any green thread- Labels embedded in name strings:
get_or_create_counter("http_requests_total{method=\"GET\"}")— simple, no type-level label machinery needed - Process metrics include: memory allocation stats (from generational allocator), green thread count, OS thread count, FD count, CPU time
Example:
package main
use "metrics"use "time"use "net/http"
pub fun main() { // Counters requests := metrics.get_or_create_counter("http_requests_total") errors := metrics.get_or_create_counter("http_errors_total")
// Histogram for latency duration := metrics.get_or_create_histogram("http_request_duration_seconds")
// Gauge with callback metrics.get_or_create_gauge("goroutines_count", fun() f64 { return f64(runtime.num_goroutine()) })
r := http.new_router()
// Expose /metrics endpoint r.get("/metrics", fun(w &http.ResponseWriter, req @http.Request) { metrics.write_prometheus(w, true) })
r.get("/api/data", fun(w &http.ResponseWriter, req @http.Request) { start := time.now() defer duration.update_duration(start)
requests.inc() // ... handle request ... })
http.listen_and_serve(":8080", r)}Dependencies: io, time, sync, context, net/http (for push only)
url — URL Parsing
Section titled “url — URL Parsing”Purpose: Parse, construct, and escape URLs.
Key types and functions:
Url struct — parsed URL scheme, host, port, path, raw_query, fragment string user UserInfo?
parse(raw string) !Url(u @Url) string() string(u @Url) query() map[string][]stringpath_escape(s string) stringpath_unescape(s string) !stringquery_escape(s string) stringquery_unescape(s string) !stringDependencies: strings, strconv
mime — MIME Types
Section titled “mime — MIME Types”Purpose: MIME type detection and file extension mapping.
Key types and functions:
type_by_extension(ext string) stringextension_by_type(mime_type string) string?parse_media_type(s string) !(string, map[string]string)format_media_type(mime_type string, params map[string]string) stringDependencies: strings
unicode — Unicode Tables and Properties
Section titled “unicode — Unicode Tables and Properties”Purpose: Unicode character classification and properties.
Key types and functions:
is_letter(r rune) boolis_digit(r rune) boolis_upper(r rune) boolis_lower(r rune) boolis_space(r rune) boolis_punct(r rune) boolis_control(r rune) boolis_graphic(r rune) boolis_print(r rune) boolto_upper(r rune) runeto_lower(r rune) runeto_title(r rune) runeDependencies: None
unicode/utf8 — UTF-8 Encoding
Section titled “unicode/utf8 — UTF-8 Encoding”Purpose: UTF-8 encoding/decoding, validation, and rune manipulation.
Key types and functions:
encode(r rune) []bytedecode(b []byte) (rune, int)decode_string(s string, pos int) (rune, int)valid(b []byte) boolvalid_string(s string) boolrune_count(b []byte) intrune_count_string(s string) intrune_len(r rune) intfull_rune(b []byte) boolDependencies: None
os/exec — Running External Processes
Section titled “os/exec — Running External Processes”Purpose: Run external commands and capture their output.
Key types and functions:
Cmd struct — external command configurationProcessError sum type — .notFound | .permissionDenied | .exitError(int)
command(name string, args ...string) Cmd(c &Cmd) run() !(c &Cmd) output() ![]byte(c &Cmd) combined_output() ![]byte(c &Cmd) start() !(c &Cmd) wait() !(c &Cmd) stdin_pipe() !io.WriteCloser(c &Cmd) stdout_pipe() !io.ReadCloser(c &Cmd) stderr_pipe() !io.ReadCloserDependencies: os, io, bytes
os/signal — OS Signal Handling
Section titled “os/signal — OS Signal Handling”Purpose: Receive and handle OS signals (SIGINT, SIGTERM, etc.) via channels.
Key types and functions:
Signal sum type — .interrupt | .terminate | .hangup | .usr1 | .usr2 | .pipe
notify(c chan[Signal], signals ...Signal) — relay signals to channelstop(c chan[Signal]) — stop relayingignore(signals ...Signal) — ignore signalsreset(signals ...Signal) — reset to default behaviorDependencies: os
encoding/toml — TOML Parsing and Serialization
Section titled “encoding/toml — TOML Parsing and Serialization”Purpose: Parse and generate TOML configuration files. Required by the package manager (run.toml).
Key types and functions:
TomlError sum type — .syntax_error | .type_mismatch | .duplicate_key | .invalid_datetime | .mixed_arrayValue sum type — .string | .int | .float | .bool | .datetime | .array | .table
parse(data string) !Value — parse TOML string to Value treeparse_file(path string) !Value — read and parse TOML filemarshal(value any) !string — encode to TOML stringunmarshal(data string, target &any) ! — decode into target
(v Value) get(key string) Value? — lookup by key(v Value) get_string(key string) string? — get string value(v Value) get_int(key string) int? — get integer value(v Value) get_bool(key string) bool? — get boolean value(v Value) get_table(key string) Value? — get table value(v Value) get_array(key string) []Value? — get array value
Encoder struct — streaming TOML encoderDecoder struct — streaming TOML decoderDependencies: io
Status: Stub exists
encoding/yaml — YAML Parsing and Serialization
Section titled “encoding/yaml — YAML Parsing and Serialization”Purpose: Parse and generate YAML, the most common configuration format (Kubernetes, CI/CD, Docker Compose).
Key types and functions:
YamlError sum type — .syntax_error | .duplicate_key | .invalid_anchor | .circular_reference | .type_mismatch | .unsupported_tagValue sum type — .null | .bool | .int | .float | .string | .sequence | .mapping
marshal(value any) ![]byte — encode to YAML bytesunmarshal(data []byte, target &any) ! — decode YAML bytesmarshal_string(value any) !string — encode to YAML stringparse(data []byte) !Value — parse to Value treeparse_string(s string) !Value — parse string to Value tree
(v Value) get(key string) Value? — lookup by key(v Value) index(i int) Value? — lookup by index in sequence(v Value) as_string() string? — extract string value(v Value) as_int() int? — extract int value(v Value) as_float() f64? — extract float value(v Value) as_bool() bool? — extract bool value(v Value) as_sequence() []Value? — extract sequence(v Value) as_mapping() map[string]Value? — extract mapping
Encoder struct — streaming YAML encoderDecoder struct — streaming YAML decoder (multi-document)Dependencies: io
Status: Stub exists
encoding/xml — XML Parsing and Serialization
Section titled “encoding/xml — XML Parsing and Serialization”Purpose: XML encoding/decoding with streaming token-based and tree-based APIs.
Key types and functions:
XmlError sum type — .syntax_error | .unexpected_eof | .invalid_character | .unclosed_tag | .mismatched_tagToken sum type — .start_element | .end_element | .char_data | .comment | .proc_inst | .directive
Name struct — local string, space stringAttr struct — name Name, value stringStartElement struct — name Name, attr []AttrEndElement struct — name NameProcInst struct — target string, inst string
marshal(v any) ![]byte — encode to XMLmarshal_indent(v any, prefix, indent string) ![]byteunmarshal(data []byte, target &any) ! — decode XML
Encoder struct — streaming XML encoderDecoder struct — streaming XML decoder(d Decoder) token() !Token? — read next token(d Decoder) decode(target &any) ! — decode element(d Decoder) skip() ! — skip current elementDependencies: io
Status: Stub exists
compress/zstd — Zstandard Compression
Section titled “compress/zstd — Zstandard Compression”Purpose: Modern, fast compression with better ratios than gzip at comparable speeds.
Key types and functions:
ZstdError sum type — .corrupt_input | .window_too_large | .dictionary_mismatch | .unexpected_eof
compress(data []byte) ![]byte — compress with default levelcompress_level(data []byte, level int) ![]byte — compress with specific level (1-19)decompress(data []byte) ![]byte — decompress
Reader struct — streaming decompressor (io.Reader + io.Closer)Writer struct — streaming compressor (io.Writer + io.Closer)new_reader(r io.Reader) !Readernew_writer(w io.Writer) Writernew_writer_level(w io.Writer, level int) !WriterDependencies: io
Status: Stub exists
io/fs — Virtual Filesystem Interface
Section titled “io/fs — Virtual Filesystem Interface”Purpose: Abstract filesystem interface for testable I/O, embedded files, and archive access.
Key types and functions:
FsError sum type — .not_found | .permission_denied | .not_directory | .invalid_pathFileMode sum type — .regular | .directory | .symlink | .socket | .pipe | .device
FS interface — open(name string) !FileFile interface — stat() !FileInfo, read(buf) !int, close() !ReadDirFS interface — FS + read_dir(name string) ![]DirEntryStatFS interface — FS + stat(name string) !FileInfoFileInfo interface — name, size, mode, mod_time, is_dirDirEntry interface — name, is_dir, type_mode, info
walk_dir(fsys FS, root string, fn fun(path, d, err))sub(fsys FS, dir string) !FSglob(fsys FS, pattern string) ![]stringread_file(fsys FS, name string) ![]bytevalid_path(name string) boolDependencies: io
Status: Stub exists
html — HTML Escaping
Section titled “html — HTML Escaping”Purpose: Security-critical HTML entity escaping and unescaping to prevent XSS attacks.
Key types and functions:
escape_string(s string) string — < > & " ' → entitiesunescape_string(s string) string — entities → charactersDependencies: None Status: Stub exists
text/template — Text Templating
Section titled “text/template — Text Templating”Purpose: Data-driven text templates with field access, conditionals, iteration, and pipelines.
Key types and functions:
TemplateError sum type — .parse_error | .exec_error | .undefined_variable | .undefined_function | .wrong_arg_count
Template struct — compiled template
new(name string) Templateparse(text string) !Templateparse_files(filenames ...string) !Templatemust(t Template) Template
(t Template) execute(wr io.Writer, data any) !(t Template) execute_string(data any) !string(t Template) name() stringDependencies: io
Status: Stub exists
hash/crc32 — CRC-32
Section titled “hash/crc32 — CRC-32”Purpose: CRC-32 checksum computation with IEEE, Castagnoli, and Koopman polynomials.
Key types and functions:
Table struct — precomputed polynomial table
make_table(poly int) Table — build table from polynomialnew(tab Table) hash.Hash32 — new Hash32 using tablechecksum(data []byte, tab Table) int — compute CRC-32checksum_ieee(data []byte) int — CRC-32 with IEEE polynomialupdate(crc int, tab Table, data []byte) int — update running CRCDependencies: hash
Status: Stub exists
hash/fnv — FNV Hash
Section titled “hash/fnv — FNV Hash”Purpose: FNV-1 and FNV-1a hash functions in 32, 64, and 128-bit variants.
Key types and functions:
new32() hash.Hash32 — FNV-1 32-bitnew32a() hash.Hash32 — FNV-1a 32-bitnew64() hash.Hash64 — FNV-1 64-bitnew64a() hash.Hash64 — FNV-1a 64-bitnew128() hash.Hash64 — FNV-1 128-bitnew128a() hash.Hash64 — FNV-1a 128-bitDependencies: hash
Status: Stub exists
crypto/subtle — Constant-Time Operations
Section titled “crypto/subtle — Constant-Time Operations”Purpose: Constant-time operations for avoiding timing side-channel attacks in cryptographic code.
Key types and functions:
constant_time_compare(a, b []byte) bool — constant-time byte comparisonconstant_time_eq(a, b int) bool — constant-time integer equalityconstant_time_select(v, a, b int) int — constant-time conditional selectconstant_time_copy(v int, dst, src []byte) — conditional copyxor_bytes(dst, a, b []byte) int — XOR byte slicesDependencies: None Status: Stub exists
P3 — Advanced/Specialized Packages
Section titled “P3 — Advanced/Specialized Packages”simd — SIMD Vector Operations
Section titled “simd — SIMD Vector Operations”Purpose: Compiler-recognized operations on Run’s first-class SIMD vector and
mask primitives. The simd namespace maps to runtime helpers and target
intrinsics, with scalar fallbacks when no fast path is available.
Key scalar and vector types:
// Scalar lane types used by SIMD indexingi8, i16, i32, f32, f64
// Built-in vector primitivesv4f32, v2f64, v4i32, v8i16, v16i8v8f32, v4f64, v8i32, v16i16, v32i8
// Built-in mask primitivesv2bool, v4bool, v8bool, v16bool, v32boolKey operations:
// Element-wise operators on matching vector typesv + wv - wv * wv / w
// Comparisons return the matching mask typev < wv <= wv > wv >= wv == wv != w
// Lane accesslane := v[i]v[i] = lane_value // mutable local/parameter only
// SIMD literal syntaxv4f32{ 1.0, 2.0, 3.0, 4.0 }Compiler-recognized simd.* builtins:
hadd(v) scalardot(a, b) scalarshuffle(v, idx0, ..., idxN) vector — one literal index per lane, all indices in rangemin(a, b) vectormax(a, b) vectorselect(mask, a, b) vector — mask lane count must match vector lane countload(ptr) vector — aligned load from @Vector or &Vectorload_unaligned(ptr) vector — unaligned load from @Vector or &Vectorstore(ptr, v) — aligned store through &Vectorwidth() int — 256 with AVX, 128 with SSE/NEON, otherwise 0sqrt(v) vector — element-wise square root (float vectors only)abs(v) vector — element-wise absolute value (float vectors only)floor(v) vector — element-wise floor (float vectors only)ceil(v) vector — element-wise ceiling (float vectors only)round(v) vector — element-wise round to nearest (float vectors only)fma(a, b, c) vector — fused multiply-add a*b+c (float vectors only)clamp(v, lo, hi) vector — element-wise clamp to [lo, hi]broadcast(T, scalar) vector — fill all lanes of vector type T with scalari32_to_f32(v) vector — convert v4i32/v8i32 to v4f32/v8f32f32_to_i32(v) vector — convert v4f32/v8f32 to v4i32/v8i32Notes:
simdis currently a compiler-recognized pseudo-package; it does not rely on ordinary package loading.unsafe.alignof(T)returns the natural SIMD alignment (16for 128-bit vectors,32for 256-bit vectors).
Dependencies: None (compiler-recognized namespace lowered to runtime helpers/intrinsics)
numa — NUMA-Aware Memory and Scheduling
Section titled “numa — NUMA-Aware Memory and Scheduling”Purpose: Topology discovery, NUMA-aware allocation, and thread/green-thread affinity. Allows programs to optimize for memory locality on multi-socket systems.
Key types and functions:
Node struct — NUMA node id int cpus []int memory_total int memory_free int
Topology struct — system NUMA topology nodes []Node distances [][]int
topology() Topology — discover system NUMA topologyavailable() bool — is NUMA actually present?node_count() int — number of NUMA nodescurrent_node() int — NUMA node of calling threadpreferred_node() int — preferred allocation node
// Memory placementAllocator struct — NUMA-aware allocatorlocal_alloc(size int) &byte — allocate on current nodenode_alloc(node int, size int) &byte — allocate on specific nodeinterleave_alloc(size int) &byte — interleave across nodes
// Affinitybind_thread(node int) ! — bind current OS thread to nodebind_green_thread(node int) ! — prefer scheduling on nodeset_memory_policy(policy Policy) !
Policy sum type — .local | .bind(node int) | .interleave | .preferred(node int)Dependencies: os, unsafe
asm — Inline Assembly Utilities
Section titled “asm — Inline Assembly Utilities”Purpose: Helpers for working with Run’s inline assembly blocks. Register constants, constraint helpers, and platform detection.
Key types and functions:
Arch sum type — .x86_64 | .aarch64 | .riscv64 | .wasm32arch() Arch — current target architecture
// Platform detection (compile-time constants)is_x86_64 boolis_aarch64 boolis_riscv64 boolis_wasm32 bool
// CPU feature detection (runtime)has_avx() boolhas_avx2() boolhas_avx512() boolhas_sse42() boolhas_neon() boolhas_sve() bool
// Memory barriersfence() — full memory fenceload_fence() — load-acquire fencestore_fence() — store-release fence
// Cache controlprefetch(addr &byte)cache_line_size() intflush_cache_line(addr &byte)Dependencies: unsafe
embed — Embed Files at Compile Time
Section titled “embed — Embed Files at Compile Time”Purpose: Embed file contents into the binary at compile time.
Key types and functions:
// Used via compiler directive// @embed("path/to/file") produces a []byte or string at compile time
File struct — embedded file name string data []byte
Dir struct — embedded directory tree (d @Dir) open(name string) !File (d @Dir) read_dir() []stringDependencies: None (compiler feature)
debug — Debugging Utilities
Section titled “debug — Debugging Utilities”Purpose: Stack traces, assertions, and diagnostic tools for development.
Key types and functions:
StackFrame struct — function, file, linestack_trace() []StackFrame — capture current stackprint_stack() — print stack to stderrassert(condition bool, msg string) — panic with message if falseunreachable(msg string) — panic with "unreachable" messagetodo(msg string) — panic with "not implemented" messagebreakpoint() — trigger debugger breakpointDependencies: fmt, os
runtime — Runtime Introspection
Section titled “runtime — Runtime Introspection”Purpose: Query and control the Run runtime: green thread count, memory stats, GC-free allocation stats, scheduler info.
Key types and functions:
MemStats struct — allocator statistics alloc_count int free_count int bytes_allocated int bytes_freed int generation_checks int generation_failures int
num_cpu() int — number of logical CPUsnum_goroutine() int — number of active green threadsgomaxprocs(n int) int — set/get OS thread count for schedulermem_stats() MemStats — memory allocator statisticsversion() string — Run version stringgc_disable() — disable generation checks (unsafe, for benchmarks)gc_enable() — re-enable generation checksyield() — yield current green thread to schedulerDependencies: None (compiler builtins)
Package Dependency Graph
Section titled “Package Dependency Graph” ┌──────────┐ │ unsafe │ └──────────┘ │ ┌────────────────────┼────────────────────┐ │ │ │┌───▼──┐ ┌────▼───┐ ┌────▼──┐│ io │ │ sync │ │ numa │└───┬──┘ └────────┘ └───────┘ │ ├──────────────┬──────────────┐ │ │ │┌───▼──┐ ┌───▼───┐ ┌───▼────┐│ os │ │ bytes │ │ fmt │└───┬──┘ └───┬───┘ └───┬────┘ │ │ │ ├─────────────┼─────────────┤ │ │ │┌───▼─────┐ ┌───▼────┐ ┌────▼───┐│strings │ │strconv │ │ time │└─────────┘ └────────┘ └────┬───┘ │ ┌─────────────────────────┤ │ │┌───▼──┐ ┌───▼──────┐│ log │ │ context │└──────┘ └──────────┘
┌─────────┐ ┌────────┐ ┌──────────┐ ┌───────────────┐│ net │───▶│net/http│───▶│net/http2 │───▶│ net/grpc │└─────────┘ └───┬────┘ └──────────┘ └───────┬───────┘ │ │ │ │ ▼ ▼ │ ┌────────────┐ ┌────────────────┐ │ │encoding/* │ │ encoding/proto │ │ └────────────┘ └────────────────┘ ▼ ┌─────────┐ │ metrics │◀── Prometheus exposition, push gateway └─────────┘
┌────────┐ ┌──────┐ ┌──────┐│ math │ │ simd │ │ asm │└───┬────┘ └──────┘ └──────┘ │┌───▼───────┐│ math/rand │└───────────┘Complete Package List
Section titled “Complete Package List”| Package | Purpose | Priority | Dependencies |
|---|---|---|---|
io | I/O interfaces, buffered I/O, utilities | P0 | — |
fmt | Formatting and printing | P0 | io |
os | Files, processes, env, paths | P0 | io |
errors | Error creation, wrapping, inspection | P0 | — |
strings | String manipulation | P1 | — |
bytes | Byte slice utilities, Buffer | P1 | io |
math | Math functions and constants | P1 | — |
math/rand | Pseudo-random numbers | P1 | math |
math/bits | Bit counting, rotation, extended arithmetic | P1 | — |
testing | Test framework and assertions | P1 | fmt, strings |
time | Time, duration, timers | P1 | — |
log | Structured logging | P1 | io, time, fmt |
strconv | String/number conversions | P1 | strings |
unicode | Unicode character properties | P1 | — |
unicode/utf8 | UTF-8 encoding/decoding | P1 | — |
sort | Sorting algorithms | P1 | — |
bufio | Scanner, line-by-line reading | P1 | io, bytes |
iter | Iterator protocol and combinators | P1 | — |
slices | Slice utilities | P1 | — |
maps | Map utilities | P1 | — |
cmp | Comparison and ordering | P1 | — |
path | OS-independent path manipulation | P1 | — |
net | TCP/UDP, DNS | P2 | io, time, os |
net/http | HTTP client and server | P2 | net, io, fmt, strings, time, context, metrics |
net/http2 | HTTP/2 protocol | P2 | net, net/http, io, sync, crypto/tls |
net/grpc | gRPC client and server | P2 | net, net/http2, encoding/proto, context, time, sync, crypto/tls |
encoding/proto | Protocol Buffers | P2 | bytes, io |
encoding/json | JSON encode/decode | P2 | io, strings, bytes, fmt |
encoding/csv | CSV read/write | P2 | io, strings, bytes |
encoding/base64 | Base64 encode/decode | P2 | — |
encoding/hex | Hex encode/decode | P2 | bytes |
encoding/toml | TOML parsing and serialization | P2 | io |
encoding/yaml | YAML parsing and serialization | P2 | io |
encoding/xml | XML parsing and serialization | P2 | io |
crypto | Hash/AEAD/signing interfaces, recommended defaults | P2 | io |
crypto/sha256 | SHA-256 | P2 | crypto |
crypto/sha512 | SHA-512 | P2 | crypto |
crypto/hmac | HMAC | P2 | crypto |
crypto/aes | AES block cipher | P2 | crypto |
crypto/tls | TLS connections | P2 | crypto/*, net, io |
crypto/subtle | Constant-time operations | P2 | — |
sync | Mutex, RwMutex, WaitGroup, Atomic | P2 | — |
unsafe | Raw pointers, type layout | P2 | — |
context | Cancellation and deadlines | P2 | time |
metrics | Application metrics, Prometheus exposition | P2 | io, time, sync, context |
url | URL parsing and escaping | P2 | strings, strconv |
mime | MIME types | P2 | strings |
flag | CLI flag parsing | P2 | os, fmt, strconv |
cli | CLI application framework | P3 | flag, fmt, os, strings |
os/exec | Run external commands | P2 | os, io, bytes |
os/signal | OS signal handling | P2 | os |
regex | Regular expressions | P2 | strings |
hash | Non-crypto hash functions | P2 | — |
hash/crc32 | CRC-32 checksums | P2 | hash |
hash/fnv | FNV hash functions | P2 | hash |
compress/flate | DEFLATE compression | P2 | io |
compress/gzip | Gzip compression | P2 | io, compress/flate |
compress/zlib | Zlib compression | P2 | io, compress/flate |
compress/zstd | Zstandard compression | P2 | io |
archive/tar | Tar archives | P2 | io, os, time |
archive/zip | Zip archives | P2 | io, os, compress/flate, time |
io/fs | Virtual filesystem interface | P2 | io |
html | HTML escaping | P2 | — |
text/template | Text templating | P2 | io |
simd | SIMD vector operations | P3 | — |
numa | NUMA topology and allocation | P3 | os, unsafe |
asm | Assembly utilities, CPU features | P3 | unsafe |
embed | Compile-time file embedding | P3 | — |
debug | Stack traces, assertions | P3 | fmt, os |
runtime | Runtime introspection | P3 | — |
Total: 67 packages