keelith

module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0

README

Keelith

Go Reference License

Keelith 是面向 Go 服务的运行时与开发工具集,覆盖应用生命周期、依赖装配、服务治理、传输适配、配置发布、可观测性和可编程拓扑控制。

它适合希望把框架能力保留在进程边界、治理中间件和生成工具里的团队:业务代码仍然是普通 Go 函数、普通构造函数和普通协议定义,Keelith 负责把这些部件连接成可运行、可诊断、可渐进交付的服务。

核心能力

  • 应用生命周期:app 负责有序启动、健康状态、优雅停止、hook 回滚和 server 退出处理。
  • 依赖装配:di 提供实例级依赖图、模块组合、命名绑定、分组绑定、插件排序、运行时构建和静态 wiring 生成。
  • 配置系统:config 支持多来源合并、未知字段策略、类型绑定、订阅发布、版本化配置和重启边界。
  • 服务治理:governance 提供 timeout、retry、rate limit、bulkhead、circuit breaker、hedging、loadshed、fallback、idempotency 等按 operation.Operation 解析的中间件。
  • 传输层:根模块内置 HTTP、gRPC、SSE、WebSocket、metadata、auth、TLS reload 和 framework error 映射。
  • 可观测性与运维面:observability 和 ops 提供 App 级日志、trace、metrics、审计、健康检查、pprof、运行时状态和可编程 runtime 管理入口。
  • 可编程运行时:programmable/continuation、programmable/projection、programmable/topology 提供 durable call、投影调度、拓扑计划和流量 epoch 控制。
  • 开发工具:keelith CLI 支持项目增量生成、配置管理、doctor、依赖图检查、wiring 同步和离线模型生成;protoc-gen-go-keelith 从 Protobuf 注解生成传输适配代码。

模块

模块 导入路径 说明
核心 github.com/keelab/keelith 稳定运行时、治理、传输、CLI 和代码生成器
扩展适配 github.com/keelab/contrib etcd、Nacos、Redis、Kafka、SQL、Kubernetes、Vault、JWT、OTLP、Prometheus、Protovalidate 等外部系统适配
实验扩展 github.com/keelab/x CloudWeGo Hertz、Kitex 和 Kitex generic profile
Operator github.com/keelab/operator Kubernetes TopologyRevision API、渲染器和 namespaced controller

安装

Keelith 当前按 go.mod 中的 Go 版本开发和验证。

go install github.com/keelab/keelith/cmd/keelith@latest
go install github.com/keelab/keelith/cmd/protoc-gen-go-keelith@latest

查看 CLI 能力:

keelith --help

当前命令分组包括:

  • add:添加 API、依赖或应用组件。
  • config:管理版本化配置的 stage、active、history、activate、rollback。
  • doctor:检查工具链和项目完整性。
  • generate:生成 adapter、facade 或离线数据模型。
  • graph:检查服务和依赖合约。
  • wiring:同步、校验和检查依赖 wiring 产物。

快速开始

创建一个普通 Go 模块后,先用 CLI 初始化或增量补齐项目结构:

mkdir orders && cd orders
go mod init example.com/orders
keelith doctor --path .
keelith add --help
keelith wiring --help

在应用代码里,核心运行方式是组合 server、component 和 hook,然后交给 app.App 管理生命周期。下面是最小骨架;实际服务应通过 options 加入 HTTP/gRPC server 或 component:

package main

import (
	"log"

	"github.com/keelab/keelith/app"
)

func main() {
	application, err := app.New()
	if err != nil {
		log.Fatal(err)
	}
	_ = application
}

带有 server 的应用通常在进程入口阻塞运行:

if err := application.Run(context.Background()); err != nil {
	log.Fatal(err)
}

实际服务通常还会加入 HTTP/gRPC server、治理中间件、配置 manager、health registry、observability bundle 和业务组件。Keelith 不要求业务构造函数依赖容器;di 只在构建图时解析依赖。

项目结构

路径 说明
api/ Keelith Protobuf API、错误协议和 generated manifest
app/ 应用生命周期、component 注册、drain 和 termination
cache/ 进程内缓存、codec、失效事件和策略
cmd/ keelith CLI 和 protoc-gen-go-keelith
config/ 配置源、合并、typed binding、versioned runtime
di/ 模块、provider、graph、静态 wiring 和 topology bridge
governance/ retry、timeout、ratelimit、bulkhead、breaker、hedging 等治理中间件
middleware/ 传输无关 unary/stream middleware 组合
observability/ 日志、审计、trace、metrics、resource 和 programmable adapter
ops/ 独立运维 HTTP server 和诊断接口
programmable/ continuation、projection、topology 控制运行时
registry/、selector/ 服务注册发现抽象和节点选择策略
transport/ HTTP、gRPC、SSE、WebSocket、TLS、auth 适配
worker/、inbox/、outbox/、saga/ 后台任务、消息一致性和流程状态基础设施
contrib/ 外部系统适配模块,见 contrib/README.md
x/ 实验传输扩展,见 x/README.md
operator/ Kubernetes 拓扑 operator,见 operator/README.md

开发

安装依赖:

go mod download

常用检查:

go test ./...
make test
make vet
make verify

Makefile 会按模块运行核心、contrib、x、operator 和示例模块的检查。涉及集成能力时使用专门目标,例如:

make integration
make projection-storage-integration
make topology-kubernetes-integration
make topology-operator-integration

生成协议和兼容性检查:

make generated-check
make compatibility-check

安全与贡献

安全问题不要通过公开 Issue 报告,请遵循 SECURITY.md。贡献流程、提交规范和本地检查见 CONTRIBUTING.md。

License

Keelith 使用 Apache License 2.0。

Directories

Path Synopsis
api
v1
app
Package app defines application lifecycle, dependency, and shutdown contracts.
Package app defines application lifecycle, dependency, and shutdown contracts.
drain
Package drain coordinates service deregistration before server shutdown.
Package drain coordinates service deregistration before server shutdown.
registration
Package registration coordinates service registration after listeners start and deregistration before listeners drain.
Package registration coordinates service registration after listeners start and deregistration before listeners drain.
termination
Package termination coordinates executable-owned two-stage shutdown.
Package termination coordinates executable-owned two-stage shutdown.
Package cache provides backend-neutral read-through cache policy.
Package cache provides backend-neutral read-through cache policy.
invalidation
Package invalidation defines versioned cache invalidation events and a Worker-compatible processor.
Package invalidation defines versioned cache invalidation events and a Worker-compatible processor.
memory
Package memory provides an in-process implementation of cache.Backend.
Package memory provides an in-process implementation of cache.Backend.
Package client connects service discovery snapshots to feedback-aware selectors without owning transport connections.
Package client connects service discovery snapshots to feedback-aware selectors without owning transport connections.
cmd
keelith command
Command keelith provides project generation and diagnostics.
Command keelith provides project generation and diagnostics.
protoc-gen-go-keelith command
Command protoc-gen-go-keelith generates Keelith transport adapters.
Command protoc-gen-go-keelith generates Keelith transport adapters.
Package config provides immutable, validated, atomically published configuration snapshots.
Package config provides immutable, validated, atomically published configuration snapshots.
env
Package env provides prefix-scoped environment configuration snapshots.
Package env provides prefix-scoped environment configuration snapshots.
file
Package file provides JSON and YAML file-backed configuration snapshots.
Package file provides JSON and YAML file-backed configuration snapshots.
testsource
Package testsource provides an in-memory Config Source for tests and local composition.
Package testsource provides an in-memory Config Source for tests and local composition.
versioned
Package versioned defines provider-neutral immutable configuration revision and activation contracts.
Package versioned defines provider-neutral immutable configuration revision and activation contracts.
Package contract defines generated service and dependency manifests.
Package contract defines generated service and dependency manifests.
Package coordination defines small distributed ownership contracts: try to acquire an auto-maintained lease for a stable key, observe loss via Done/Err, and carry a fencing token on Handler contexts.
Package coordination defines small distributed ownership contracts: try to acquire an auto-maintained lease for a stable key, observe loss via Done/Err, and carry a fencing token on Handler contexts.
memory
Package memory provides process-local coordination for development and contract verification.
Package memory provides process-local coordination for development and contract verification.
Package correlation defines validated, transport-neutral request correlation identities.
Package correlation defines validated, transport-neutral request correlation identities.
di
Package di builds an instance-scoped application dependency graph.
Package di builds an instance-scoped application dependency graph.
topology
Package topology bridges Keelith dependency injection with frozen programmable local/remote component bindings.
Package topology bridges Keelith dependency injection with frozen programmable local/remote component bindings.
Package errors defines transport-neutral Keelith application errors.
Package errors defines transport-neutral Keelith application errors.
Package feature provides provider-neutral, request-scoped feature evaluation over immutable revisioned definitions.
Package feature provides provider-neutral, request-scoped feature evaluation over immutable revisioned definitions.
configured
Package configured adapts Keelith dynamic configuration to feature.Store.
Package configured adapts Keelith dynamic configuration to feature.Store.
governance
admission
Package admission applies dynamic, provider-neutral outbound drop policies.
Package admission applies dynamic, provider-neutral outbound drop policies.
attempt
Package attempt carries low-cardinality governance attempt metadata.
Package attempt carries low-cardinality governance attempt metadata.
breaker
Package breaker provides explainable service and instance circuit breakers.
Package breaker provides explainable service and instance circuit breakers.
bulkhead
Package bulkhead provides dependency-scoped concurrency isolation.
Package bulkhead provides dependency-scoped concurrency isolation.
dependency
Package dependency assembles coherent outbound dependency governance.
Package dependency assembles coherent outbound dependency governance.
failure
Package failure classifies transport-neutral invocation failures.
Package failure classifies transport-neutral invocation failures.
fallback
Package fallback provides explicit, transport-neutral degraded responses.
Package fallback provides explicit, transport-neutral degraded responses.
hedging
Package hedging provides bounded parallel attempts for idempotent methods.
Package hedging provides bounded parallel attempts for idempotent methods.
idempotency
Package idempotency provides transport-neutral, operation-scoped request deduplication with fenced ownership and bounded result replay.
Package idempotency provides transport-neutral, operation-scoped request deduplication with fenced ownership and bounded result replay.
inbound
Package inbound assembles coherent server-side request governance.
Package inbound assembles coherent server-side request governance.
loadshed
Package loadshed provides CPU-aware BBR-like concurrency shedding.
Package loadshed provides CPU-aware BBR-like concurrency shedding.
outlier
Package outlier provides passive instance health detection for selectors.
Package outlier provides passive instance health detection for selectors.
policy
Package policy defines immutable, transport-neutral method policy snapshots.
Package policy defines immutable, transport-neutral method policy snapshots.
ratelimit
Package ratelimit provides per-Operation token and concurrency limits.
Package ratelimit provides per-Operation token and concurrency limits.
retry
Package retry provides deadline-aware, budgeted full-jitter retries.
Package retry provides deadline-aware, budgeted full-jitter retries.
streamlimit
Package streamlimit provides per-stream quotas and shared message limits.
Package streamlimit provides per-stream quotas and shared message limits.
timeout
Package timeout applies Method Policy deadlines.
Package timeout applies Method Policy deadlines.
Package health provides instance-scoped lifecycle and health reporting.
Package health provides instance-scoped lifecycle and health reporting.
Package inbox provides broker-neutral transactional consumer idempotency.
Package inbox provides broker-neutral transactional consumer idempotency.
internal
cli
Package cli implements the Keelith developer command.
Package cli implements the Keelith developer command.
generator
Package generator implements Keelith's standard Protobuf code generator.
Package generator implements Keelith's standard Protobuf code generator.
generator/data
Package data generates optional Go data models from SQL DDL.
Package data generates optional Go data models from SQL DDL.
generator/kitexfacade
Package kitexfacade generates governance-safe facades around Kitex clients.
Package kitexfacade generates governance-safe facades around Kitex clients.
httptemplate
Package httptemplate parses and executes google.api.http path templates.
Package httptemplate parses and executes google.api.http path templates.
projectinfo
Package projectinfo reads the standard, filesystem-owned identity of a Go project without requiring Keelith-specific scaffold metadata.
Package projectinfo reads the standard, filesystem-owned identity of a Go project without requiring Keelith-specific scaffold metadata.
protowkt
Package protowkt centralizes Protobuf well-known-type wire projections.
Package protowkt centralizes Protobuf well-known-type wire projections.
scaffold
Package scaffold provides bounded source and contract mutations for existing Go projects.
Package scaffold provides bounded source and contract mutations for existing Go projects.
version
Package version reports the Keelith build version.
Package version reports the Keelith build version.
Package metadata provides immutable request metadata and explicit propagation policies.
Package metadata provides immutable request metadata and explicit propagation policies.
Package middleware defines Keelith's transport-neutral invocation model.
Package middleware defines Keelith's transport-neutral invocation model.
Package observability composes one App-scoped log/trace/metric pipeline.
Package observability composes one App-scoped log/trace/metric pipeline.
completion
Package completion defines the shared, low-cardinality result contract used by request logs, metrics, and traces.
Package completion defines the shared, low-cardinality result contract used by request logs, metrics, and traces.
logging
Package logging provides instance-scoped slog with redaction and trace IDs.
Package logging provides instance-scoped slog with redaction and trace IDs.
logging/audit
Package audit provides bounded, non-sampled security audit records.
Package audit provides bounded, non-sampled security audit records.
metrics
Package metrics provides instance-scoped OpenTelemetry RPC metrics.
Package metrics provides instance-scoped OpenTelemetry RPC metrics.
programmable
Package programmable exports bounded OpenTelemetry observers for Keelith's continuation, topology, and projection runtimes.
Package programmable exports bounded OpenTelemetry observers for Keelith's continuation, topology, and projection runtimes.
resource
Package resource defines the single service identity shared by telemetry.
Package resource defines the single service identity shared by telemetry.
tracing
Package tracing provides instance-scoped OpenTelemetry tracing.
Package tracing provides instance-scoped OpenTelemetry tracing.
Package operation defines stable identities for transport-neutral calls.
Package operation defines stable identities for transport-neutral calls.
Package ops provides an isolated operational HTTP server.
Package ops provides an isolated operational HTTP server.
Package outbox provides a storage- and broker-neutral transactional outbox dispatcher.
Package outbox provides a storage- and broker-neutral transactional outbox dispatcher.
Package placement carries immutable, low-cardinality deployment placement for one inbound service invocation.
Package placement carries immutable, low-cardinality deployment placement for one inbound service invocation.
programmable
component
Package component binds typed local or remote providers to frozen topology.
Package component binds typed local or remote providers to frozen topology.
continuation
Package continuation defines the durable state model for continuable calls.
Package continuation defines the durable state model for continuable calls.
continuation/memory
Package memory provides a process-local continuation Store.
Package memory provides a process-local continuation Store.
projection
Package projection defines transport- and storage-neutral typed projection synchronization models.
Package projection defines transport- and storage-neutral typed projection synchronization models.
projection/memory
Package memory provides an in-process projection Store.
Package memory provides an in-process projection Store.
projection/ownermemory
Package ownermemory provides a bounded single-owner projection Source.
Package ownermemory provides a bounded single-owner projection Source.
topology
Package topology defines immutable component placement plans and bindings.
Package topology defines immutable component placement plans and bindings.
topology/control
Package control applies signed, revisioned topology candidates while retaining the last known-good runtime epoch.
Package control applies signed, revisioned topology candidates while retaining the last known-good runtime epoch.
topology/planfile
Package planfile defines Keelith's strict, canonical topology plan document.
Package planfile defines Keelith's strict, canonical topology plan document.
Package registry defines infrastructure-neutral registration and discovery contracts.
Package registry defines infrastructure-neutral registration and discovery contracts.
configured
Package configured provides atomically reloadable, configuration-backed service discovery.
Package configured provides atomically reloadable, configuration-backed service discovery.
memory
Package memory provides an in-memory Registry and Discovery implementation.
Package memory provides an in-memory Registry and Discovery implementation.
Package saga provides durable, lease-fenced orchestration and compensation.
Package saga provides durable, lease-fenced orchestration and compensation.
memory
Package memory provides a process-local Saga Repository.
Package memory provides a process-local Saga Repository.
Package secret defines provider-neutral secret references and values.
Package secret defines provider-neutral secret references and values.
file
Package file provides bounded filesystem-backed secrets with polling watch.
Package file provides bounded filesystem-backed secrets with polling watch.
memory
Package memory provides an instance-scoped in-memory secret provider for development, conformance, and bootstrap use.
Package memory provides an instance-scoped in-memory secret provider for development, conformance, and bootstrap use.
Package security defines authenticated principal state shared by AuthN and AuthZ adapters.
Package security defines authenticated principal state shared by AuthN and AuthZ adapters.
authn
Package authn provides transport-neutral authentication middleware.
Package authn provides transport-neutral authentication middleware.
authz
Package authz provides transport-neutral authorization middleware and a small exact/wildcard RBAC policy.
Package authz provides transport-neutral authorization middleware and a small exact/wildcard RBAC policy.
Package selector provides feedback-aware service node selection.
Package selector provides feedback-aware service node selection.
Package server defines the lifecycle contract implemented by Keelith transports, workers, jobs, and operational endpoints.
Package server defines the lifecycle contract implemented by Keelith transports, workers, jobs, and operational endpoints.
Package service defines the immutable identity shared by runtime, registration, logs, traces, and metrics.
Package service defines the immutable identity shared by runtime, registration, logs, traces, and metrics.
transport
grpc
Package grpc provides Keelith's grpc-go transport.
Package grpc provides Keelith's grpc-go transport.
grpc/continuation
Package continuationgrpc exposes the transport-neutral Continuation Service through a bounded, authenticated gRPC v1 protocol.
Package continuationgrpc exposes the transport-neutral Continuation Service through a bounded, authenticated gRPC v1 protocol.
grpc/projection
Package projectiongrpc adapts projection Sources to a bounded gRPC stream.
Package projectiongrpc adapts projection Sources to a bounded gRPC stream.
grpcauth
Package grpcauth provides Secret-backed outbound gRPC credentials without coupling application config to plaintext authentication material.
Package grpcauth provides Secret-backed outbound gRPC credentials without coupling application config to plaintext authentication material.
http
Package http provides Keelith's standard-library HTTP transport.
Package http provides Keelith's standard-library HTTP transport.
http/continuation
Package continuationhttp implements the continuation v1 HTTP profile.
Package continuationhttp implements the continuation v1 HTTP profile.
httpauth
Package httpauth provides fail-closed outbound HTTP authentication transports without coupling callers to plaintext credential material.
Package httpauth provides fail-closed outbound HTTP authentication transports without coupling callers to plaintext credential material.
sse
Package sse defines transport-neutral Server-Sent Events values and bounded wire rendering shared by HTTP transport profiles.
Package sse defines transport-neutral Server-Sent Events values and bounded wire rendering shared by HTTP transport profiles.
tlsconfig
Package tlsconfig provides shared TLS and mTLS profiles for transports.
Package tlsconfig provides shared TLS and mTLS profiles for transports.
websocket
Package websocket provides an explicit, lifecycle-owned RFC 6455 adapter for standard Keelith HTTP routes.
Package websocket provides an explicit, lifecycle-owned RFC 6455 adapter for standard Keelith HTTP routes.
Package validation defines transport-neutral request validation and stable field violation errors.
Package validation defines transport-neutral request validation and stable field violation errors.
Package worker provides broker- and scheduler-neutral background runtimes.
Package worker provides broker- and scheduler-neutral background runtimes.
owned
Package owned decorates a worker Scheduler with distributed lease ownership.
Package owned decorates a worker Scheduler with distributed lease ownership.

Jump to

Keyboard shortcuts

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