framework-sdk-go

module
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT

README

XiHan Framework SDK for Go

Out-of-process plugins and remote providers in Go, verified by the same conformance vectors as the .NET host

CI Go Reference Go 1.26 MIT License GitHub Stars

Docs · Getting Started · Specification · Reference Implementation

English | 简体中文

The Go implementation of XiHan Spec: the primitives layer, manifests, the invocation context, the pipeline, operation contracts and the out-of-process plugin runtime, plus the plugin side of the caching.distributed@1 remote provider. Use it to write Go plugins that run in the .NET host (XiHan.Framework), or to use the same primitives in Go applications; the spec lives in spec/ as a submodule, and conformance is verified by the vectors and black-box runner of the spec repository.

Modules

Package Contents Spec
primitives Error and error codes, Result[T], Maybe[T], ID[Tag, V], lifecycle, pipeline stages, Baggage keys, message keys and templates RFC-0001, RFC-0010
manifest The xihan.manifest.json model, reading, canonical output and validation RFC-0002
invocation The invocation context: cancellation and deadlines, W3C tracing, registered Baggage RFC-0003
pipeline The eleven-stage pipeline and its ordering rules RFC-0004
operation Operation contracts, the registry, and an invoker that runs through the full pipeline RFC-0011
plugin The out-of-process plugin runtime Serve and the host callback client Host RFC-0017
plugin/v1 Protocol code generated from spec/plugin/plugin.proto plugin/plugin.proto
caching The plugin side of the caching.distributed@1 remote provider: the store contract, a bounded in-memory store and the operation set RFC-0019
examples/echo An echo plugin; cmd/echo-go is the executable entry point —
examples/cache A remote cache provider plugin; cmd/cache-go is the executable entry point —

Installation

go get github.com/xihanfun/framework-sdk-go

Getting Started

package main

import (
	"context"
	_ "embed"
	"os"

	"github.com/xihanfun/framework-sdk-go/invocation"
	"github.com/xihanfun/framework-sdk-go/operation"
	"github.com/xihanfun/framework-sdk-go/plugin"
	"github.com/xihanfun/framework-sdk-go/primitives"
)

//go:embed xihan.manifest.json
var manifest []byte

type CreateRequest struct{ Text string `json:"text"` }
type CreateResponse struct{ Text, Tenant string }

func main() {
	registry := operation.NewRegistry()
	_ = operation.Add(registry, operation.Contract{ID: "echoes.create", Stability: primitives.Experimental, Expose: []string{operation.ExposeHTTP}},
		operation.HandlerFunc[CreateRequest, CreateResponse](func(ctx *invocation.Context, request CreateRequest) primitives.Result[CreateResponse] {
			return primitives.Ok(CreateResponse{Text: request.Text, Tenant: ctx.Tenant()})
		}), nil, "")

	if err := plugin.Serve(context.Background(), plugin.Options{Manifest: manifest, Operations: registry}); err != nil {
		os.Exit(1)
	}
}

Put the manifest xihan.manifest.json in the same directory as the built executable and the host can load it; verify it with the black-box runner of the spec repository, xihan-conformance plugin --dir <output-dir>. How to write the manifest, message catalogs, subscriptions, callbacks and logs is covered in Write a plugin in the docs.

Documentation

The documentation site is in Chinese.

Where Contents
Go SDK Modules, writing a plugin, behavior shared with the host, language mapping, conformance, breaking changes and migration
Out-of-process plugins The protocol, handshake and lifecycle, loading and callbacks on the host side, remote providers
Spec and languages How the spec is organized, conformance profiles, the state of each language SDK
XiHan Spec RFCs, vocabulary, protocol mappings, conformance vectors and the black-box runner

Status

Claimed conformance profiles (RFC-0024): core, plugin and provider:caching.distributed@1, with no gaps; the pinned spec version is the one in the spec/ submodule and the conformance module in go.mod. Until there is a release pinned to a spec tag, the maturity is Experimental; streaming operations and the Wasm carrier are out of scope. Details are in Conformance in the docs.

Ecosystem

Project Description
framework-spec XiHan Spec: RFCs, vocabulary, protocol mappings and conformance vectors
XiHan.Framework The .NET reference implementation
framework-sdk-typescript TypeScript SDK
framework-sdk-rust Rust SDK
framework-sdk-java Java SDK
framework-sdk-python Python SDK
framework-sdk-php PHP SDK

Contributing

Issues and pull requests are welcome. Changes to public contracts are not made in the SDK repositories: they go through the RFC process of framework-spec first and are then synced to each SDK. Development conventions, gates and the release process are in AGENTS.md.

License

MIT © 2021-Present XiHanFun and contributors.

Directories

Path Synopsis
Package caching 是 caching.distributed@1 远程 Provider 的插件侧(RFC-0019,spec/provider/caching-distributed.md): Store 是 RFC-0006 的六个原子存储操作加三个批量操作(conventions/batch-first.md),MemoryStore 是有界的进程内实现, RegisterOperations 把任何 Store 暴露成操作集,让 .NET 宿主的 Caching.Remote 适配器把这个插件当作分布式缓存 Provider。
Package caching 是 caching.distributed@1 远程 Provider 的插件侧(RFC-0019,spec/provider/caching-distributed.md): Store 是 RFC-0006 的六个原子存储操作加三个批量操作(conventions/batch-first.md),MemoryStore 是有界的进程内实现, RegisterOperations 把任何 Store 暴露成操作集,让 .NET 宿主的 Caching.Remote 适配器把这个插件当作分布式缓存 Provider。
examples
cache
Package cache 是 caching.distributed@1 的远程 Provider 示例插件:用 caching.MemoryStore 实现操作集, .NET 宿主经 Caching.Remote 适配器把它当分布式缓存 Provider(P4-07)。
Package cache 是 caching.distributed@1 的远程 Provider 示例插件:用 caching.MemoryStore 实现操作集, .NET 宿主经 Caching.Remote 适配器把它当分布式缓存 Provider(P4-07)。
cache/cmd/cache-go command
cache-go 是远程缓存 Provider 示例插件的可执行入口:把它和 xihan.manifest.json 放进同一目录,宿主即可加载。
cache-go 是远程缓存 Provider 示例插件的可执行入口:把它和 xihan.manifest.json 放进同一目录,宿主即可加载。
echo
Package echo 是用本 SDK 写的回声插件:与 XiHan.Framework 的 samples/EchoPlugin(.NET)行为对齐, 既是 SDK 的端到端用例,也是 .NET 宿主加载 Go 插件的示例(P4-06)。
Package echo 是用本 SDK 写的回声插件:与 XiHan.Framework 的 samples/EchoPlugin(.NET)行为对齐, 既是 SDK 的端到端用例,也是 .NET 宿主加载 Go 插件的示例(P4-06)。
echo/cmd/echo-go command
echo-go 是回声插件的可执行入口:把它和 xihan.manifest.json 放进同一目录,宿主即可加载。
echo-go 是回声插件的可执行入口:把它和 xihan.manifest.json 放进同一目录,宿主即可加载。
internal
jsoncodec
Package jsoncodec 是 SDK 读写 JSON 值的共用实现,建在 internal/jsontext 读出的、按文档顺序的值上:
Package jsoncodec 是 SDK 读写 JSON 值的共用实现,建在 internal/jsontext 读出的、按文档顺序的值上:
jsontext
Package jsontext 是 XiHan 读取 JSON 文本的共同检查(RFC-0001「JSON 文本」,ADR-0236):Result 与 Error 的线上编码、操作载荷与清单 都先过这一遍,再按文档顺序交给各自的读取。
Package jsontext 是 XiHan 读取 JSON 文本的共同检查(RFC-0001「JSON 文本」,ADR-0236):Result 与 Error 的线上编码、操作载荷与清单 都先过这一遍,再按文档顺序交给各自的读取。
Package invocation 是调用上下文(RFC-0003):取消、截止时间、W3C 追踪、已登记的 Baggage 与请求作用域对象袋; 不绑定任何协议,载体映射由协议适配器与插件运行时实现。
Package invocation 是调用上下文(RFC-0003):取消、截止时间、W3C 追踪、已登记的 Baggage 与请求作用域对象袋; 不绑定任何协议,载体映射由协议适配器与插件运行时实现。
Package manifest 是 xihan.manifest.json 的模型(RFC-0002,Schema 见 spec/manifest/manifest.schema.json):读取、规范排版的写出与校验, 读取的检查顺序、错误与写出的排版与 .NET 的 ManifestReader 逐字一致(ADR-0236);收集、解析与求解是宿主的职责。
Package manifest 是 xihan.manifest.json 的模型(RFC-0002,Schema 见 spec/manifest/manifest.schema.json):读取、规范排版的写出与校验, 读取的检查顺序、错误与写出的排版与 .NET 的 ManifestReader 逐字一致(ADR-0236);收集、解析与求解是宿主的职责。
Package operation 是操作契约与 XGI 消息(RFC-0011):业务以操作为单位声明,调用器让它经过完整管道并在 handle 阶段执行; 请求与响应用 encoding/json 编解码,JSON 是 XGI 的规范编码。
Package operation 是操作契约与 XGI 消息(RFC-0011):业务以操作为单位声明,调用器让它经过完整管道并在 handle 阶段执行; 请求与响应用 encoding/json 编解码,JSON 是 XGI 的规范编码。
Package pipeline 是固定阶段的执行管道(RFC-0004):中间件按阶段贡献,排序确定、可打印、可测试。
Package pipeline 是固定阶段的执行管道(RFC-0004):中间件按阶段贡献,排序确定、可打印、可测试。
Package plugin 是进程外插件的运行时(RFC-0017,spec/plugin/):读取宿主下发的环境变量、以 gRPC 服务端提供 xihan.plugin.v1 的 Plugin 服务、向 stdout 写握手行、按 lifecycle.md §7 维护调用次序、生命周期状态机与健康推送、 把调用分派给登记的操作,并以 Host 客户端回调宿主;Stop、stdin 关闭与 SIGTERM 都按规范的时限收尾退出。
Package plugin 是进程外插件的运行时(RFC-0017,spec/plugin/):读取宿主下发的环境变量、以 gRPC 服务端提供 xihan.plugin.v1 的 Plugin 服务、向 stdout 写握手行、按 lifecycle.md §7 维护调用次序、生命周期状态机与健康推送、 把调用分派给登记的操作,并以 Host 客户端回调宿主;Stop、stdin 关闭与 SIGTERM 都按规范的时限收尾退出。
v1
Package primitives 是 XiHan Framework 原语层(RFC-0001)的 Go 形态:错误与错误码、Result、Maybe、 类型化标识、生命周期状态、管道阶段、稳定性、Baggage 键与消息原语。
Package primitives 是 XiHan Framework 原语层(RFC-0001)的 Go 形态:错误与错误码、Result、Maybe、 类型化标识、生命周期状态、管道阶段、稳定性、Baggage 键与消息原语。

Jump to

Keyboard shortcuts

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