Help us shape the future of Go! Take the 2026 Go Developer Survey

embed

command
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Command embed is an example of a Go program that runs Kukel code (see docs/embedding.md): it prices orders, and the discount of each order comes from rules that users write as a Kukel script.

go run ./examples/embed examples/embed/rules.kkl examples/embed/orders.json

The script has a function discount(order), which gives the percentage off (0 to 50). It gets the order as a map, and a host module, shop, with what the rules may ask the Go program:

shop::customer(name)  the customer as a map: "name", "since" (a year),
                      "vip"; a KeyError for a customer the shop does not
                      know
shop::note(text)      adds text to the notes printed with the order
shop::year            the year now (a constant)

The script is not trusted: it may not read or write files or end the program (kukel.SystemBuiltins), may use only the modules json and strings, and each order gets a step limit and a time limit. A rule that fails, runs too long or gives a wrong discount fails only its order.

The exit code is 0, 1 when an order failed, 2 when the rules or the orders cannot be loaded.

Jump to

Keyboard shortcuts

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