example

command
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

完整示例:一条 xyz.Define(...)...Run() 链 = 整个程序。 覆盖常用写法:位置参数、短名/别名、env 注入与 secret 字段、枚举、 指针与切片、命名标量、time.Duration/[]byte、required/validate、 全局默认值与 CLI/HTTP/MCP 三层覆盖、表格输出、基础类型返回、 错误分类(not_found/invalid_input/unauthorized)、MCP 注解与版本限定。

试用:

go run ./cmd/example user add bob -a 20 -m fast --tags a,b
APP_TOKEN=t0ken go run ./cmd/example user add alice --verbose
go run ./cmd/example user ua carol            # 别名
go run ./cmd/example user rm alice            # 成功;user rm bob → not_found
go run ./cmd/example user list                # []struct → 表格
go run ./cmd/example search query --query golang  # CLI 专属默认 k=25(--q 是未知 flag)
go run ./cmd/example math sum --a 1 --b 2     # 基础类型 int
go run ./cmd/example math div --a 10 --b 4    # float64;--b 0 → invalid_input
go run ./cmd/example time now                 # time.Time
go run ./cmd/example sys sleep --d 300ms      # time.Duration;>5s 报错
go run ./cmd/example sys port -p 9090         # 命名标量 type Port
go run ./cmd/example file hash --data hello   # []byte
NEXT_KEY=k go run ./cmd/example net head      # header/httpName + env
go run ./cmd/example mcp stdio                # MCP:命令即工具

Jump to

Keyboard shortcuts

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