gen

package
v0.7.1 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 gen 实现 appkit gen 的四个代码生成器: contract(契约五件套:接口/DTO/wrapper/client/server + openapi 派生导出)、 events(事件类型)、errors(错误码)、wrap(契约 wrapper,ProvideContract 闭环)。

共同约定:生成物首行是标准 "Code generated" 头;输出前经 go/format 格式化; 同一输入重复生成逐字节稳定(golden 测试可校验,CI 用 git diff 防手改)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contract

func Contract(inPath, outDir string) error

Contract 读取契约 yaml,在 outDir 生成契约包的全套文件:

service.gen.go  Service 接口 + 传值 DTO(本文件渲染)
wrap.gen.go     进程内 wrapper(复用 Wrap 链路,扫刚写出的 service.gen.go)
client.gen.go   远程 client:同一接口,contract.Call + 幂等有界重试
server.gen.go   HTTP 暴露:与 client 互为镜像的编解码
openapi.yaml    派生导出(文档 / oasdiff 门禁;非事实源)

方法 HTTP 形态唯一:POST + JSON body,错误一律 problem+json—— 契约调用是 RPC 语义,client/server 两侧的编解码因此只有一份约定。

func Errors

func Errors(inPath, outPath string) error

Errors 读取错误码 yaml,生成 Code* 常量与 Err* sentinel。见 appkit gen errors。

func Events

func Events(inPath, outPath string) error

Events 读取事件 schema yaml,生成事件类型文件(struct + Topic 常量 + Event()/Parse* 方法)。见 appkit gen events。

func Wrap

func Wrap(srcDir, iface, system, outPath string) error

Wrap 解析 srcDir 包中的接口 iface,生成同包的契约 wrapper 文件: wrapped<Iface> 每个方法体经 contract.Call(事务守卫/ctx 防火墙/超时/错误规范化), Wrap<Iface> 供 appkit.ProvideContract 使用——裸实现进不了 registry。

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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