Skip to content

Commit

Permalink
Fix interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Nov 5, 2023
1 parent 91db586 commit 52d2455
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion metrics/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Merger struct {
OutputMetrics []byte
}

var _ IMerger = &Merger{}
var _ IMerger = (*Merger)(nil)

// NewMerger creates a new metrics merger.
func NewMerger(
Expand Down
2 changes: 1 addition & 1 deletion network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion network/conn_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions network/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion network/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Proxy struct {
ClientConfig *config.Client
}

var _ IProxy = &Proxy{}
var _ IProxy = (*Proxy)(nil)

// NewProxy creates a new proxy.
func NewProxy(
Expand Down
14 changes: 14 additions & 0 deletions network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 52d2455

Please sign in to comment.