From 273624dd1314d4d8afece6f873a7b07f57ad3475 Mon Sep 17 00:00:00 2001 From: Janishar Ali Date: Mon, 1 Jul 2024 03:57:08 +0530 Subject: [PATCH] add micro module support --- arch/micro/interfaces.go | 5 +++++ arch/micro/nats.go | 2 +- arch/micro/router.go | 2 +- arch/network/interfaces.go | 8 ++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/micro/interfaces.go b/arch/micro/interfaces.go index 0f4cf20..e781ca4 100644 --- a/arch/micro/interfaces.go +++ b/arch/micro/interfaces.go @@ -26,3 +26,8 @@ type Router interface { Disconnect() LoadControllers(controllers []Controller) } + +type Module[T any] interface { + network.BaseModule[T] + Controllers() []Controller +} diff --git a/arch/micro/nats.go b/arch/micro/nats.go index ad37628..5df670d 100644 --- a/arch/micro/nats.go +++ b/arch/micro/nats.go @@ -20,7 +20,7 @@ type NatsClient struct { Timeout time.Duration } -func NewNatsClient(config Config) *NatsClient { +func NewNatsClient(config *Config) *NatsClient { fmt.Println("connecting to nats..") nc, err := nats.Connect(config.NatsUrl) diff --git a/arch/micro/router.go b/arch/micro/router.go index b154ee1..8478380 100644 --- a/arch/micro/router.go +++ b/arch/micro/router.go @@ -14,7 +14,7 @@ type router struct { natsClient *NatsClient } -func NewRouter(mode string, config Config) Router { +func NewRouter(mode string, config *Config) Router { natsClient := NewNatsClient(config) return &router{ netRouter: network.NewRouter(mode), diff --git a/arch/network/interfaces.go b/arch/network/interfaces.go index 3e04a99..7af2357 100644 --- a/arch/network/interfaces.go +++ b/arch/network/interfaces.go @@ -113,10 +113,14 @@ type Router interface { LoadControllers(controllers []Controller) } -type Module[T any] interface { +type BaseModule[T any] interface { GetInstance() *T RootMiddlewares() []RootMiddleware - Controllers() []Controller AuthenticationProvider() AuthenticationProvider AuthorizationProvider() AuthorizationProvider } + +type Module[T any] interface { + BaseModule[T] + Controllers() []Controller +}