Geblang examples

A few short, real programs that show the shape of the language. Every snippet here runs as written.

A command-line tool

Read arguments, ship one binary. No runtime for your users to install.

import io;
import sys;
let args = sys.args();
let name = args.length() > 0 ? args[0] : "world";

io.println("Hello, ${name}!");

An HTTP endpoint

A typed handler over the standard library's server. Each request runs on its own goroutine.

import http;

func handle(Request req): Response {
    return http.response("Hello from ${req.path}");
}

let server = http.listen(":8080", handle);

JSON onto a typed class

Deserialize JSON straight onto your own class with json.parseAs. No manual unpacking, no untyped dictionaries to thread around.

import io;
import json;

class Person {
    string name;
    int age;

    func Person(string name, int age) {
        this.name = name;
        this.age = age;
    }
}

let p = json.parseAs('{"name": "Mara", "age": 34}', Person);
io.println("${p.name} is ${p.age}");

Work in parallel

Start tasks on goroutines and wait for the batch together.

import io;
import async;

async func fetch(string name): string {
    await async.sleep(50);
    return "${name} ready";
}

let results = await async.all([fetch("users"), fetch("orders"), fetch("stats")]);
for (r in results) {
    io.println(r);
}

More to read

The repository ships a directory of runnable example programs, and the full language and standard-library reference lives in the online manual.