archcheck

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 14 Imported by: 0 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.

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

View Source
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

func LoadConfig(dir string) (*Config, error)

LoadConfig 读取并校验 dir 下的 .appkit.yml。 module 缺省时回退到 go.mod 的 module 声明。

type Violation

type Violation struct {
	File string
	Line int
	Msg  string
}

Violation 是一条违规。File 为相对仓库根目录的斜杠路径; Line 为 1 起始行号,文件级违规(如文件名不合规)为 0。

func CheckImports

func CheckImports(dir string, cfg *Config) ([]Violation, error)

CheckImports 用 go/parser(ImportsOnly)扫描全部 .go 文件的 import 边界。 跳过 _test.go 与 vendor/、点开头目录,其余一律扫描。规则见 importViolation。

func CheckMigrations

func CheckMigrations(dir string) ([]Violation, error)

CheckMigrations 检查 db/migrations 下 .sql 文件名格式,以及序号严格递增且不重复。 目录不存在视为无迁移,不报错。非 .sql 文件不参与检查。

func CheckRequires

func CheckRequires(dir string, cfg *Config) ([]Violation, error)

CheckRequires 检查 go.mod 的 require 清单:github.com/forgeplex/* 中 只放行 appkit、appkit/lint、.appkit.yml 的 contracts 与 allowRequires, 其余一律违规(域仓库互不依赖铁律,跨域调用只依赖 contracts 生成的类型)。

func CheckSQL

func CheckSQL(dir string, cfg *Config) ([]Violation, error)

CheckSQL 扫描 db/**/*.sql 中的跨 schema 引用: 捕获到的 schema 名既不是本域 domain 也不是系统 schema 即违规 (每域独占 Postgres schema,跨域数据走契约调用或事件读模型)。

分区域域(partitioned: true)的规则翻转:任何 schema 前缀都是违规—— 落位由事务级 search_path 路由决定,混入前缀形态破坏 sqlc 编译自洽性 (一个世界里有前缀、一个世界里没有)。sqlc 编译器也会拦,但那是 make gen 才跑;这里在 make check(无 DB)就给出行号。

func Run

func Run(dir string) ([]Violation, error)

Run 读取 .appkit.yml 后依次执行四类检查,返回全部违规。 kind: system 跳过 Requires 与 SQL 检查,Imports 内部只保留结构性规则。

func (Violation) String

func (v Violation) String() string

String 输出 "file:line: 消息";文件级违规行号记为 1,保持格式可被编辑器跳转。

Jump to

Keyboard shortcuts

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