Write a plugin in Go

Extending loadr

The plugin model is open: implement a protocol in Go (or any language that builds a C-ABI shared object), declare its URL scheme, and loadr plugin install it. This demo drives a Go echo service through a custom plugin.

Browse all 52 demos 12 categories
Run it
$ loadr run examples/35-go-echo.yaml
examples/35-go-echo.yaml
# A protocol plugin written in Go, loaded over loadr's frozen C ABI.
#
# Like the c-echo example, go-echo is NOT a Rust plugin: it's a Go shared
# library (`go build -buildmode=c-shared`) exporting the four `extern "C"`
# symbols of loadr's C ABI — proving loadr plugins can be authored in Go. The
# host auto-detects the C ABI at load time. It serves the `goecho://` scheme
# and echoes each request body back, status 200.
#
# Build + install the plugin, then run:
#   make -C examples/plugins/go-echo
#   mkdir -p dist && cp examples/plugins/go-echo/plugin.toml dist/ \
#     && cp examples/plugins/go-echo/libloadr_plugin_goecho.so dist/
#   loadr plugin install dist
#   loadr run examples/35-go-echo.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly:
#   plugins:
#     - { name: goecho, path: examples/plugins/go-echo/libloadr_plugin_goecho.so }
name: go-echo
description: echo protocol via a Go (C-ABI) loadr plugin

plugins:
  # Resolve `goecho` by name from the plugins dir (after `loadr plugin install`).
  - name: goecho

scenarios:
  echo:
    executor: constant-vus
    vus: 4
    duration: 5s
    flow:
      - request:
          name: echo a payload
          # No `protocol:` needed: the plugin claims the `goecho://` scheme.
          url: goecho://localhost/whatever
          method: SEND
          body: "ping-from-loadr-${vu}-${iteration}"
          assert:
            - { type: status, equals: 200 }                 # 200 = ok
            - { type: body_contains, value: "ping-from-loadr" }

View raw: examples/35-go-echo.yaml

What it shows

  • Native (C-ABI) plugin
  • Declare a URL scheme
  • Install like any other plugin