Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Standard library

Goblin's standard library provides modules for common program boundaries: files and paths, environment variables, external commands, time, data formats, digests, compression and archives, networking, random values, and mathematics. Import a module at module scope, then access its members with dot notation.

import "json"
import "fs"

var cwd = fs.cwd()
var text = json.encode({"cwd": String(cwd)})
print(text)

The standard library is separate from Goblin's built-in functions and types. For example, print(), eprint(), range(), Int(), List(), Dict(), and Chan() are available without an import. Import a module only when its capabilities are needed.

Modules

ModuleMain purposeStart with
jsonJSON text to values and backencode(), decode()
fsFiles, directories and path namesread(), write(), Path()
osArguments, environment, standard streams, exitargs, env, stdin, exit()
cliCommand-line arguments, options, help and usage errorsparse(), Option(), Flag(), Command()
execRun other programsrun(), capture(), start()
timeInstants, the clock, time zones, sleepingnow(), parse(), Time(), sleep()
randRandom choices, secure bytes and ids, reproducible on requestchoice(), int(), bytes(), uuid(), Rand()
mathFloat functions, constants and basic statisticsPI, sqrt(), round(), mean()
httpHTTP client: messages, requests, sessions, uploads, streamed bodiesget(), request(), send(), Request(), Client()
regexSearch and rewrite text by patternfind(), find_all(), replace(), split()
urlTake a URL apart, escape its parts, change its queryparse(), encode_query(), decode_query(), query_values()
csvCSV text to rows and backdecode(), decode_dicts(), encode(), read_rows()
hashDigests of data: checksums and HMAC signaturessha256(), hmac()
base64Bytes as Base64 text and backencode(), decode()
gzipGzip data, in memory and as files of any sizecompress(), decompress(), open(), read_lines()
zipZip archives: list, read one member, unpack safely, packextract(), open(), create()
tarTar archives, plain or gzip-compressed, from files or streamsextract(), open(), create(), Reader()

Imports and errors

Standard-library module names are single words ("json", "fs") and never start with "./" or "../". Local source modules use a relative import such as "./modules/greeter"; those are documented in Modules and imports because they use the same import syntax.

Most standard-library operations that touch the outside world can fail. JSON parsing may raise ParseError, a missing file may raise an I/O-related error, and HTTP requests may fail. Use try/catch around work that your program can recover from; see Errors.

Choosing a module

Use json whenever a program boundary expects JSON rather than trying to build JSON text manually. Prefer fs for simple whole-file reads and writes, and use its open() function when a file object is needed. Use fs.cwd() or fs.home() instead of assuming a current directory. Use time.sleep() only for intentional delays, and use Chan plus spawn() for communication between concurrent Goblin functions.

Each module has its own chapter in this section, with a focused API reference and example.

Reading API signatures

Examples and tables use name(required, optional=value) to show argument order and defaults. Square brackets mean an argument may be omitted, as in Chan([size]). They do not promise that named arguments are accepted: a function's chapter calls out positional-only APIs where that matters.

Unless a chapter says otherwise, a function that touches files, the operating system, or the network can raise an error value. Wrap the smallest useful boundary in try/catch, then add context or recover deliberately.