frame

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-frame

go-frame 是 Go 服务基础库。业务通过构造函数装配 HTTP、生命周期、数据库、Redis 和观测能力,并持有自己的业务规则和部署配置。路由使用 chi,日志使用 slog,数据库层支持按需接入 Ent 等 ORM。

最低 Go 版本以 go.mod 为准,当前版本为 v0.2.6。GitHub 可下载版本以实际标签为准,见版本发布。

文档

内容 入口
按任务选择示例和组件 文档导航 · 示例导航
用法、限制和代码片段 能力与使用参考
设计取舍、运行流程与包边界 设计说明 · 整体架构 · 能力目录
新建服务和接入现有业务 服务模板 · 业务装配
本地开发与测试 开发指南 · 验证指南
分支、版本标签和 GitHub Release 版本发布 · 更新日志
部署时的配置、日志和生命周期 运行约束

快速开始

你要做什么 推荐入口
理解启动和运行机制 basic:可直接运行,SQL/Redis 默认关闭
创建独立业务工程 服务模板:独立 module、bootstrap 和功能目录
参考完整 CRUD 与业务分层 分类业务:DTO、VO、Handler、Service、Store 与事务;运行步骤
go run ./examples/basic
curl http://localhost:3000/healthz
curl -H 'Content-Type: application/json' -d '{"name":"Ada"}' http://localhost:3000/greetings

未配置 DATABASE_URL 或 REDIS_ADDR 时也可以运行 basic 示例。启用依赖后,应用会在开始接收请求前检查连接。

本地验证

从根目录执行 go test ./... -count=1。独立服务模板、race 和集成测试的入口见验证指南。

许可证

MIT

Documentation

Overview

Package frame documents the service infrastructure library. Applications import the capability packages they use and compose them explicitly.

Directories

Path Synopsis
app
Package app manages a service and its dependencies with ordered startup, rollback, graceful shutdown and reverse-order cleanup.
Package app manages a service and its dependencies with ordered startup, rollback, graceful shutdown and reverse-order cleanup.
command
Package command dispatches standard service commands without opening resources, changing globals, installing signal handlers or exiting the process.
Package command dispatches standard service commands without opening resources, changing globals, installing signal handlers or exiting the process.
config
Package config supplies independently composable deployment settings without opening resources.
Package config supplies independently composable deployment settings without opening resources.
config/redis
Package redis maps configuration to Redis options, including verified TLS.
Package redis maps configuration to Redis options, including verified TLS.
resource
Package resource adapts explicitly owned dependencies to app lifecycle hooks.
Package resource adapts explicitly owned dependencies to app lifecycle hooks.
startup
Package startup owns process loading diagnostics and the optional logger runtime.
Package startup owns process loading diagnostics and the optional logger runtime.
auth
http
Package auth adapts credential verification to HTTP with default-required routes.
Package auth adapts credential verification to HTTP with default-required routes.
principal
Package principal carries validated application identity, not credentials or permissions.
Package principal carries validated application identity, not credentials or permissions.
token
Package token issues and verifies one deliberately narrow encrypted access-token profile: ES256 signed JWT inside a dir/A256GCM compact JWE.
Package token issues and verifies one deliberately narrow encrypted access-token profile: ES256 signed JWT inside a dir/A256GCM compact JWE.
Package cache defines bounded byte stores and explicit JSON serialization helpers.
Package cache defines bounded byte stores and explicit JSON serialization helpers.
memory
Package memory provides a bounded process-local LRU cache with lazy expiry.
Package memory provides a bounded process-local LRU cache with lazy expiry.
redis
Package redis implements cache.Store using a borrowed Redis client.
Package redis implements cache.Store using a borrowed Redis client.
cmd
frame command
Command frame runs local development tooling; see `frame dev`.
Command frame runs local development tooling; see `frame dev`.
Package concurrency provides bounded, per-process concurrency primitives.
Package concurrency provides bounded, per-process concurrency primitives.
Package config decodes explicitly declared configuration schemas, merges sources and reports safe field diagnostics independently of deployment models.
Package config decodes explicitly declared configuration schemas, merges sources and reports safe field diagnostics independently of deployment models.
dotenv
Package dotenv parses explicit development-only environment files without changing the process environment.
Package dotenv parses explicit development-only environment files without changing the process environment.
loader
Package loader composes explicit YAML, development dotenv, captured environment and CLI inputs.
Package loader composes explicit YAML, development dotenv, captured environment and CLI inputs.
reload
Package reload provides isolated configuration snapshots and explicit-file watching.
Package reload provides isolated configuration snapshots and explicit-file watching.
yaml
Package yaml supplies a strict, bounded, optional YAML configuration source.
Package yaml supplies a strict, bounded, optional YAML configuration source.
Package database provides a driver-independent SQL connection pool.
Package database provides a driver-independent SQL connection pool.
audit
Package audit defines explicit creation and update metadata, independent of authentication, persistence, clocks, and transaction policy.
Package audit defines explicit creation and update metadata, independent of authentication, persistence, clocks, and transaction policy.
audit/principal
Package principal converts trusted request identities to explicit audit actors.
Package principal converts trusted request identities to explicit audit actors.
ent
Package entdb integrates business-owned Ent clients with Frame infrastructure.
Package entdb integrates business-owned Ent clients with Frame infrastructure.
internal/txcleanup
Package txcleanup shares SQL and Ent transaction cleanup error policy.
Package txcleanup shares SQL and Ent transaction cleanup error policy.
mysql
Package mysql constructs a lazy MySQL pool using go-sql-driver/mysql.
Package mysql constructs a lazy MySQL pool using go-sql-driver/mysql.
postgres
Package postgres constructs a lazy PostgreSQL pool using pgx's SQL adapter.
Package postgres constructs a lazy PostgreSQL pool using pgx's SQL adapter.
query
Package query builds bounded SQL pagination suffixes without executing or rewriting queries.
Package query builds bounded SQL pagination suffixes without executing or rewriting queries.
examples
authenticated
Package authenticated demonstrates explicit auth, operation and audit wiring.
Package authenticated demonstrates explicit auth, operation and audit wiring.
background
Package background illustrates consumer-owned queues and task registration.
Package background illustrates consumer-owned queues and task registration.
basic command
The example starts without a database or Redis.
The example starts without a database or Redis.
basic/internal/greeting
Package greeting shows a feature module with an explicitly injected service.
Package greeting shows a feature module with an explicitly injected service.
business/cmd/api command
Command api runs the category business example.
Command api runs the category business example.
business/internal/bootstrap
Package bootstrap owns configuration and explicit assembly for the category service.
Package bootstrap owns configuration and explicit assembly for the category service.
business/internal/category
Package category owns category rules independently of HTTP and persistence.
Package category owns category rules independently of HTTP and persistence.
business/internal/category/http
Package categoryhttp adapts the category feature to Frame's HTTP boundary.
Package categoryhttp adapts the category feature to Frame's HTTP boundary.
business/internal/category/store
Package store persists business category snapshots with native Ent queries.
Package store persists business category snapshots with native Ent queries.
business/internal/devicesync
Package devicesync demonstrates durable acceptance and replayable delivery.
Package devicesync demonstrates durable acceptance and replayable delivery.
business/internal/devicesync/store
Package store implements device event state using an application-owned PostgreSQL schema.
Package store implements device event state using an application-owned PostgreSQL schema.
business/internal/devicesync/worker
Package worker demonstrates bounded, process-local delivery scheduling.
Package worker demonstrates bounded, process-local delivery scheduling.
business/internal/profile
Package profile defines a profile update use case without transport or storage dependencies.
Package profile defines a profile update use case without transport or storage dependencies.
business/internal/profile/http
Package profilehttp maps authenticated HTTP requests to the profile use case.
Package profilehttp maps authenticated HTTP requests to the profile use case.
business/internal/profile/store
Package store persists profiles and change records in one PostgreSQL transaction.
Package store persists profiles and change records in one PostgreSQL transaction.
business/internal/profile/upstream
Package upstream implements the typed profile permission dependency.
Package upstream implements the typed profile permission dependency.
configured command
Configured demonstrates business-owned settings and resource-free commands.
Configured demonstrates business-owned settings and resource-free commands.
contracts/endpoint
Package endpoint compares typed registration helpers in examples only.
Package endpoint compares typed registration helpers in examples only.
contracts/transactionhttp
Package transactionhttp is an example-only comparison of explicit and typed route composition for an independent transaction pagination contract.
Package transactionhttp is an example-only comparison of explicit and typed route composition for an independent transaction pagination contract.
ent command
Apply the selected versioned migration before running.
Apply the selected versioned migration before running.
ent/internal/productvalue
Package productvalue contains field-independent rules shared by DTOs and Ent.
Package productvalue contains field-independent rules shared by DTOs and Ent.
observability command
Observability demonstrates explicit SDK ownership without an external collector.
Observability demonstrates explicit SDK ownership without an external collector.
protocols
Package protocols demonstrates protocol adapters with business-owned effects.
Package protocols demonstrates protocol adapters with business-owned effects.
records command
Records demonstrates explicit HTTP -> service -> SQL composition.
Records demonstrates explicit HTTP -> service -> SQL composition.
records/internal/record
Package record owns the feature's business rules and persistence contracts.
Package record owns the feature's business rules and persistence contracts.
records/internal/sqlstore
Package sqlstore implements the record service's persistence contracts.
Package sqlstore implements the record service's persistence contracts.
toolkit
Package toolkit illustrates direct assembly of cross-cutting foundations: bounded caching, Redis lease locks, admission limiting, process-local scheduling, the outbound HTTP client, and hand-rolled transport middleware.
Package toolkit illustrates direct assembly of cross-cutting foundations: bounded caching, Redis lease locks, admission limiting, process-local scheduling, the outbound HTTP client, and hand-rolled transport middleware.
transactions
Package transactionexample demonstrates explicit business transactions and typed HTTP boundaries.
Package transactionexample demonstrates explicit business transactions and typed HTTP boundaries.
Package health provides liveness and bounded, named readiness checks.
Package health provides liveness and bounded, named readiness checks.
http
binding
Package binding composes prepared DTO decoding, validation and typed handlers.
Package binding composes prepared DTO decoding, validation and typed handlers.
client
Package httpclient provides an owned outbound transport and bounded JSON calls.
Package httpclient provides an owned outbound transport and bounded JSON calls.
health
Package healthhttp exposes readiness and liveness over HTTP.
Package healthhttp exposes readiness and liveness over HTTP.
httperror
Package httperror defines explicit public HTTP errors shared by request and response adapters.
Package httperror defines explicit public HTTP errors shared by request and response adapters.
middleware
Package middleware provides request logging, cooperative deadlines and bounded admission.
Package middleware provides request logging, cooperative deadlines and bounded admission.
request
Package request binds explicit, flat query and path DTOs without a router dependency.
Package request binds explicit, flat query and path DTOs without a router dependency.
respond
Package respond provides JSON envelopes, error handling, and explicit error mapping.
Package respond provides JSON envelopes, error handling, and explicit error mapping.
router
Package router composes chi routes with framework middleware and health endpoints.
Package router composes chi routes with framework middleware and health endpoints.
server
Package server provides composable chi routing and configurable HTTP servers.
Package server provides composable chi routing and configurable HTTP servers.
Package id 分布式 ID 生成。
Package id 分布式 ID 生成。
Package identity supplies deployment-independent service and instance metadata.
Package identity supplies deployment-independent service and instance metadata.
internal
consumer
Package consumer verifies independent consumers without changing the repository.
Package consumer verifies independent consumers without changing the repository.
dev
Package dev implements a bounded, build-before-stop development supervisor.
Package dev implements a bounded, build-before-stop development supervisor.
faulttest
Package faulttest provides test-only, connection-scoped fault injection.
Package faulttest provides test-only, connection-scoped fault injection.
isnil
Package isnil reports typed nil values passed through interface arguments.
Package isnil reports typed nil values passed through interface arguments.
requestmeta
Package requestmeta shares bounded observation state across middleware context copies.
Package requestmeta shares bounded observation state across middleware context copies.
responsewriter
Package responsewriter observes response commitment without buffering bodies.
Package responsewriter observes response commitment without buffering bodies.
sortspec
Package sortspec carries the sort-whitelist algorithm shared by the SQL query helpers and the Ent adapter.
Package sortspec carries the sort-whitelist algorithm shared by the SQL query helpers and the Ent adapter.
sqltest
Package sqltest contains opt-in database integration assertions for adapters.
Package sqltest contains opt-in database integration assertions for adapters.
lock
redis
Package redis provides cooperative leases using a borrowed Redis client.
Package redis provides cooperative leases using a borrowed Redis client.
Package optional provides presence-aware JSON request fields.
Package optional provides presence-aware JSON request fields.
Package pagination defines protocol-independent, bounded offset pagination.
Package pagination defines protocol-independent, bounded offset pagination.
Package redis provides an explicitly configured Redis connection pool.
Package redis provides an explicitly configured Redis connection pool.
Package schedule runs explicitly registered, process-local recurring tasks.
Package schedule runs explicitly registered, process-local recurring tasks.
scripts
consumer command
Command consumer verifies independent Frame consumer modules.
Command consumer verifies independent Frame consumer modules.
release-check command
Command release-check validates local release version declarations and, optionally, checks that the VERSION tag resolves to HEAD.
Command release-check validates local release version declarations and, optionally, checks that the VERSION tag resolves to HEAD.
verify-test command
Command verify-test supplies the shared test stage of the verification scripts.
Command verify-test supplies the shared test stage of the verification scripts.
telemetry
logger
Package logger slog 接线:console/JSON 输出 + ctx 惯用法 + 文件轮转。
Package logger slog 接线:console/JSON 输出 + ctx 惯用法 + 文件轮转。
metric
Package metric provides fixed-bucket request-latency histograms with dependency-free exports.
Package metric provides fixed-bucket request-latency histograms with dependency-free exports.
metric/otel
Package metricotel binds a metric.RequestRecorder to OpenTelemetry histograms.
Package metricotel binds a metric.RequestRecorder to OpenTelemetry histograms.
metric/redis
Package metricredis adapts Redis client pool statistics without network I/O.
Package metricredis adapts Redis client pool statistics without network I/O.
operation
Package operation defines bounded, structured operation events and sinks.
Package operation defines bounded, structured operation events and sinks.
operation/http
Package operationhttp records bounded HTTP operations with route-controlled request capture.
Package operationhttp records bounded HTTP operations with route-controlled request capture.
otel
Package telemetry adapts explicit OpenTelemetry providers to HTTP and slog.
Package telemetry adapts explicit OpenTelemetry providers to HTTP and slog.
trace
Package trace provides request correlation IDs, response headers and context propagation.
Package trace provides request correlation IDs, response headers and context propagation.
Package validation defines transport-independent, public field diagnostics.
Package validation defines transport-independent, public field diagnostics.
tags
Package tags adapts declarative v-tag validation to safe input errors.
Package tags adapts declarative v-tag validation to safe input errors.

Jump to

Keyboard shortcuts

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