refactor: SimApiExtensions 移入根包 simapi 并改为静态类,删除 extensions 子包
- src/extensions/SimApiExtensions.cj 删除,内容合并进 src/SimApiExtensions.cj(package simapi)
- 接口+extend 改为静态类 SimApiExtensions:
SimApiExtensions.addSimApi(builder, configure) / useSimApi(host)(对齐 .NET 根命名空间静态类)
- 私有辅助 addSimApiCore / addControllers 收敛为私有静态方法
- 用法从 builder.addSimApi{} / host.useSimApi() 改为 SimApiExtensions.addSimApi(builder){} / useSimApi(host)
This commit is contained in:
@@ -16,7 +16,7 @@ import soulsoft_web_routing.*
|
||||
import soulsoft_web_hosting.*
|
||||
import soulsoft_extensions_logging.*
|
||||
import soulsoft_extensions_injection.*
|
||||
import simapi.extensions.*
|
||||
import simapi.*
|
||||
import simapi.communications.*
|
||||
|
||||
main(args: Array<String>) {
|
||||
@@ -25,14 +25,14 @@ main(args: Array<String>) {
|
||||
builder.services.addLogging()
|
||||
|
||||
// 注册 SimApi 服务(与 addLogging 同样式)
|
||||
builder.addSimApi { options =>
|
||||
SimApiExtensions.addSimApi(builder) { options =>
|
||||
options.enableSimApiAuth = true // Token 认证(未配 Redis 自动用 InMemory)
|
||||
options.enableSimApiCache = true // 缓存
|
||||
options.enableSimApiException = true // 全局异常拦截
|
||||
}
|
||||
|
||||
let host = builder.build()
|
||||
host.useSimApi()
|
||||
SimApiExtensions.useSimApi(host)
|
||||
|
||||
// 业务接口:返回统一响应格式
|
||||
host.mapGet("hello") {
|
||||
@@ -74,17 +74,17 @@ main(args: Array<String>) {
|
||||
simapi-cj/
|
||||
├── cjpm.toml # 包配置
|
||||
├── src/
|
||||
│ ├── SimApiExtensions.cj # 根包入口:SimApiExtensions 静态类(addSimApi / useSimApi + 内置路由 + 响应封装)
|
||||
│ ├── attributes/ # 声明式注解:@SimApiAuth(鉴权)、@OriginResponse(原样响应)
|
||||
│ ├── authsdk/ # 认证中心 SDK:SimApiAuthClient/Center/Iam + 网关中间件 + DTO
|
||||
│ ├── communications/ # SimApiBaseResponse, PageResponse, SimApiLoginItem, 请求 DTO
|
||||
│ ├── configurations/ # SimApiOptions + 各模块 Option(含 ConfigureSimApiXxx 回调)
|
||||
│ ├── controllers/ # SimApiBaseController, SimApiCommonController, SimApiAuthController(MVC 写法)
|
||||
│ ├── exceptions/ # SimApiException
|
||||
│ ├── extensions/ # SimApiExtensions(addSimApi / useSimApi + 内置路由 + 响应封装)
|
||||
│ ├── helpers/ # SimApiError, SimApiUtil, SimApiAuth, SimApiCache, SimApiHttpClient,
|
||||
│ │ # SimApiAesUtil(AES-256), SimApiSignChecker(验签), SimApiAesBodyChecker(AES body),
|
||||
│ │ # SimApiStorage(S3/MinIO, 自实现 SigV4)
|
||||
│ ├── interfaces/ # ISimApiAuthChecker
|
||||
│ │ # SimApiStorage(S3/MinIO, 自实现 SigV4), SimApiRequestDelegateFactory, SimApiResultWriter
|
||||
│ ├── interfaces/ # ISimApiAuthChecker, IBindRequestContext
|
||||
│ ├── logger/ # SimApiLogger, SimApiLoggerProvider(彩色日志)
|
||||
│ ├── macros/ # ReadTomlVersion(编译期读版本号)
|
||||
│ ├── middlewares/ # SimApiExceptionMiddleware, SimApiAuthMiddleware, SimApiRequestLogMiddleware
|
||||
@@ -283,7 +283,7 @@ let resp3 = client.aesSignQuery<SimApiLoginItem>("/api/data", body: "{\"a\":1}")
|
||||
- 响应体因 soulsoft `HttpResponse.body` 只读不可替换,记录 `Content-Length` 作为替代(C# 用 MemoryStream 捕获)
|
||||
|
||||
```cangjie
|
||||
builder.addSimApi { options =>
|
||||
SimApiExtensions.addSimApi(builder) { options =>
|
||||
options.enableRequestLog = true
|
||||
options.simApiRequestLogOptions.showFullHeader = true // 打印完整 Header(默认只打 Token/Query-Id)
|
||||
options.simApiRequestLogOptions.requestStringLogLength = 200 // 请求体字段截断长度(0 不截断)
|
||||
@@ -326,7 +326,7 @@ builder.addSimApi { options =>
|
||||
`enableSimApiStorage = true` 时注册 `SimApiStorage`(Scoped,内部自实现 AWS Signature V4,无需 Minio SDK):
|
||||
|
||||
```cangjie
|
||||
builder.addSimApi { options =>
|
||||
SimApiExtensions.addSimApi(builder) { options =>
|
||||
options.enableSimApiStorage = true
|
||||
options.configureSimApiStorage { storage =>
|
||||
storage.endpoint = "http://192.168.0.2:9000" // 必须 http:// 或 https:// 开头
|
||||
@@ -388,7 +388,7 @@ class MyAuthChecker <: ISimApiAuthChecker {
|
||||
`enableSimApiAuthGate = true` 时注册 `SimApiAuthClient` / `SimApiAuthCenter` / `SimApiAuthIam` 单例并挂载网关透传中间件:
|
||||
|
||||
```cangjie
|
||||
builder.addSimApi { options =>
|
||||
SimApiExtensions.addSimApi(builder) { options =>
|
||||
options.enableSimApiAuthGate = true
|
||||
options.configureSimApiAuthCenter { auth =>
|
||||
auth.server = "https://auth.example.com"
|
||||
@@ -420,7 +420,7 @@ iam.checkPermission(profileId, "app:create") // 无权限抛 403
|
||||
## SimApiOptions 完整配置
|
||||
|
||||
```cangjie
|
||||
builder.addSimApi { options =>
|
||||
SimApiExtensions.addSimApi(builder) { options =>
|
||||
options.redisConfiguration = "localhost:6379" // Redis(可选,支持 ,password=xxx,db=2)
|
||||
|
||||
// 功能开关
|
||||
|
||||
Reference in New Issue
Block a user