Skip to main content
Version: 0.15.0

An interface client

An interface client is anything that reaches an application from outside it — a panel, a browser's back end, a command-line tool — and it reaches it through a channel the description declares. It speaks the interface contract, and nothing it holds gives it administrative reach.

One contract, many interfaces — your client and ours, the same way in
A managed interfaceAn attached client
started bythe Core, as a unit of kind interfacewhoever runs it
finds its channelin YOKE_SOCKET, which the Core hands itfrom the instance's name and the channel's
examplea device's own panelthe tool on this page

Both attach the same way and are arbitrated the same way (attaching, arbitration).

The program​

The Go family's interface library is the package iface of the module github.com/yoke-project/yoke-sdk-go, the same module a Plugin in Go uses. This client asks one unit one question, so it serves for both Plugins of the example.

mkdir ask && cd ask
go mod init example.com/ask
go get github.com/yoke-project/yoke-sdk-go@latest
main.go
// Command ask is an interface client: it attaches to a channel of a running instance, asks one unit one
// question, and prints the answer.
package main

import (
"context"
"fmt"
"os"
"time"

"github.com/yoke-project/yoke-sdk-go/iface"
)

func main() {
if len(os.Args) != 5 && len(os.Args) != 6 {
fmt.Fprintln(os.Stderr, "usage: ask <instance> <channel> <unit> <question> [<payload>]")
os.Exit(2)
}
instance, channel, unit, question := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
var payload []byte
if len(os.Args) == 6 {
payload = []byte(os.Args[5])
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// In an application instance a channel's socket derives from the instance's name.
address, err := iface.Application(instance, channel, os.Getenv)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
a, err := iface.Attach(ctx, address)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
defer a.Close()
answer, err := a.Ask(ctx, unit, question, payload)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
fmt.Println(string(answer))
}
go mod tidy
CGO_ENABLED=0 go build -o ask .
CallWhat it does
iface.Applicationthe channel's socket in an application instance; iface.Service is the service form's, iface.Managed a managed interface's
iface.Attachattaches, and waits for the opening: what the channel may address and observe — attaching
a.Askasks a unit a question and returns its answer; Command, Read, Subscribe and the stream calls are the other operations — the operations
a.Closeends the attachment in order

The library never retries and never reconnects: an attachment that ended has ended, and a client that wants another attaches again (the interface library).

The channel it attaches to​

A channel is declared in the description, with its transport and how many clients it holds at once. This client needs one on the local socket, local; a browser would need http+ws (channels, the projections). The project declared one, cli, and running it attaches this client to it: ./ask <instance> cli system-info system.info.

In another language​

FamilyA client imports
Goiface, in github.com/yoke-project/yoke-sdk-go
Rustyoke_sdk::interface
Pythonyoke_sdk.interface
Cyoke/interface.h
C++yoke/interface.hpp

yoke-reference holds clients written with four of them: a terminal client in Rust and in Python, and an instrument's panel in C++ with Qt and in C with LVGL.