From 37d435fb746482eb85aa815dbe1258aee5bb45e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=8F=AF?= Date: Tue, 22 Oct 2024 14:53:04 +0800 Subject: [PATCH] feat: add full method name in generated code --- cmd/kod/internal/generate_generator.go | 46 +- examples/helloworld/kod_gen.go | 106 ++--- interceptor/interceptor.go | 4 +- interceptor/interceptor_test.go | 4 +- interceptor/kaccesslog/accesslog.go | 2 +- interceptor/kmetric/metric.go | 2 +- tests/case1/kod_gen.go | 562 +++++++++++++------------ tests/case2/kod_gen.go | 73 ++-- tests/case3/kod_gen.go | 84 ++-- tests/case4/kod_gen.go | 84 ++-- tests/case5/kod_gen.go | 3 + tests/graphcase/kod_gen.go | 194 +++++---- 12 files changed, 626 insertions(+), 538 deletions(-) diff --git a/cmd/kod/internal/generate_generator.go b/cmd/kod/internal/generate_generator.go index 4e18003..ea49f3d 100644 --- a/cmd/kod/internal/generate_generator.go +++ b/cmd/kod/internal/generate_generator.go @@ -157,8 +157,9 @@ func newGenerator(opt Options, pkg *packages.Package, fset *token.FileSet) (*gen // kod.AutoMarshal struct. tset := newTypeSet(pkg) - // Find and process all components. - components := map[string]*component{} + // Find and process all seen. + seen := map[string]*component{} + components := []*component{} for _, file := range pkg.Syntax { filename := fset.Position(file.Package).Filename if filepath.Base(filename) == generatedCodeFile { @@ -179,25 +180,28 @@ func newGenerator(opt Options, pkg *packages.Package, fset *token.FileSet) (*gen // This code relies on the fact that a component // interface and component implementation have to be in the same // package. If we lift this requirement, then this code will break. - if existing, ok := components[c.fullIntfName()]; ok { + if existing, ok := seen[c.fullIntfName()]; ok { errs = append(errs, errorf(pkg.Fset, c.impl.Obj().Pos(), "Duplicate implementation for component %s, other declaration: %v", c.fullIntfName(), fset.Position(existing.impl.Obj().Pos()))) continue } - components[c.fullIntfName()] = c + seen[c.fullIntfName()] = c + components = append(components, c) } } if err := errors.Join(errs...); err != nil { return nil, err } + // slices.Reverse(components) + return &generator{ opt: opt, pkg: pkg, tset: tset, fileset: fset, - components: lo.Values(components), + components: components, }, nil } @@ -393,6 +397,10 @@ func (c *component) intfName() string { return c.intf.Obj().Name() } +func (c *component) fullMethodNameVar(methodName string) string { + return fmt.Sprintf("%s_%s_FullMethodName", c.intfName(), methodName) +} + // implName returns the component implementation name. func (c *component) implName() string { return c.impl.Obj().Name() @@ -549,10 +557,10 @@ func (g *generator) generate() error { return nil } - // Process components in deterministic order. - sort.Slice(g.components, func(i, j int) bool { - return g.components[i].intfName() < g.components[j].intfName() - }) + // // Process components in deterministic order. + // sort.Slice(g.components, func(i, j int) bool { + // return g.components[i].intfName() < g.components[j].intfName() + // }) // Generate the file body. var body bytes.Buffer @@ -574,7 +582,9 @@ func (g *generator) generate() error { fn := func(format string, args ...interface{}) { fmt.Fprintln(&header, fmt.Sprintf(format, args...)) } + g.generateImports(fn) + g.generateFullMethodNames(fn) } // Create a generated file. @@ -643,6 +653,19 @@ func (g *generator) generateImports(p printFn) { p(`)`) } +func (g *generator) generateFullMethodNames(p printFn) { + p(``) + p(`// Full method names for components.`) + p(`const (`) + for _, comp := range g.components { + for _, m := range comp.methods() { + p(`// %s is the full name of the method [%s.%s].`, comp.fullMethodNameVar(m.Name()), comp.implName(), m.Name()) + p(`%s = %q`, comp.fullMethodNameVar(m.Name()), comp.fullIntfName()) + } + } + p(`)`) +} + // generateInstanceChecks generates code that checks that every component // implementation type implements kod.InstanceOf[T] for the appropriate T. func (g *generator) generateInstanceChecks(p printFn) { @@ -798,10 +821,9 @@ func (g *generator) generateLocalStubs(p printFn) { p(`info := interceptor.CallInfo { Impl: s.impl, Component: s.name, - FullMethod: "%s.%s", - Method: "%s", + FullMethod: %s, } - `, comp.fullIntfName(), m.Name(), m.Name()) + `, comp.fullMethodNameVar(m.Name())) p(`%s = s.interceptor(ctx, info, []any{%s}, []any{%s}, call)`, lo.If(haveError(mt), "err").Else("_"), diff --git a/examples/helloworld/kod_gen.go b/examples/helloworld/kod_gen.go index 91a6fc8..df2a469 100644 --- a/examples/helloworld/kod_gen.go +++ b/examples/helloworld/kod_gen.go @@ -10,12 +10,24 @@ import ( "reflect" ) +// Full method names for components. +const ( + // HelloWorld_SayHello_FullMethodName is the full name of the method [helloWorld.SayHello]. + HelloWorld_SayHello_FullMethodName = "github.com/go-kod/kod/examples/helloworld/HelloWorld" + // HelloWorldLazy_SayHello_FullMethodName is the full name of the method [lazyHelloWorld.SayHello]. + HelloWorldLazy_SayHello_FullMethodName = "github.com/go-kod/kod/examples/helloworld/HelloWorldLazy" + // HelloWorldInterceptor_SayHello_FullMethodName is the full name of the method [helloWorldInterceptor.SayHello]. + HelloWorldInterceptor_SayHello_FullMethodName = "github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor" +) + func init() { kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/examples/helloworld/HelloWorld", - Interface: reflect.TypeOf((*HelloWorld)(nil)).Elem(), - Impl: reflect.TypeOf(helloWorld{}), - Refs: ``, + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦bda493e9:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorld⟧, +⟦b60b3708:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorldLazy⟧, +⟦c811f6f3:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -24,17 +36,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return helloWorld_local_stub{ - impl: info.Impl.(HelloWorld), + return main_local_stub{ + impl: info.Impl.(kod.Main), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor", - Interface: reflect.TypeOf((*HelloWorldInterceptor)(nil)).Elem(), - Impl: reflect.TypeOf(helloWorldInterceptor{}), + Name: "github.com/go-kod/kod/examples/helloworld/HelloWorld", + Interface: reflect.TypeOf((*HelloWorld)(nil)).Elem(), + Impl: reflect.TypeOf(helloWorld{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -44,8 +56,8 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return helloWorldInterceptor_local_stub{ - impl: info.Impl.(HelloWorldInterceptor), + return helloWorld_local_stub{ + impl: info.Impl.(HelloWorld), interceptor: interceptor.Chain(interceptors), name: info.Name, } @@ -72,12 +84,10 @@ func init() { }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦bda493e9:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorld⟧, -⟦b60b3708:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorldLazy⟧, -⟦c811f6f3:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor⟧`, + Name: "github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor", + Interface: reflect.TypeOf((*HelloWorldInterceptor)(nil)).Elem(), + Impl: reflect.TypeOf(helloWorldInterceptor{}), + Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -86,8 +96,8 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return main_local_stub{ - impl: info.Impl.(kod.Main), + return helloWorldInterceptor_local_stub{ + impl: info.Impl.(HelloWorldInterceptor), interceptor: interceptor.Chain(interceptors), name: info.Name, } @@ -96,13 +106,23 @@ func init() { } // kod.InstanceOf checks. +var _ kod.InstanceOf[kod.Main] = (*App)(nil) var _ kod.InstanceOf[HelloWorld] = (*helloWorld)(nil) -var _ kod.InstanceOf[HelloWorldInterceptor] = (*helloWorldInterceptor)(nil) var _ kod.InstanceOf[HelloWorldLazy] = (*lazyHelloWorld)(nil) -var _ kod.InstanceOf[kod.Main] = (*App)(nil) +var _ kod.InstanceOf[HelloWorldInterceptor] = (*helloWorldInterceptor)(nil) // Local stub implementations. +// main_local_stub is a local stub implementation of [kod.Main]. +type main_local_stub struct { + impl kod.Main + name string + interceptor interceptor.Interceptor +} + +// Check that main_local_stub implements the kod.Main interface. +var _ kod.Main = (*main_local_stub)(nil) + // helloWorld_local_stub is a local stub implementation of [HelloWorld]. type helloWorld_local_stub struct { impl HelloWorld @@ -128,24 +148,23 @@ func (s helloWorld_local_stub) SayHello(ctx context.Context) { info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/examples/helloworld/HelloWorld.SayHello", - Method: "SayHello", + FullMethod: HelloWorld_SayHello_FullMethodName, } _ = s.interceptor(ctx, info, []any{}, []any{}, call) } -// helloWorldInterceptor_local_stub is a local stub implementation of [HelloWorldInterceptor]. -type helloWorldInterceptor_local_stub struct { - impl HelloWorldInterceptor +// helloWorldLazy_local_stub is a local stub implementation of [HelloWorldLazy]. +type helloWorldLazy_local_stub struct { + impl HelloWorldLazy name string interceptor interceptor.Interceptor } -// Check that helloWorldInterceptor_local_stub implements the HelloWorldInterceptor interface. -var _ HelloWorldInterceptor = (*helloWorldInterceptor_local_stub)(nil) +// Check that helloWorldLazy_local_stub implements the HelloWorldLazy interface. +var _ HelloWorldLazy = (*helloWorldLazy_local_stub)(nil) -func (s helloWorldInterceptor_local_stub) SayHello(ctx context.Context) { +func (s helloWorldLazy_local_stub) SayHello(ctx context.Context) { if s.interceptor == nil { s.impl.SayHello(ctx) @@ -160,24 +179,23 @@ func (s helloWorldInterceptor_local_stub) SayHello(ctx context.Context) { info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/examples/helloworld/HelloWorldInterceptor.SayHello", - Method: "SayHello", + FullMethod: HelloWorldLazy_SayHello_FullMethodName, } _ = s.interceptor(ctx, info, []any{}, []any{}, call) } -// helloWorldLazy_local_stub is a local stub implementation of [HelloWorldLazy]. -type helloWorldLazy_local_stub struct { - impl HelloWorldLazy +// helloWorldInterceptor_local_stub is a local stub implementation of [HelloWorldInterceptor]. +type helloWorldInterceptor_local_stub struct { + impl HelloWorldInterceptor name string interceptor interceptor.Interceptor } -// Check that helloWorldLazy_local_stub implements the HelloWorldLazy interface. -var _ HelloWorldLazy = (*helloWorldLazy_local_stub)(nil) +// Check that helloWorldInterceptor_local_stub implements the HelloWorldInterceptor interface. +var _ HelloWorldInterceptor = (*helloWorldInterceptor_local_stub)(nil) -func (s helloWorldLazy_local_stub) SayHello(ctx context.Context) { +func (s helloWorldInterceptor_local_stub) SayHello(ctx context.Context) { if s.interceptor == nil { s.impl.SayHello(ctx) @@ -192,20 +210,8 @@ func (s helloWorldLazy_local_stub) SayHello(ctx context.Context) { info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/examples/helloworld/HelloWorldLazy.SayHello", - Method: "SayHello", + FullMethod: HelloWorldInterceptor_SayHello_FullMethodName, } _ = s.interceptor(ctx, info, []any{}, []any{}, call) } - -// main_local_stub is a local stub implementation of [kod.Main]. -type main_local_stub struct { - impl kod.Main - name string - interceptor interceptor.Interceptor -} - -// Check that main_local_stub implements the kod.Main interface. -var _ kod.Main = (*main_local_stub)(nil) - diff --git a/interceptor/interceptor.go b/interceptor/interceptor.go index 894e390..fc29431 100644 --- a/interceptor/interceptor.go +++ b/interceptor/interceptor.go @@ -12,8 +12,6 @@ type CallInfo struct { Component string // The full name of the called method, in the format of "package/service.method". FullMethod string - // The name of the method. - Method string } // HandleFunc is the type of the function invoked by Components. @@ -102,6 +100,6 @@ func Not(condition Condition) Condition { // IsMethod returns a condition that checks if the method name matches the given method. func IsMethod(method string) Condition { return func(_ context.Context, info CallInfo) bool { - return info.Method == method + return info.FullMethod == method } } diff --git a/interceptor/interceptor_test.go b/interceptor/interceptor_test.go index 2d60ce7..31ec6e9 100644 --- a/interceptor/interceptor_test.go +++ b/interceptor/interceptor_test.go @@ -272,7 +272,7 @@ func TestIsMethod(t *testing.T) { name: "Method matches", method: "test", info: CallInfo{ - Method: "test", + FullMethod: "test", }, expected: true, }, @@ -280,7 +280,7 @@ func TestIsMethod(t *testing.T) { name: "Method does not match", method: "test", info: CallInfo{ - Method: "other", + FullMethod: "other", }, expected: false, }, diff --git a/interceptor/kaccesslog/accesslog.go b/interceptor/kaccesslog/accesslog.go index 2855499..1bf2228 100644 --- a/interceptor/kaccesslog/accesslog.go +++ b/interceptor/kaccesslog/accesslog.go @@ -19,7 +19,7 @@ func Interceptor() interceptor.Interceptor { attrs := []slog.Attr{ slog.Any("req", req), slog.Any("reply", reply), - slog.String("method", info.Method), + slog.String("method", info.FullMethod), slog.Int64("cost", time.Since(now).Milliseconds()), } diff --git a/interceptor/kmetric/metric.go b/interceptor/kmetric/metric.go index b24827d..67ca63e 100644 --- a/interceptor/kmetric/metric.go +++ b/interceptor/kmetric/metric.go @@ -37,7 +37,7 @@ func Interceptor() interceptor.Interceptor { as := attribute.NewSet( attribute.String("component", info.Component), - attribute.String("method", info.Method), + attribute.String("method", info.FullMethod), ) if err != nil { diff --git a/tests/case1/kod_gen.go b/tests/case1/kod_gen.go index ca60813..b9d14f1 100644 --- a/tests/case1/kod_gen.go +++ b/tests/case1/kod_gen.go @@ -13,12 +13,46 @@ import ( "reflect" ) +// Full method names for components. +const ( + // testService_Foo_FullMethodName is the full name of the method [serviceImpl.Foo]. + testService_Foo_FullMethodName = "github.com/go-kod/kod/tests/case1/testService" + // testRepository_Foo_FullMethodName is the full name of the method [modelImpl.Foo]. + testRepository_Foo_FullMethodName = "github.com/go-kod/kod/tests/case1/testRepository" + // Test1Component_Foo_FullMethodName is the full name of the method [test1Component.Foo]. + Test1Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case1/Test1Component" + // Test2Component_GetClient_FullMethodName is the full name of the method [test2Component.GetClient]. + Test2Component_GetClient_FullMethodName = "github.com/go-kod/kod/tests/case1/Test2Component" + // ctxInterface_Foo_FullMethodName is the full name of the method [ctxImpl.Foo]. + ctxInterface_Foo_FullMethodName = "github.com/go-kod/kod/tests/case1/ctxInterface" + // testEchoController_Error_FullMethodName is the full name of the method [testEchoControllerImpl.Error]. + testEchoController_Error_FullMethodName = "github.com/go-kod/kod/tests/case1/testEchoController" + // testEchoController_Hello_FullMethodName is the full name of the method [testEchoControllerImpl.Hello]. + testEchoController_Hello_FullMethodName = "github.com/go-kod/kod/tests/case1/testEchoController" + // testGinController_Hello_FullMethodName is the full name of the method [testGinControllerImpl.Hello]. + testGinController_Hello_FullMethodName = "github.com/go-kod/kod/tests/case1/testGinController" + // HTTPController_Foo_FullMethodName is the full name of the method [httpControllerImpl.Foo]. + HTTPController_Foo_FullMethodName = "github.com/go-kod/kod/tests/case1/HTTPController" + // InterceptorRetry_TestError_FullMethodName is the full name of the method [interceptorRetry.TestError]. + InterceptorRetry_TestError_FullMethodName = "github.com/go-kod/kod/tests/case1/InterceptorRetry" + // InterceptorRetry_TestNormal_FullMethodName is the full name of the method [interceptorRetry.TestNormal]. + InterceptorRetry_TestNormal_FullMethodName = "github.com/go-kod/kod/tests/case1/InterceptorRetry" + // LazyInitImpl_Try_FullMethodName is the full name of the method [lazyInitImpl.Try]. + LazyInitImpl_Try_FullMethodName = "github.com/go-kod/kod/tests/case1/LazyInitImpl" + // LazyInitComponent_Try_FullMethodName is the full name of the method [lazyInitComponent.Try]. + LazyInitComponent_Try_FullMethodName = "github.com/go-kod/kod/tests/case1/LazyInitComponent" + // panicCaseInterface_TestPanic_FullMethodName is the full name of the method [panicCase.TestPanic]. + panicCaseInterface_TestPanic_FullMethodName = "github.com/go-kod/kod/tests/case1/panicCaseInterface" + // panicNoRecvoeryCaseInterface_TestPanic_FullMethodName is the full name of the method [panicNoRecvoeryCase.TestPanic]. + panicNoRecvoeryCaseInterface_TestPanic_FullMethodName = "github.com/go-kod/kod/tests/case1/panicNoRecvoeryCaseInterface" +) + func init() { kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/HTTPController", - Interface: reflect.TypeOf((*HTTPController)(nil)).Elem(), - Impl: reflect.TypeOf(httpControllerImpl{}), - Refs: ``, + Name: "github.com/go-kod/kod/tests/case1/test1Controller", + Interface: reflect.TypeOf((*test1Controller)(nil)).Elem(), + Impl: reflect.TypeOf(test1ControllerImpl{}), + Refs: `⟦dd37e4d0:KoDeDgE:github.com/go-kod/kod/tests/case1/test1Controller→github.com/go-kod/kod/tests/case1/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -27,17 +61,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return hTTPController_local_stub{ - impl: info.Impl.(HTTPController), + return test1Controller_local_stub{ + impl: info.Impl.(test1Controller), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/InterceptorRetry", - Interface: reflect.TypeOf((*InterceptorRetry)(nil)).Elem(), - Impl: reflect.TypeOf(interceptorRetry{}), + Name: "github.com/go-kod/kod/tests/case1/testService", + Interface: reflect.TypeOf((*testService)(nil)).Elem(), + Impl: reflect.TypeOf(serviceImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -47,17 +81,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return interceptorRetry_local_stub{ - impl: info.Impl.(InterceptorRetry), + return testService_local_stub{ + impl: info.Impl.(testService), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/LazyInitComponent", - Interface: reflect.TypeOf((*LazyInitComponent)(nil)).Elem(), - Impl: reflect.TypeOf(lazyInitComponent{}), + Name: "github.com/go-kod/kod/tests/case1/testRepository", + Interface: reflect.TypeOf((*testRepository)(nil)).Elem(), + Impl: reflect.TypeOf(modelImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -67,18 +101,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return lazyInitComponent_local_stub{ - impl: info.Impl.(LazyInitComponent), + return testRepository_local_stub{ + impl: info.Impl.(testRepository), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/LazyInitImpl", - Interface: reflect.TypeOf((*LazyInitImpl)(nil)).Elem(), - Impl: reflect.TypeOf(lazyInitImpl{}), - Refs: `⟦8e153348:KoDeDgE:github.com/go-kod/kod/tests/case1/LazyInitImpl→github.com/go-kod/kod/tests/case1/LazyInitComponent⟧`, + Name: "github.com/go-kod/kod/tests/case1/Test1Component", + Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), + Impl: reflect.TypeOf(test1Component{}), + Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -87,18 +121,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return lazyInitImpl_local_stub{ - impl: info.Impl.(LazyInitImpl), + return test1Component_local_stub{ + impl: info.Impl.(Test1Component), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦d40a644a:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case1/Test1Component⟧`, + Name: "github.com/go-kod/kod/tests/case1/Test2Component", + Interface: reflect.TypeOf((*Test2Component)(nil)).Elem(), + Impl: reflect.TypeOf(test2Component{}), + Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -107,18 +141,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return main_local_stub{ - impl: info.Impl.(kod.Main), + return test2Component_local_stub{ + impl: info.Impl.(Test2Component), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/Test1Component", - Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), - Impl: reflect.TypeOf(test1Component{}), - Refs: ``, + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦d40a644a:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case1/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -127,17 +161,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test1Component_local_stub{ - impl: info.Impl.(Test1Component), + return main_local_stub{ + impl: info.Impl.(kod.Main), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/Test2Component", - Interface: reflect.TypeOf((*Test2Component)(nil)).Elem(), - Impl: reflect.TypeOf(test2Component{}), + Name: "github.com/go-kod/kod/tests/case1/ctxInterface", + Interface: reflect.TypeOf((*ctxInterface)(nil)).Elem(), + Impl: reflect.TypeOf(ctxImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -147,17 +181,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test2Component_local_stub{ - impl: info.Impl.(Test2Component), + return ctxInterface_local_stub{ + impl: info.Impl.(ctxInterface), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/ctxInterface", - Interface: reflect.TypeOf((*ctxInterface)(nil)).Elem(), - Impl: reflect.TypeOf(ctxImpl{}), + Name: "github.com/go-kod/kod/tests/case1/testEchoController", + Interface: reflect.TypeOf((*testEchoController)(nil)).Elem(), + Impl: reflect.TypeOf(testEchoControllerImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -167,17 +201,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return ctxInterface_local_stub{ - impl: info.Impl.(ctxInterface), + return testEchoController_local_stub{ + impl: info.Impl.(testEchoController), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/panicCaseInterface", - Interface: reflect.TypeOf((*panicCaseInterface)(nil)).Elem(), - Impl: reflect.TypeOf(panicCase{}), + Name: "github.com/go-kod/kod/tests/case1/testGinController", + Interface: reflect.TypeOf((*testGinController)(nil)).Elem(), + Impl: reflect.TypeOf(testGinControllerImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -187,17 +221,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return panicCaseInterface_local_stub{ - impl: info.Impl.(panicCaseInterface), + return testGinController_local_stub{ + impl: info.Impl.(testGinController), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/panicNoRecvoeryCaseInterface", - Interface: reflect.TypeOf((*panicNoRecvoeryCaseInterface)(nil)).Elem(), - Impl: reflect.TypeOf(panicNoRecvoeryCase{}), + Name: "github.com/go-kod/kod/tests/case1/HTTPController", + Interface: reflect.TypeOf((*HTTPController)(nil)).Elem(), + Impl: reflect.TypeOf(httpControllerImpl{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -207,18 +241,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return panicNoRecvoeryCaseInterface_local_stub{ - impl: info.Impl.(panicNoRecvoeryCaseInterface), + return hTTPController_local_stub{ + impl: info.Impl.(HTTPController), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/test1Controller", - Interface: reflect.TypeOf((*test1Controller)(nil)).Elem(), - Impl: reflect.TypeOf(test1ControllerImpl{}), - Refs: `⟦dd37e4d0:KoDeDgE:github.com/go-kod/kod/tests/case1/test1Controller→github.com/go-kod/kod/tests/case1/Test1Component⟧`, + Name: "github.com/go-kod/kod/tests/case1/InterceptorRetry", + Interface: reflect.TypeOf((*InterceptorRetry)(nil)).Elem(), + Impl: reflect.TypeOf(interceptorRetry{}), + Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -227,18 +261,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test1Controller_local_stub{ - impl: info.Impl.(test1Controller), + return interceptorRetry_local_stub{ + impl: info.Impl.(InterceptorRetry), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/testEchoController", - Interface: reflect.TypeOf((*testEchoController)(nil)).Elem(), - Impl: reflect.TypeOf(testEchoControllerImpl{}), - Refs: ``, + Name: "github.com/go-kod/kod/tests/case1/LazyInitImpl", + Interface: reflect.TypeOf((*LazyInitImpl)(nil)).Elem(), + Impl: reflect.TypeOf(lazyInitImpl{}), + Refs: `⟦8e153348:KoDeDgE:github.com/go-kod/kod/tests/case1/LazyInitImpl→github.com/go-kod/kod/tests/case1/LazyInitComponent⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -247,17 +281,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testEchoController_local_stub{ - impl: info.Impl.(testEchoController), + return lazyInitImpl_local_stub{ + impl: info.Impl.(LazyInitImpl), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/testGinController", - Interface: reflect.TypeOf((*testGinController)(nil)).Elem(), - Impl: reflect.TypeOf(testGinControllerImpl{}), + Name: "github.com/go-kod/kod/tests/case1/LazyInitComponent", + Interface: reflect.TypeOf((*LazyInitComponent)(nil)).Elem(), + Impl: reflect.TypeOf(lazyInitComponent{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -267,17 +301,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testGinController_local_stub{ - impl: info.Impl.(testGinController), + return lazyInitComponent_local_stub{ + impl: info.Impl.(LazyInitComponent), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/testRepository", - Interface: reflect.TypeOf((*testRepository)(nil)).Elem(), - Impl: reflect.TypeOf(modelImpl{}), + Name: "github.com/go-kod/kod/tests/case1/panicCaseInterface", + Interface: reflect.TypeOf((*panicCaseInterface)(nil)).Elem(), + Impl: reflect.TypeOf(panicCase{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -287,17 +321,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testRepository_local_stub{ - impl: info.Impl.(testRepository), + return panicCaseInterface_local_stub{ + impl: info.Impl.(panicCaseInterface), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case1/testService", - Interface: reflect.TypeOf((*testService)(nil)).Elem(), - Impl: reflect.TypeOf(serviceImpl{}), + Name: "github.com/go-kod/kod/tests/case1/panicNoRecvoeryCaseInterface", + Interface: reflect.TypeOf((*panicNoRecvoeryCaseInterface)(nil)).Elem(), + Impl: reflect.TypeOf(panicNoRecvoeryCase{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -307,8 +341,8 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testService_local_stub{ - impl: info.Impl.(testService), + return panicNoRecvoeryCaseInterface_local_stub{ + impl: info.Impl.(panicNoRecvoeryCaseInterface), interceptor: interceptor.Chain(interceptors), name: info.Name, } @@ -317,159 +351,145 @@ func init() { } // kod.InstanceOf checks. -var _ kod.InstanceOf[HTTPController] = (*httpControllerImpl)(nil) -var _ kod.InstanceOf[InterceptorRetry] = (*interceptorRetry)(nil) -var _ kod.InstanceOf[LazyInitComponent] = (*lazyInitComponent)(nil) -var _ kod.InstanceOf[LazyInitImpl] = (*lazyInitImpl)(nil) -var _ kod.InstanceOf[kod.Main] = (*App)(nil) +var _ kod.InstanceOf[test1Controller] = (*test1ControllerImpl)(nil) +var _ kod.InstanceOf[testService] = (*serviceImpl)(nil) +var _ kod.InstanceOf[testRepository] = (*modelImpl)(nil) var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) var _ kod.InstanceOf[Test2Component] = (*test2Component)(nil) +var _ kod.InstanceOf[kod.Main] = (*App)(nil) var _ kod.InstanceOf[ctxInterface] = (*ctxImpl)(nil) -var _ kod.InstanceOf[panicCaseInterface] = (*panicCase)(nil) -var _ kod.InstanceOf[panicNoRecvoeryCaseInterface] = (*panicNoRecvoeryCase)(nil) -var _ kod.InstanceOf[test1Controller] = (*test1ControllerImpl)(nil) var _ kod.InstanceOf[testEchoController] = (*testEchoControllerImpl)(nil) var _ kod.InstanceOf[testGinController] = (*testGinControllerImpl)(nil) -var _ kod.InstanceOf[testRepository] = (*modelImpl)(nil) -var _ kod.InstanceOf[testService] = (*serviceImpl)(nil) +var _ kod.InstanceOf[HTTPController] = (*httpControllerImpl)(nil) +var _ kod.InstanceOf[InterceptorRetry] = (*interceptorRetry)(nil) +var _ kod.InstanceOf[LazyInitImpl] = (*lazyInitImpl)(nil) +var _ kod.InstanceOf[LazyInitComponent] = (*lazyInitComponent)(nil) +var _ kod.InstanceOf[panicCaseInterface] = (*panicCase)(nil) +var _ kod.InstanceOf[panicNoRecvoeryCaseInterface] = (*panicNoRecvoeryCase)(nil) // Local stub implementations. -// hTTPController_local_stub is a local stub implementation of [HTTPController]. -type hTTPController_local_stub struct { - impl HTTPController +// test1Controller_local_stub is a local stub implementation of [test1Controller]. +type test1Controller_local_stub struct { + impl test1Controller name string interceptor interceptor.Interceptor } -// Check that hTTPController_local_stub implements the HTTPController interface. -var _ HTTPController = (*hTTPController_local_stub)(nil) - -func (s hTTPController_local_stub) Foo(a0 http.ResponseWriter, a1 *http.Request) { - // Because the first argument is not context.Context, so interceptors are not supported. - s.impl.Foo(a0, a1) - return -} +// Check that test1Controller_local_stub implements the test1Controller interface. +var _ test1Controller = (*test1Controller_local_stub)(nil) -// interceptorRetry_local_stub is a local stub implementation of [InterceptorRetry]. -type interceptorRetry_local_stub struct { - impl InterceptorRetry +// testService_local_stub is a local stub implementation of [testService]. +type testService_local_stub struct { + impl testService name string interceptor interceptor.Interceptor } -// Check that interceptorRetry_local_stub implements the InterceptorRetry interface. -var _ InterceptorRetry = (*interceptorRetry_local_stub)(nil) +// Check that testService_local_stub implements the testService interface. +var _ testService = (*testService_local_stub)(nil) -func (s interceptorRetry_local_stub) TestError(ctx context.Context) (err error) { +func (s testService_local_stub) Foo(ctx context.Context) (err error) { if s.interceptor == nil { - err = s.impl.TestError(ctx) + err = s.impl.Foo(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.TestError(ctx) + err = s.impl.Foo(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/InterceptorRetry.TestError", - Method: "TestError", + FullMethod: testService_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{}, []any{}, call) return } -func (s interceptorRetry_local_stub) TestNormal(ctx context.Context) (err error) { +// testRepository_local_stub is a local stub implementation of [testRepository]. +type testRepository_local_stub struct { + impl testRepository + name string + interceptor interceptor.Interceptor +} + +// Check that testRepository_local_stub implements the testRepository interface. +var _ testRepository = (*testRepository_local_stub)(nil) + +func (s testRepository_local_stub) Foo(ctx context.Context) (err error) { if s.interceptor == nil { - err = s.impl.TestNormal(ctx) + err = s.impl.Foo(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.TestNormal(ctx) + err = s.impl.Foo(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/InterceptorRetry.TestNormal", - Method: "TestNormal", + FullMethod: testRepository_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{}, []any{}, call) return } -// lazyInitComponent_local_stub is a local stub implementation of [LazyInitComponent]. -type lazyInitComponent_local_stub struct { - impl LazyInitComponent +// test1Component_local_stub is a local stub implementation of [Test1Component]. +type test1Component_local_stub struct { + impl Test1Component name string interceptor interceptor.Interceptor } -// Check that lazyInitComponent_local_stub implements the LazyInitComponent interface. -var _ LazyInitComponent = (*lazyInitComponent_local_stub)(nil) +// Check that test1Component_local_stub implements the Test1Component interface. +var _ Test1Component = (*test1Component_local_stub)(nil) -func (s lazyInitComponent_local_stub) Try(ctx context.Context) (err error) { +func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (r0 *FooRes, err error) { if s.interceptor == nil { - err = s.impl.Try(ctx) + r0, err = s.impl.Foo(ctx, a1) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.Try(ctx) + r0, err = s.impl.Foo(ctx, a1) + res[0] = r0 return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/LazyInitComponent.Try", - Method: "Try", + FullMethod: Test1Component_Foo_FullMethodName, } - err = s.interceptor(ctx, info, []any{}, []any{}, call) + err = s.interceptor(ctx, info, []any{a1}, []any{r0}, call) return } -// lazyInitImpl_local_stub is a local stub implementation of [LazyInitImpl]. -type lazyInitImpl_local_stub struct { - impl LazyInitImpl +// test2Component_local_stub is a local stub implementation of [Test2Component]. +type test2Component_local_stub struct { + impl Test2Component name string interceptor interceptor.Interceptor } -// Check that lazyInitImpl_local_stub implements the LazyInitImpl interface. -var _ LazyInitImpl = (*lazyInitImpl_local_stub)(nil) - -func (s lazyInitImpl_local_stub) Try(ctx context.Context) { - - if s.interceptor == nil { - s.impl.Try(ctx) - return - } - - call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - s.impl.Try(ctx) - return - } - - info := interceptor.CallInfo{ - Impl: s.impl, - Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/LazyInitImpl.Try", - Method: "Try", - } +// Check that test2Component_local_stub implements the Test2Component interface. +var _ Test2Component = (*test2Component_local_stub)(nil) - _ = s.interceptor(ctx, info, []any{}, []any{}, call) +func (s test2Component_local_stub) GetClient() (r0 *http.Client) { + // Because the first argument is not context.Context, so interceptors are not supported. + r0 = s.impl.GetClient() + return } // main_local_stub is a local stub implementation of [kod.Main]. @@ -482,262 +502,266 @@ type main_local_stub struct { // Check that main_local_stub implements the kod.Main interface. var _ kod.Main = (*main_local_stub)(nil) -// test1Component_local_stub is a local stub implementation of [Test1Component]. -type test1Component_local_stub struct { - impl Test1Component +// ctxInterface_local_stub is a local stub implementation of [ctxInterface]. +type ctxInterface_local_stub struct { + impl ctxInterface name string interceptor interceptor.Interceptor } -// Check that test1Component_local_stub implements the Test1Component interface. -var _ Test1Component = (*test1Component_local_stub)(nil) +// Check that ctxInterface_local_stub implements the ctxInterface interface. +var _ ctxInterface = (*ctxInterface_local_stub)(nil) -func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (r0 *FooRes, err error) { +func (s ctxInterface_local_stub) Foo(ctx context.Context) { if s.interceptor == nil { - r0, err = s.impl.Foo(ctx, a1) + s.impl.Foo(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - r0, err = s.impl.Foo(ctx, a1) - res[0] = r0 + s.impl.Foo(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/Test1Component.Foo", - Method: "Foo", + FullMethod: ctxInterface_Foo_FullMethodName, } - err = s.interceptor(ctx, info, []any{a1}, []any{r0}, call) + _ = s.interceptor(ctx, info, []any{}, []any{}, call) +} + +// testEchoController_local_stub is a local stub implementation of [testEchoController]. +type testEchoController_local_stub struct { + impl testEchoController + name string + interceptor interceptor.Interceptor +} + +// Check that testEchoController_local_stub implements the testEchoController interface. +var _ testEchoController = (*testEchoController_local_stub)(nil) + +func (s testEchoController_local_stub) Error(a0 echo.Context) (err error) { + // Because the first argument is not context.Context, so interceptors are not supported. + err = s.impl.Error(a0) return } -// test2Component_local_stub is a local stub implementation of [Test2Component]. -type test2Component_local_stub struct { - impl Test2Component +func (s testEchoController_local_stub) Hello(a0 echo.Context) (err error) { + // Because the first argument is not context.Context, so interceptors are not supported. + err = s.impl.Hello(a0) + return +} + +// testGinController_local_stub is a local stub implementation of [testGinController]. +type testGinController_local_stub struct { + impl testGinController name string interceptor interceptor.Interceptor } -// Check that test2Component_local_stub implements the Test2Component interface. -var _ Test2Component = (*test2Component_local_stub)(nil) +// Check that testGinController_local_stub implements the testGinController interface. +var _ testGinController = (*testGinController_local_stub)(nil) -func (s test2Component_local_stub) GetClient() (r0 *http.Client) { +func (s testGinController_local_stub) Hello(a0 *gin.Context) { // Because the first argument is not context.Context, so interceptors are not supported. - r0 = s.impl.GetClient() + s.impl.Hello(a0) return } -// ctxInterface_local_stub is a local stub implementation of [ctxInterface]. -type ctxInterface_local_stub struct { - impl ctxInterface +// hTTPController_local_stub is a local stub implementation of [HTTPController]. +type hTTPController_local_stub struct { + impl HTTPController name string interceptor interceptor.Interceptor } -// Check that ctxInterface_local_stub implements the ctxInterface interface. -var _ ctxInterface = (*ctxInterface_local_stub)(nil) +// Check that hTTPController_local_stub implements the HTTPController interface. +var _ HTTPController = (*hTTPController_local_stub)(nil) -func (s ctxInterface_local_stub) Foo(ctx context.Context) { +func (s hTTPController_local_stub) Foo(a0 http.ResponseWriter, a1 *http.Request) { + // Because the first argument is not context.Context, so interceptors are not supported. + s.impl.Foo(a0, a1) + return +} + +// interceptorRetry_local_stub is a local stub implementation of [InterceptorRetry]. +type interceptorRetry_local_stub struct { + impl InterceptorRetry + name string + interceptor interceptor.Interceptor +} + +// Check that interceptorRetry_local_stub implements the InterceptorRetry interface. +var _ InterceptorRetry = (*interceptorRetry_local_stub)(nil) + +func (s interceptorRetry_local_stub) TestError(ctx context.Context) (err error) { if s.interceptor == nil { - s.impl.Foo(ctx) + err = s.impl.TestError(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - s.impl.Foo(ctx) + err = s.impl.TestError(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/ctxInterface.Foo", - Method: "Foo", + FullMethod: InterceptorRetry_TestError_FullMethodName, } - _ = s.interceptor(ctx, info, []any{}, []any{}, call) -} - -// panicCaseInterface_local_stub is a local stub implementation of [panicCaseInterface]. -type panicCaseInterface_local_stub struct { - impl panicCaseInterface - name string - interceptor interceptor.Interceptor + err = s.interceptor(ctx, info, []any{}, []any{}, call) + return } -// Check that panicCaseInterface_local_stub implements the panicCaseInterface interface. -var _ panicCaseInterface = (*panicCaseInterface_local_stub)(nil) - -func (s panicCaseInterface_local_stub) TestPanic(ctx context.Context) { +func (s interceptorRetry_local_stub) TestNormal(ctx context.Context) (err error) { if s.interceptor == nil { - s.impl.TestPanic(ctx) + err = s.impl.TestNormal(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - s.impl.TestPanic(ctx) + err = s.impl.TestNormal(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/panicCaseInterface.TestPanic", - Method: "TestPanic", + FullMethod: InterceptorRetry_TestNormal_FullMethodName, } - _ = s.interceptor(ctx, info, []any{}, []any{}, call) + err = s.interceptor(ctx, info, []any{}, []any{}, call) + return } -// panicNoRecvoeryCaseInterface_local_stub is a local stub implementation of [panicNoRecvoeryCaseInterface]. -type panicNoRecvoeryCaseInterface_local_stub struct { - impl panicNoRecvoeryCaseInterface +// lazyInitImpl_local_stub is a local stub implementation of [LazyInitImpl]. +type lazyInitImpl_local_stub struct { + impl LazyInitImpl name string interceptor interceptor.Interceptor } -// Check that panicNoRecvoeryCaseInterface_local_stub implements the panicNoRecvoeryCaseInterface interface. -var _ panicNoRecvoeryCaseInterface = (*panicNoRecvoeryCaseInterface_local_stub)(nil) +// Check that lazyInitImpl_local_stub implements the LazyInitImpl interface. +var _ LazyInitImpl = (*lazyInitImpl_local_stub)(nil) -func (s panicNoRecvoeryCaseInterface_local_stub) TestPanic(ctx context.Context) { +func (s lazyInitImpl_local_stub) Try(ctx context.Context) { if s.interceptor == nil { - s.impl.TestPanic(ctx) + s.impl.Try(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - s.impl.TestPanic(ctx) + s.impl.Try(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/panicNoRecvoeryCaseInterface.TestPanic", - Method: "TestPanic", + FullMethod: LazyInitImpl_Try_FullMethodName, } _ = s.interceptor(ctx, info, []any{}, []any{}, call) } -// test1Controller_local_stub is a local stub implementation of [test1Controller]. -type test1Controller_local_stub struct { - impl test1Controller - name string - interceptor interceptor.Interceptor -} - -// Check that test1Controller_local_stub implements the test1Controller interface. -var _ test1Controller = (*test1Controller_local_stub)(nil) - -// testEchoController_local_stub is a local stub implementation of [testEchoController]. -type testEchoController_local_stub struct { - impl testEchoController +// lazyInitComponent_local_stub is a local stub implementation of [LazyInitComponent]. +type lazyInitComponent_local_stub struct { + impl LazyInitComponent name string interceptor interceptor.Interceptor } -// Check that testEchoController_local_stub implements the testEchoController interface. -var _ testEchoController = (*testEchoController_local_stub)(nil) +// Check that lazyInitComponent_local_stub implements the LazyInitComponent interface. +var _ LazyInitComponent = (*lazyInitComponent_local_stub)(nil) -func (s testEchoController_local_stub) Error(a0 echo.Context) (err error) { - // Because the first argument is not context.Context, so interceptors are not supported. - err = s.impl.Error(a0) - return -} +func (s lazyInitComponent_local_stub) Try(ctx context.Context) (err error) { -func (s testEchoController_local_stub) Hello(a0 echo.Context) (err error) { - // Because the first argument is not context.Context, so interceptors are not supported. - err = s.impl.Hello(a0) - return -} + if s.interceptor == nil { + err = s.impl.Try(ctx) + return + } -// testGinController_local_stub is a local stub implementation of [testGinController]. -type testGinController_local_stub struct { - impl testGinController - name string - interceptor interceptor.Interceptor -} + call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { + err = s.impl.Try(ctx) + return + } -// Check that testGinController_local_stub implements the testGinController interface. -var _ testGinController = (*testGinController_local_stub)(nil) + info := interceptor.CallInfo{ + Impl: s.impl, + Component: s.name, + FullMethod: LazyInitComponent_Try_FullMethodName, + } -func (s testGinController_local_stub) Hello(a0 *gin.Context) { - // Because the first argument is not context.Context, so interceptors are not supported. - s.impl.Hello(a0) + err = s.interceptor(ctx, info, []any{}, []any{}, call) return } -// testRepository_local_stub is a local stub implementation of [testRepository]. -type testRepository_local_stub struct { - impl testRepository +// panicCaseInterface_local_stub is a local stub implementation of [panicCaseInterface]. +type panicCaseInterface_local_stub struct { + impl panicCaseInterface name string interceptor interceptor.Interceptor } -// Check that testRepository_local_stub implements the testRepository interface. -var _ testRepository = (*testRepository_local_stub)(nil) +// Check that panicCaseInterface_local_stub implements the panicCaseInterface interface. +var _ panicCaseInterface = (*panicCaseInterface_local_stub)(nil) -func (s testRepository_local_stub) Foo(ctx context.Context) (err error) { +func (s panicCaseInterface_local_stub) TestPanic(ctx context.Context) { if s.interceptor == nil { - err = s.impl.Foo(ctx) + s.impl.TestPanic(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.Foo(ctx) + s.impl.TestPanic(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/testRepository.Foo", - Method: "Foo", + FullMethod: panicCaseInterface_TestPanic_FullMethodName, } - err = s.interceptor(ctx, info, []any{}, []any{}, call) - return + _ = s.interceptor(ctx, info, []any{}, []any{}, call) } -// testService_local_stub is a local stub implementation of [testService]. -type testService_local_stub struct { - impl testService +// panicNoRecvoeryCaseInterface_local_stub is a local stub implementation of [panicNoRecvoeryCaseInterface]. +type panicNoRecvoeryCaseInterface_local_stub struct { + impl panicNoRecvoeryCaseInterface name string interceptor interceptor.Interceptor } -// Check that testService_local_stub implements the testService interface. -var _ testService = (*testService_local_stub)(nil) +// Check that panicNoRecvoeryCaseInterface_local_stub implements the panicNoRecvoeryCaseInterface interface. +var _ panicNoRecvoeryCaseInterface = (*panicNoRecvoeryCaseInterface_local_stub)(nil) -func (s testService_local_stub) Foo(ctx context.Context) (err error) { +func (s panicNoRecvoeryCaseInterface_local_stub) TestPanic(ctx context.Context) { if s.interceptor == nil { - err = s.impl.Foo(ctx) + s.impl.TestPanic(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.Foo(ctx) + s.impl.TestPanic(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case1/testService.Foo", - Method: "Foo", + FullMethod: panicNoRecvoeryCaseInterface_TestPanic_FullMethodName, } - err = s.interceptor(ctx, info, []any{}, []any{}, call) - return + _ = s.interceptor(ctx, info, []any{}, []any{}, call) } diff --git a/tests/case2/kod_gen.go b/tests/case2/kod_gen.go index 11a2906..5863582 100644 --- a/tests/case2/kod_gen.go +++ b/tests/case2/kod_gen.go @@ -10,12 +10,20 @@ import ( "reflect" ) +// Full method names for components. +const ( + // Test1Component_Foo_FullMethodName is the full name of the method [test1Component.Foo]. + Test1Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case2/Test1Component" + // Test2Component_Foo_FullMethodName is the full name of the method [test2Component.Foo]. + Test2Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case2/Test2Component" +) + func init() { kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦73dc6a0b:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case2/Test1Component⟧`, + Name: "github.com/go-kod/kod/tests/case2/Test1Component", + Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), + Impl: reflect.TypeOf(test1Component{}), + Refs: `⟦3dc9f060:KoDeDgE:github.com/go-kod/kod/tests/case2/Test1Component→github.com/go-kod/kod/tests/case2/Test2Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -24,18 +32,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return main_local_stub{ - impl: info.Impl.(kod.Main), + return test1Component_local_stub{ + impl: info.Impl.(Test1Component), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case2/Test1Component", - Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), - Impl: reflect.TypeOf(test1Component{}), - Refs: `⟦3dc9f060:KoDeDgE:github.com/go-kod/kod/tests/case2/Test1Component→github.com/go-kod/kod/tests/case2/Test2Component⟧`, + Name: "github.com/go-kod/kod/tests/case2/Test2Component", + Interface: reflect.TypeOf((*Test2Component)(nil)).Elem(), + Impl: reflect.TypeOf(test2Component{}), + Refs: `⟦1767cee9:KoDeDgE:github.com/go-kod/kod/tests/case2/Test2Component→github.com/go-kod/kod/tests/case2/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -44,18 +52,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test1Component_local_stub{ - impl: info.Impl.(Test1Component), + return test2Component_local_stub{ + impl: info.Impl.(Test2Component), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/case2/Test2Component", - Interface: reflect.TypeOf((*Test2Component)(nil)).Elem(), - Impl: reflect.TypeOf(test2Component{}), - Refs: `⟦1767cee9:KoDeDgE:github.com/go-kod/kod/tests/case2/Test2Component→github.com/go-kod/kod/tests/case2/Test1Component⟧`, + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦73dc6a0b:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case2/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -64,8 +72,8 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test2Component_local_stub{ - impl: info.Impl.(Test2Component), + return main_local_stub{ + impl: info.Impl.(kod.Main), interceptor: interceptor.Chain(interceptors), name: info.Name, } @@ -74,22 +82,12 @@ func init() { } // kod.InstanceOf checks. -var _ kod.InstanceOf[kod.Main] = (*App)(nil) var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) var _ kod.InstanceOf[Test2Component] = (*test2Component)(nil) +var _ kod.InstanceOf[kod.Main] = (*App)(nil) // Local stub implementations. -// main_local_stub is a local stub implementation of [kod.Main]. -type main_local_stub struct { - impl kod.Main - name string - interceptor interceptor.Interceptor -} - -// Check that main_local_stub implements the kod.Main interface. -var _ kod.Main = (*main_local_stub)(nil) - // test1Component_local_stub is a local stub implementation of [Test1Component]. type test1Component_local_stub struct { impl Test1Component @@ -115,8 +113,7 @@ func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case2/Test1Component.Foo", - Method: "Foo", + FullMethod: Test1Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) @@ -148,10 +145,20 @@ func (s test2Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case2/Test2Component.Foo", - Method: "Foo", + FullMethod: Test2Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) return } + +// main_local_stub is a local stub implementation of [kod.Main]. +type main_local_stub struct { + impl kod.Main + name string + interceptor interceptor.Interceptor +} + +// Check that main_local_stub implements the kod.Main interface. +var _ kod.Main = (*main_local_stub)(nil) + diff --git a/tests/case3/kod_gen.go b/tests/case3/kod_gen.go index 4bc4d89..4167b26 100644 --- a/tests/case3/kod_gen.go +++ b/tests/case3/kod_gen.go @@ -10,28 +10,17 @@ import ( "reflect" ) -func init() { - kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦964a80ec:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case3/Test1Component⟧, -⟦e679c332:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case3/Test2Component⟧`, - LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { - interceptors := info.Interceptors - if h, ok := info.Impl.(interface { - Interceptors() []interceptor.Interceptor - }); ok { - interceptors = append(interceptors, h.Interceptors()...) - } +// Full method names for components. +const ( + // Test1Component_Foo_FullMethodName is the full name of the method [test1Component.Foo]. + Test1Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case3/Test1Component" + // Test2Component_Foo_FullMethodName is the full name of the method [test2Component.Foo]. + Test2Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case3/Test2Component" + // Test3Component_Foo_FullMethodName is the full name of the method [test3Component.Foo]. + Test3Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case3/Test3Component" +) - return main_local_stub{ - impl: info.Impl.(kod.Main), - interceptor: interceptor.Chain(interceptors), - name: info.Name, - } - }, - }) +func init() { kod.Register(&kod.Registration{ Name: "github.com/go-kod/kod/tests/case3/Test1Component", Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), @@ -92,26 +81,37 @@ func init() { } }, }) + kod.Register(&kod.Registration{ + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦964a80ec:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case3/Test1Component⟧, +⟦e679c332:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case3/Test2Component⟧`, + LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { + interceptors := info.Interceptors + if h, ok := info.Impl.(interface { + Interceptors() []interceptor.Interceptor + }); ok { + interceptors = append(interceptors, h.Interceptors()...) + } + + return main_local_stub{ + impl: info.Impl.(kod.Main), + interceptor: interceptor.Chain(interceptors), + name: info.Name, + } + }, + }) } // kod.InstanceOf checks. -var _ kod.InstanceOf[kod.Main] = (*App)(nil) var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) var _ kod.InstanceOf[Test2Component] = (*test2Component)(nil) var _ kod.InstanceOf[Test3Component] = (*test3Component)(nil) +var _ kod.InstanceOf[kod.Main] = (*App)(nil) // Local stub implementations. -// main_local_stub is a local stub implementation of [kod.Main]. -type main_local_stub struct { - impl kod.Main - name string - interceptor interceptor.Interceptor -} - -// Check that main_local_stub implements the kod.Main interface. -var _ kod.Main = (*main_local_stub)(nil) - // test1Component_local_stub is a local stub implementation of [Test1Component]. type test1Component_local_stub struct { impl Test1Component @@ -137,8 +137,7 @@ func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case3/Test1Component.Foo", - Method: "Foo", + FullMethod: Test1Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) @@ -170,8 +169,7 @@ func (s test2Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case3/Test2Component.Foo", - Method: "Foo", + FullMethod: Test2Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) @@ -203,10 +201,20 @@ func (s test3Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case3/Test3Component.Foo", - Method: "Foo", + FullMethod: Test3Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) return } + +// main_local_stub is a local stub implementation of [kod.Main]. +type main_local_stub struct { + impl kod.Main + name string + interceptor interceptor.Interceptor +} + +// Check that main_local_stub implements the kod.Main interface. +var _ kod.Main = (*main_local_stub)(nil) + diff --git a/tests/case4/kod_gen.go b/tests/case4/kod_gen.go index 38a2aff..5a92c0c 100644 --- a/tests/case4/kod_gen.go +++ b/tests/case4/kod_gen.go @@ -10,28 +10,17 @@ import ( "reflect" ) -func init() { - kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦214d0158:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case4/Test1Component⟧, -⟦e43caa42:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case4/Test2Component⟧`, - LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { - interceptors := info.Interceptors - if h, ok := info.Impl.(interface { - Interceptors() []interceptor.Interceptor - }); ok { - interceptors = append(interceptors, h.Interceptors()...) - } +// Full method names for components. +const ( + // Test1Component_Foo_FullMethodName is the full name of the method [test1Component.Foo]. + Test1Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case4/Test1Component" + // Test2Component_Foo_FullMethodName is the full name of the method [test2Component.Foo]. + Test2Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case4/Test2Component" + // Test3Component_Foo_FullMethodName is the full name of the method [test3Component.Foo]. + Test3Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/case4/Test3Component" +) - return main_local_stub{ - impl: info.Impl.(kod.Main), - interceptor: interceptor.Chain(interceptors), - name: info.Name, - } - }, - }) +func init() { kod.Register(&kod.Registration{ Name: "github.com/go-kod/kod/tests/case4/Test1Component", Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), @@ -92,26 +81,37 @@ func init() { } }, }) + kod.Register(&kod.Registration{ + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦214d0158:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case4/Test1Component⟧, +⟦e43caa42:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/case4/Test2Component⟧`, + LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { + interceptors := info.Interceptors + if h, ok := info.Impl.(interface { + Interceptors() []interceptor.Interceptor + }); ok { + interceptors = append(interceptors, h.Interceptors()...) + } + + return main_local_stub{ + impl: info.Impl.(kod.Main), + interceptor: interceptor.Chain(interceptors), + name: info.Name, + } + }, + }) } // kod.InstanceOf checks. -var _ kod.InstanceOf[kod.Main] = (*App)(nil) var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) var _ kod.InstanceOf[Test2Component] = (*test2Component)(nil) var _ kod.InstanceOf[Test3Component] = (*test3Component)(nil) +var _ kod.InstanceOf[kod.Main] = (*App)(nil) // Local stub implementations. -// main_local_stub is a local stub implementation of [kod.Main]. -type main_local_stub struct { - impl kod.Main - name string - interceptor interceptor.Interceptor -} - -// Check that main_local_stub implements the kod.Main interface. -var _ kod.Main = (*main_local_stub)(nil) - // test1Component_local_stub is a local stub implementation of [Test1Component]. type test1Component_local_stub struct { impl Test1Component @@ -137,8 +137,7 @@ func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case4/Test1Component.Foo", - Method: "Foo", + FullMethod: Test1Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) @@ -170,8 +169,7 @@ func (s test2Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case4/Test2Component.Foo", - Method: "Foo", + FullMethod: Test2Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) @@ -203,10 +201,20 @@ func (s test3Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err err info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/case4/Test3Component.Foo", - Method: "Foo", + FullMethod: Test3Component_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{a1}, []any{}, call) return } + +// main_local_stub is a local stub implementation of [kod.Main]. +type main_local_stub struct { + impl kod.Main + name string + interceptor interceptor.Interceptor +} + +// Check that main_local_stub implements the kod.Main interface. +var _ kod.Main = (*main_local_stub)(nil) + diff --git a/tests/case5/kod_gen.go b/tests/case5/kod_gen.go index 88c73e0..d16523d 100644 --- a/tests/case5/kod_gen.go +++ b/tests/case5/kod_gen.go @@ -10,6 +10,9 @@ import ( "reflect" ) +// Full method names for components. +const () + func init() { kod.Register(&kod.Registration{ Name: "github.com/go-kod/kod/Main", diff --git a/tests/graphcase/kod_gen.go b/tests/graphcase/kod_gen.go index e3b00af..c08c389 100644 --- a/tests/graphcase/kod_gen.go +++ b/tests/graphcase/kod_gen.go @@ -12,12 +12,27 @@ import ( "reflect" ) +// Full method names for components. +const ( + // test1Controller_Foo_FullMethodName is the full name of the method [test1ControllerImpl.Foo]. + test1Controller_Foo_FullMethodName = "github.com/go-kod/kod/tests/graphcase/test1Controller" + // HTTPController_Foo_FullMethodName is the full name of the method [httpControllerImpl.Foo]. + HTTPController_Foo_FullMethodName = "github.com/go-kod/kod/tests/graphcase/HTTPController" + // testService_Foo_FullMethodName is the full name of the method [serviceImpl.Foo]. + testService_Foo_FullMethodName = "github.com/go-kod/kod/tests/graphcase/testService" + // testModel_Foo_FullMethodName is the full name of the method [modelImpl.Foo]. + testModel_Foo_FullMethodName = "github.com/go-kod/kod/tests/graphcase/testModel" + // Test1Component_Foo_FullMethodName is the full name of the method [test1Component.Foo]. + Test1Component_Foo_FullMethodName = "github.com/go-kod/kod/tests/graphcase/Test1Component" +) + func init() { kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/graphcase/HTTPController", - Interface: reflect.TypeOf((*HTTPController)(nil)).Elem(), - Impl: reflect.TypeOf(httpControllerImpl{}), - Refs: `⟦38b48264:KoDeDgE:github.com/go-kod/kod/tests/graphcase/HTTPController→github.com/go-kod/kod/tests/graphcase/testService⟧`, + Name: "github.com/go-kod/kod/tests/graphcase/test1Controller", + Interface: reflect.TypeOf((*test1Controller)(nil)).Elem(), + Impl: reflect.TypeOf(test1ControllerImpl{}), + Refs: `⟦54c533d5:KoDeDgE:github.com/go-kod/kod/tests/graphcase/test1Controller→github.com/go-kod/kod/tests/graphcase/HTTPController⟧, +⟦f932c69a:KoDeDgE:github.com/go-kod/kod/tests/graphcase/test1Controller→github.com/go-kod/kod/tests/graphcase/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -26,19 +41,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return hTTPController_local_stub{ - impl: info.Impl.(HTTPController), + return test1Controller_local_stub{ + impl: info.Impl.(test1Controller), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/Main", - Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), - Impl: reflect.TypeOf(App{}), - Refs: `⟦b628eb85:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/graphcase/test1Controller⟧, -⟦75680c21:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/graphcase/Test1Component⟧`, + Name: "github.com/go-kod/kod/tests/graphcase/HTTPController", + Interface: reflect.TypeOf((*HTTPController)(nil)).Elem(), + Impl: reflect.TypeOf(httpControllerImpl{}), + Refs: `⟦38b48264:KoDeDgE:github.com/go-kod/kod/tests/graphcase/HTTPController→github.com/go-kod/kod/tests/graphcase/testService⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -47,18 +61,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return main_local_stub{ - impl: info.Impl.(kod.Main), + return hTTPController_local_stub{ + impl: info.Impl.(HTTPController), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/graphcase/Test1Component", - Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), - Impl: reflect.TypeOf(test1Component{}), - Refs: ``, + Name: "github.com/go-kod/kod/tests/graphcase/testService", + Interface: reflect.TypeOf((*testService)(nil)).Elem(), + Impl: reflect.TypeOf(serviceImpl{}), + Refs: `⟦e691e13e:KoDeDgE:github.com/go-kod/kod/tests/graphcase/testService→github.com/go-kod/kod/tests/graphcase/testModel⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -67,19 +81,18 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test1Component_local_stub{ - impl: info.Impl.(Test1Component), + return testService_local_stub{ + impl: info.Impl.(testService), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/graphcase/test1Controller", - Interface: reflect.TypeOf((*test1Controller)(nil)).Elem(), - Impl: reflect.TypeOf(test1ControllerImpl{}), - Refs: `⟦54c533d5:KoDeDgE:github.com/go-kod/kod/tests/graphcase/test1Controller→github.com/go-kod/kod/tests/graphcase/HTTPController⟧, -⟦f932c69a:KoDeDgE:github.com/go-kod/kod/tests/graphcase/test1Controller→github.com/go-kod/kod/tests/graphcase/Test1Component⟧`, + Name: "github.com/go-kod/kod/tests/graphcase/testModel", + Interface: reflect.TypeOf((*testModel)(nil)).Elem(), + Impl: reflect.TypeOf(modelImpl{}), + Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -88,17 +101,17 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return test1Controller_local_stub{ - impl: info.Impl.(test1Controller), + return testModel_local_stub{ + impl: info.Impl.(testModel), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/graphcase/testModel", - Interface: reflect.TypeOf((*testModel)(nil)).Elem(), - Impl: reflect.TypeOf(modelImpl{}), + Name: "github.com/go-kod/kod/tests/graphcase/Test1Component", + Interface: reflect.TypeOf((*Test1Component)(nil)).Elem(), + Impl: reflect.TypeOf(test1Component{}), Refs: ``, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors @@ -108,18 +121,19 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testModel_local_stub{ - impl: info.Impl.(testModel), + return test1Component_local_stub{ + impl: info.Impl.(Test1Component), interceptor: interceptor.Chain(interceptors), name: info.Name, } }, }) kod.Register(&kod.Registration{ - Name: "github.com/go-kod/kod/tests/graphcase/testService", - Interface: reflect.TypeOf((*testService)(nil)).Elem(), - Impl: reflect.TypeOf(serviceImpl{}), - Refs: `⟦e691e13e:KoDeDgE:github.com/go-kod/kod/tests/graphcase/testService→github.com/go-kod/kod/tests/graphcase/testModel⟧`, + Name: "github.com/go-kod/kod/Main", + Interface: reflect.TypeOf((*kod.Main)(nil)).Elem(), + Impl: reflect.TypeOf(App{}), + Refs: `⟦b628eb85:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/graphcase/test1Controller⟧, +⟦75680c21:KoDeDgE:github.com/go-kod/kod/Main→github.com/go-kod/kod/tests/graphcase/Test1Component⟧`, LocalStubFn: func(ctx context.Context, info *kod.LocalStubFnInfo) any { interceptors := info.Interceptors if h, ok := info.Impl.(interface { @@ -128,8 +142,8 @@ func init() { interceptors = append(interceptors, h.Interceptors()...) } - return testService_local_stub{ - impl: info.Impl.(testService), + return main_local_stub{ + impl: info.Impl.(kod.Main), interceptor: interceptor.Chain(interceptors), name: info.Name, } @@ -138,15 +152,31 @@ func init() { } // kod.InstanceOf checks. -var _ kod.InstanceOf[HTTPController] = (*httpControllerImpl)(nil) -var _ kod.InstanceOf[kod.Main] = (*App)(nil) -var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) var _ kod.InstanceOf[test1Controller] = (*test1ControllerImpl)(nil) -var _ kod.InstanceOf[testModel] = (*modelImpl)(nil) +var _ kod.InstanceOf[HTTPController] = (*httpControllerImpl)(nil) var _ kod.InstanceOf[testService] = (*serviceImpl)(nil) +var _ kod.InstanceOf[testModel] = (*modelImpl)(nil) +var _ kod.InstanceOf[Test1Component] = (*test1Component)(nil) +var _ kod.InstanceOf[kod.Main] = (*App)(nil) // Local stub implementations. +// test1Controller_local_stub is a local stub implementation of [test1Controller]. +type test1Controller_local_stub struct { + impl test1Controller + name string + interceptor interceptor.Interceptor +} + +// Check that test1Controller_local_stub implements the test1Controller interface. +var _ test1Controller = (*test1Controller_local_stub)(nil) + +func (s test1Controller_local_stub) Foo(a0 *gin.Context) { + // Because the first argument is not context.Context, so interceptors are not supported. + s.impl.Foo(a0) + return +} + // hTTPController_local_stub is a local stub implementation of [HTTPController]. type hTTPController_local_stub struct { impl HTTPController @@ -163,62 +193,35 @@ func (s hTTPController_local_stub) Foo(a0 http.ResponseWriter, a1 http.Request) return } -// main_local_stub is a local stub implementation of [kod.Main]. -type main_local_stub struct { - impl kod.Main - name string - interceptor interceptor.Interceptor -} - -// Check that main_local_stub implements the kod.Main interface. -var _ kod.Main = (*main_local_stub)(nil) - -// test1Component_local_stub is a local stub implementation of [Test1Component]. -type test1Component_local_stub struct { - impl Test1Component +// testService_local_stub is a local stub implementation of [testService]. +type testService_local_stub struct { + impl testService name string interceptor interceptor.Interceptor } -// Check that test1Component_local_stub implements the Test1Component interface. -var _ Test1Component = (*test1Component_local_stub)(nil) +// Check that testService_local_stub implements the testService interface. +var _ testService = (*testService_local_stub)(nil) -func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err error) { +func (s testService_local_stub) Foo(ctx context.Context) (err error) { if s.interceptor == nil { - err = s.impl.Foo(ctx, a1) + err = s.impl.Foo(ctx) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.Foo(ctx, a1) + err = s.impl.Foo(ctx) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/graphcase/Test1Component.Foo", - Method: "Foo", + FullMethod: testService_Foo_FullMethodName, } - err = s.interceptor(ctx, info, []any{a1}, []any{}, call) - return -} - -// test1Controller_local_stub is a local stub implementation of [test1Controller]. -type test1Controller_local_stub struct { - impl test1Controller - name string - interceptor interceptor.Interceptor -} - -// Check that test1Controller_local_stub implements the test1Controller interface. -var _ test1Controller = (*test1Controller_local_stub)(nil) - -func (s test1Controller_local_stub) Foo(a0 *gin.Context) { - // Because the first argument is not context.Context, so interceptors are not supported. - s.impl.Foo(a0) + err = s.interceptor(ctx, info, []any{}, []any{}, call) return } @@ -247,43 +250,52 @@ func (s testModel_local_stub) Foo(ctx context.Context) (err error) { info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/graphcase/testModel.Foo", - Method: "Foo", + FullMethod: testModel_Foo_FullMethodName, } err = s.interceptor(ctx, info, []any{}, []any{}, call) return } -// testService_local_stub is a local stub implementation of [testService]. -type testService_local_stub struct { - impl testService +// test1Component_local_stub is a local stub implementation of [Test1Component]. +type test1Component_local_stub struct { + impl Test1Component name string interceptor interceptor.Interceptor } -// Check that testService_local_stub implements the testService interface. -var _ testService = (*testService_local_stub)(nil) +// Check that test1Component_local_stub implements the Test1Component interface. +var _ Test1Component = (*test1Component_local_stub)(nil) -func (s testService_local_stub) Foo(ctx context.Context) (err error) { +func (s test1Component_local_stub) Foo(ctx context.Context, a1 *FooReq) (err error) { if s.interceptor == nil { - err = s.impl.Foo(ctx) + err = s.impl.Foo(ctx, a1) return } call := func(ctx context.Context, info interceptor.CallInfo, req, res []any) (err error) { - err = s.impl.Foo(ctx) + err = s.impl.Foo(ctx, a1) return } info := interceptor.CallInfo{ Impl: s.impl, Component: s.name, - FullMethod: "github.com/go-kod/kod/tests/graphcase/testService.Foo", - Method: "Foo", + FullMethod: Test1Component_Foo_FullMethodName, } - err = s.interceptor(ctx, info, []any{}, []any{}, call) + err = s.interceptor(ctx, info, []any{a1}, []any{}, call) return } + +// main_local_stub is a local stub implementation of [kod.Main]. +type main_local_stub struct { + impl kod.Main + name string + interceptor interceptor.Interceptor +} + +// Check that main_local_stub implements the kod.Main interface. +var _ kod.Main = (*main_local_stub)(nil) +