diff --git a/config/config.go b/config/config.go index 3da49e30..c21d0bec 100644 --- a/config/config.go +++ b/config/config.go @@ -45,7 +45,7 @@ type Config struct { Plugin PluginConfig } -var _ IConfig = &Config{} +var _ IConfig = (*Config)(nil) func NewConfig(ctx context.Context, globalConfigFile, pluginConfigFile string) *Config { _, span := otel.Tracer(TracerName).Start(ctx, "Create new config") diff --git a/metrics/merger.go b/metrics/merger.go index f311658c..7663a6a1 100644 --- a/metrics/merger.go +++ b/metrics/merger.go @@ -44,7 +44,7 @@ type Merger struct { OutputMetrics []byte } -var _ IMerger = &Merger{} +var _ IMerger = (*Merger)(nil) // NewMerger creates a new metrics merger. func NewMerger( diff --git a/network/client.go b/network/client.go index 1977df99..97bd0382 100644 --- a/network/client.go +++ b/network/client.go @@ -44,7 +44,7 @@ type Client struct { Address string } -var _ IClient = &Client{} +var _ IClient = (*Client)(nil) // NewClient creates a new client. func NewClient(ctx context.Context, clientConfig *config.Client, logger zerolog.Logger) *Client { diff --git a/network/conn_wrapper.go b/network/conn_wrapper.go index f221ab86..add7bf1e 100644 --- a/network/conn_wrapper.go +++ b/network/conn_wrapper.go @@ -37,7 +37,7 @@ type ConnWrapper struct { handshakeTimeout time.Duration } -var _ IConnWrapper = &ConnWrapper{} +var _ IConnWrapper = (*ConnWrapper)(nil) // Conn returns the underlying connection. func (cw *ConnWrapper) Conn() net.Conn { diff --git a/network/engine.go b/network/engine.go index 6f8192ee..a67d3d73 100644 --- a/network/engine.go +++ b/network/engine.go @@ -11,6 +11,11 @@ import ( "github.com/rs/zerolog" ) +type IEngine interface { + CountConnections() int + Stop(ctx context.Context) error +} + // Engine is the network engine. // TODO: Move this to the Server struct. type Engine struct { @@ -24,6 +29,8 @@ type Engine struct { mu *sync.RWMutex } +var _ IEngine = (*Engine)(nil) + // CountConnections returns the current number of connections. func (engine *Engine) CountConnections() int { engine.mu.RLock() diff --git a/network/proxy.go b/network/proxy.go index 1b2f56cc..adb6f028 100644 --- a/network/proxy.go +++ b/network/proxy.go @@ -49,7 +49,7 @@ type Proxy struct { ClientConfig *config.Client } -var _ IProxy = &Proxy{} +var _ IProxy = (*Proxy)(nil) // NewProxy creates a new proxy. func NewProxy( diff --git a/network/server.go b/network/server.go index 39aeca40..fb6da7aa 100644 --- a/network/server.go +++ b/network/server.go @@ -33,6 +33,18 @@ const ( Shutdown ) +type IServer interface { + OnBoot(engine Engine) Action + OnOpen(conn *ConnWrapper) ([]byte, Action) + OnClose(conn *ConnWrapper, err error) Action + OnTraffic(conn *ConnWrapper, stopConnection chan struct{}) Action + OnShutdown() + OnTick() (time.Duration, Action) + Run() *gerr.GatewayDError + Shutdown() + IsRunning() bool +} + type Server struct { engine Engine proxy IProxy @@ -55,6 +67,8 @@ type Server struct { HandshakeTimeout time.Duration } +var _ IServer = (*Server)(nil) + // OnBoot is called when the server is booted. It calls the OnBooting and OnBooted hooks. // It also sets the status to running, which is used to determine if the server should be running // or shutdown. diff --git a/plugin/plugin.go b/plugin/plugin.go index 12616798..d4a4964f 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -17,7 +17,7 @@ type IPlugin interface { Ping() *gerr.GatewayDError } -var _ IPlugin = &Plugin{} +var _ IPlugin = (*Plugin)(nil) // Start starts the plugin. func (p *Plugin) Start() (net.Addr, error) { diff --git a/plugin/plugin_registry.go b/plugin/plugin_registry.go index 27e52116..e42ffcde 100644 --- a/plugin/plugin_registry.go +++ b/plugin/plugin_registry.go @@ -64,7 +64,7 @@ type Registry struct { Termination config.TerminationPolicy } -var _ IRegistry = &Registry{} +var _ IRegistry = (*Registry)(nil) // NewRegistry creates a new plugin registry. func NewRegistry( diff --git a/pool/pool.go b/pool/pool.go index a87844d3..4e70087f 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -30,7 +30,7 @@ type Pool struct { ctx context.Context //nolint:containedctx } -var _ IPool = &Pool{} +var _ IPool = (*Pool)(nil) // ForEach iterates over the pool and calls the callback function for each key/value pair. func (p *Pool) ForEach(cb Callback) {