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:
+14
-5
@@ -29,8 +29,9 @@ var guardHit = false
|
||||
|
||||
type TestGuard struct{}
|
||||
|
||||
func (g *TestGuard) Guard(ctx Ctx) {
|
||||
func (g *TestGuard) Guard(ctx Ctx) error {
|
||||
guardHit = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TestSvc) Hello(dto TestDto) (string, error) {
|
||||
@@ -58,7 +59,9 @@ func (s *TestSvc) Count(dto TestDto) (*Stream, error) {
|
||||
func TestCtxBoxInject(t *testing.T) {
|
||||
f := New()
|
||||
guardHit = false
|
||||
f.BindService(&TestSvc{}, &TestGuard{})
|
||||
if err := f.BindService(&TestSvc{}, &TestGuard{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &Ctx{Ip: "1.2.3.4", MethodName: "Hello", ServiceName: "TestSvc"}
|
||||
data := map[string]any{"name": "tom", "age": 1}
|
||||
c.Data = &data
|
||||
@@ -79,7 +82,9 @@ func TestCtxBoxInject(t *testing.T) {
|
||||
|
||||
func TestCheckDtoRequired(t *testing.T) {
|
||||
f := New()
|
||||
f.BindService(&TestSvc{})
|
||||
if err := f.BindService(&TestSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &Ctx{Ip: "x", MethodName: "Hello", ServiceName: "TestSvc"}
|
||||
data := map[string]any{"age": 1}
|
||||
c.Data = &data
|
||||
@@ -94,7 +99,9 @@ func TestCheckDtoRequired(t *testing.T) {
|
||||
|
||||
func TestGenCode(t *testing.T) {
|
||||
isolateGeneratorGlobals(t)
|
||||
GetFun().BindService(&TestSvc{})
|
||||
if err := GetFun().BindService(&TestSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
SetOutput(t.TempDir())
|
||||
GenCode(GenGo{}, GenTs{})
|
||||
if _, err := os.Stat(filepath.Join(getDirectory(), "go", "test_svc.go")); err != nil {
|
||||
@@ -107,7 +114,9 @@ func TestGenCode(t *testing.T) {
|
||||
|
||||
func startServer(t *testing.T, port uint16) *Fun {
|
||||
f := New()
|
||||
f.BindService(&TestSvc{})
|
||||
if err := f.BindService(&TestSvc{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go f.Start(port)
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
return f
|
||||
|
||||
Reference in New Issue
Block a user