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:
+18
-6
@@ -39,7 +39,9 @@ func (s *BugSvc) Ticker() (string, *Stream, error) {
|
||||
func bugInvoke(t *testing.T, method string, data map[string]any) (*Result[any], error) {
|
||||
t.Helper()
|
||||
f := New()
|
||||
f.BindService(&BugSvc{})
|
||||
if err := f.BindService(&BugSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if data == nil {
|
||||
data = map[string]any{}
|
||||
}
|
||||
@@ -76,7 +78,9 @@ func TestBugNullableEnum(t *testing.T) {
|
||||
// bug3: 含 () error 方法的代码生成不应 panic,且类型应生成为 Void/void
|
||||
func TestBugGenErrorOnly(t *testing.T) {
|
||||
isolateGeneratorGlobals(t)
|
||||
GetFun().BindService(&BugSvc{})
|
||||
if err := GetFun().BindService(&BugSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
SetOutput(t.TempDir())
|
||||
GenCode(GenGo{}, GenTs{})
|
||||
goSrc, err := os.ReadFile(filepath.Join(getDirectory(), "go", "bug_svc.go"))
|
||||
@@ -98,7 +102,9 @@ func TestBugGenErrorOnly(t *testing.T) {
|
||||
// bug4+5: 响应键应为小写;(T, stream, error) 的 T 应作为流的第一条消息下发
|
||||
func TestBugJsonKeysAndStreamFirst(t *testing.T) {
|
||||
f := New()
|
||||
f.BindService(&BugSvc{})
|
||||
if err := f.BindService(&BugSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go f.Start(39003)
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
|
||||
@@ -150,7 +156,9 @@ func (s *NullSlicSvc) Save(dto NullSlicDto) (string, error) { return "ok", nil }
|
||||
|
||||
func TestBugSliceNull(t *testing.T) {
|
||||
f := New()
|
||||
f.BindService(&NullSlicSvc{})
|
||||
if err := f.BindService(&NullSlicSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := map[string]any{"tags": nil}
|
||||
c := &Ctx{Ip: "1", MethodName: "Save", ServiceName: "NullSlicSvc", Data: &data}
|
||||
var streamCh chan any
|
||||
@@ -177,7 +185,9 @@ func (s *LeakSvc) Fail() (*Stream, error) {
|
||||
|
||||
func TestBugStreamLeak(t *testing.T) {
|
||||
f := New()
|
||||
f.BindService(&LeakSvc{})
|
||||
if err := f.BindService(&LeakSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &Ctx{Ip: "1", MethodName: "Fail", ServiceName: "LeakSvc"}
|
||||
var streamCh chan any
|
||||
var streamDone chan struct{}
|
||||
@@ -202,7 +212,9 @@ func (s *CollideSvc) Cookie() (string, error) { return "cookie", nil }
|
||||
|
||||
func TestBugMethodNameCollision(t *testing.T) {
|
||||
f := New()
|
||||
f.BindService(&CollideSvc{})
|
||||
if err := f.BindService(&CollideSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := f.methods["CollideSvc.Cookie"]; !ok {
|
||||
t.Fatal("Cookie method dropped due to name collision with fasthttp.RequestCtx")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user