v2.0.0: error-channel APIs, correctness fixes, and server hardening

BREAKING CHANGES:
- Guard interface: Guard(ctx Ctx) error; returning error short-circuits
  (subsequent guards and the method no longer execute)
- Wired[T]() (*T, error); New() may return error; failed wiring is sticky
- BindService/BindGuard/BindRoute return error; routes accept guards
  (guards receive merged query/form params as Ctx.State)
- registration panics after Start; Ctx.Ip honors X-Forwarded-For/X-Real-IP
- internal errors sanitized to fixed client messages

FIXES:
- int64 precision loss: /cell data decoded from raw JSON bytes and
  responses serialized with json.Number (no float64 round-trip)
- enum values range-checked before uint8 conversion (256 no longer
  truncates to 0 and slips through)
- logger: files failing name parsing are no longer deleted; log channel
  never blocks request goroutines; ConfigLogger is race-free;
  logWriterWorker unlock bug fixed
- stream writer panics recovered (process no longer crashes);
  streamDone closed exactly once
- generated Go client emits definitions for pointer-to-enum/struct fields
- anonymous structs rejected at registration; isPrivate safe on empty names
- removed dead Result.Id and RequestInfo.Type

ADDITIONS:
- graceful shutdown (Shutdown), StartOn, server timeouts by default
  (Read 60s/Idle 120s/Write off), SetTimeouts/SetMaxConcurrency
- big-int-safe JSON in the generated TS client (>2^53 as BigInt)
- example/ demo services and cmd/genexample artifact generator
This commit is contained in:
2026-09-03 15:32:07 +08:00
parent 9019798382
commit 41df889a1a
24 changed files with 1356 additions and 214 deletions
+7 -1
View File
@@ -12,7 +12,6 @@ const (
)
type Result[T any] struct {
Id string `json:"id,omitempty"`
Code *uint16 `json:"code,omitempty"`
Data *T `json:"data,omitempty"`
Msg *string `json:"msg,omitempty"`
@@ -40,6 +39,13 @@ func callError(err error) Result[any] {
return Result[any]{Msg: new(err.Error()), Status: cellErrorCode}
}
// internalError 框架内部错误脱敏:客户端只收到固定提示,
// 完整错误(JSON 解析细节、Go 类型名等)记服务端日志,不外泄
func internalError(clientMsg string, err error) Result[any] {
ErrorLogger("fun: internal error: ", err.Error())
return Result[any]{Msg: &clientMsg, Status: cellErrorCode}
}
// success 构造成功响应,空切片规范化为 [] 而不是 null
func success(data any) Result[any] {
return Result[any]{Data: nonNil(data), Status: successCode}