Go SDK for writing switchyard Carport drivers.
package main
import (
"context"
"log"
entityv1 "github.com/fdatoo/switchyard/gen/switchyard/entity/v1"
"github.com/fdatoo/switchyard-driverkit/driver"
)
func main() {
d := driver.New("my-driver", "0.1.0")
d.AddEntity("light.main", driver.EntitySpec{
EntityType: "light",
FriendlyName: "Main Light",
Capabilities: []string{"turn_on", "turn_off"},
})
d.OnCapability("light.main", "turn_on", func(ctx context.Context, id string, args map[string]string) (*entityv1.Attributes, error) {
return &entityv1.Attributes{Kind: &entityv1.Attributes_Light{Light: &entityv1.Light{On: true}}}, nil
})
log.Fatal(d.Run(context.Background()))
}Point switchyardd at the compiled binary via drivers.toml, and it will spawn and supervise your driver automatically.
go get github.com/fdatoo/switchyard-driverkit@latest| Package | Purpose |
|---|---|
driver |
High-level SDK — start here |
protocol |
Low-level Carport protocol — for power users |
drivertest |
Test helpers: in-process harness and CLI |
go install github.com/fdatoo/switchyard-driverkit/drivertest/cmd/drivertest@latest
drivertest run ./my-driver --scenario happy-path| driverkit | Carport protocol | switchyard |
|---|---|---|
| v0.x | v1alpha1 | v0.1.1+ |