Documentation
¶
Overview ¶
Package archcheck 实现 appkit check 的四类架构检查: go.mod 依赖清单、Go import 边界、SQL 跨 schema 引用、迁移文件序号。
约束依据见 docs/DESIGN.md §1/§4/§7:域仓库互不依赖、业务包零 infra、 pgx/sqlc 只出现在 internal/postgres、transport 不抄近路、每域独占 schema。
Index ¶
Constants ¶
const ( KindDomain = "domain" KindSystem = "system" )
仓库类型:domain 为业务域仓库(默认),system 为组合仓库(如 psp), system 跳过 domain 相关检查(Requires / 域包 import / 跨域 import / SQL schema)。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Version int `yaml:"version"`
Kind string `yaml:"kind"`
Domain string `yaml:"domain"`
Module string `yaml:"module"`
Contracts string `yaml:"contracts"`
AllowRequires []string `yaml:"allowRequires"`
// Partitioned 标记分区域域(appkit new domain -partitioned):一套代码、
// N 份数据分区,schema 由调用方经事务级 search_path 路由确定。该形态下
// SQL 的前缀规则翻转(见 CheckSQL),schema 文档暂不支持(appkit schema 明确报错)。
Partitioned bool `yaml:"partitioned"`
}
Config 对应仓库根目录的 .appkit.yml。
func LoadConfig ¶
LoadConfig 读取并校验 dir 下的 .appkit.yml。 module 缺省时回退到 go.mod 的 module 声明。
type Violation ¶
Violation 是一条违规。File 为相对仓库根目录的斜杠路径; Line 为 1 起始行号,文件级违规(如文件名不合规)为 0。
func CheckImports ¶
CheckImports 用 go/parser(ImportsOnly)扫描全部 .go 文件的 import 边界。 跳过 _test.go 与 vendor/、点开头目录,其余一律扫描。规则见 importViolation。
func CheckMigrations ¶
CheckMigrations 检查 db/migrations 下 .sql 文件名格式,以及序号严格递增且不重复。 目录不存在视为无迁移,不报错。非 .sql 文件不参与检查。
func CheckRequires ¶
CheckRequires 检查 go.mod 的 require 清单:github.com/forgeplex/* 中 只放行 appkit、appkit/lint、.appkit.yml 的 contracts 与 allowRequires, 其余一律违规(域仓库互不依赖铁律,跨域调用只依赖 contracts 生成的类型)。
func CheckSQL ¶
CheckSQL 扫描 db/**/*.sql 中的跨 schema 引用: 捕获到的 schema 名既不是本域 domain 也不是系统 schema 即违规 (每域独占 Postgres schema,跨域数据走契约调用或事件读模型)。
分区域域(partitioned: true)的规则翻转:任何 schema 前缀都是违规—— 落位由事务级 search_path 路由决定,混入前缀形态破坏 sqlc 编译自洽性 (一个世界里有前缀、一个世界里没有)。sqlc 编译器也会拦,但那是 make gen 才跑;这里在 make check(无 DB)就给出行号。