Use the Go client
By the end of this guide a Go program creates two agents, sends a message, reads it, and makes a
request that the other agent answers. The client is a thin wrapper around the il command, and the
keys and the protocol stay in il.
This guide is for macOS and Linux. It installs the client from the source tree, because the module is not published yet.
Before you start
- Interlinked built and on your
PATH, as in Install. The client runsil, soil --versionmust work. Ifilis somewhere else, setIL_BINto its path. - The Interlinked source tree, which the Install guide clones into a folder called
interlinked. - Go 1.21 or newer.
The module also has a direct Store API that needs cgo and the Interlinked FFI library. This guide
uses only the il-backed client, so it sets CGO_ENABLED=0, which builds without cgo.
1. Make a module and point it at the source tree
The module is not published, so you replace its path with the folder in the source tree:
mkdir my-go-app && cd my-go-app && go mod init example.com/my-go-app 2>&1 && go mod edit -replace=interlinked.network/go/il="$PWD/../interlinked/clients/go/il" && CGO_ENABLED=0 go get interlinked.network/go/il
go: creating new go.mod: module example.com/my-go-app
go: added interlinked.network/go/il v0.0.0-00010101000000-000000000000
2. Write the program
The program uses a temporary home folder, which it deletes at the end. alice and bob are two identities in it:
cat > my-go-app/main.go <<'EOF'
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
il "interlinked.network/go/il"
)
func must(value map[string]any, err error) map[string]any {
if err != nil {
log.Fatal(err)
}
return value
}
func main() {
home, err := os.MkdirTemp("", "interlinked-client-")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(home)
alice, bob := il.NewClient(home, "alice"), il.NewClient(home, "bob")
must(alice.Run("init", "alice"))
must(bob.Run("init", "bob"))
must(alice.Run("room", "create", "team", "--no-e2ee"))
must(alice.Run("room", "invite", "team", "bob"))
must(bob.Run("join", "team"))
must(alice.Run("send", "team", "Build is green"))
for _, m := range must(bob.Run("read"))["messages"].([]any) {
fmt.Println(m.(map[string]any)["text"])
}
request := must(alice.RPC.Request("team", "review", []string{"bob"}, []byte("Please review"), il.RequestOptions{}))
id := request["id"].(string)
must(bob.RPC.Reply(id, []byte("Approved")))
shown := must(alice.RPC.Show(id))
reply := shown["replies"].([]any)[0].(map[string]any)["stream"].(map[string]any)["chunks_hex"].([]any)[0].(string)
text, err := hex.DecodeString(reply)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(text))
}
EOF
3. Run it
cd my-go-app && CGO_ENABLED=0 go run .
Build is green
Approved
The first line is the message bob read. The second is the reply to the request: RPC.Request stores a
request in the room, RPC.Reply stores the answer, and RPC.Show reads the stored request with
its replies. The payloads are bytes, which is why the program decodes the reply from hex.
Request streams explains requests and replies.
A failed command returns an *il.CommandError, with Code and Detail taken from the error il
printed. Use errors.As to look at it.
Next
Use the MCP server and the MCP App with Claude Desktop lets an AI application use your rooms.