2020-10-02 09:56:48 +00:00
|
|
|
//go:generate mockgen -source=$GOFILE -destination=./../../internal/mock/endpoints/endpoint.mock.go -package=endpoints_mock
|
2021-01-13 17:07:04 +00:00
|
|
|
package endpoint
|
2020-04-13 22:14:56 +00:00
|
|
|
|
|
|
|
import (
|
2020-10-02 09:56:48 +00:00
|
|
|
"context"
|
2020-12-26 13:11:49 +00:00
|
|
|
|
2020-05-03 08:15:24 +00:00
|
|
|
"github.com/google/uuid"
|
2020-12-26 13:11:49 +00:00
|
|
|
"gitlab.com/inetmock/inetmock/pkg/api"
|
|
|
|
"gitlab.com/inetmock/inetmock/pkg/config"
|
2020-04-13 22:14:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Endpoint interface {
|
2020-05-03 08:15:24 +00:00
|
|
|
Id() uuid.UUID
|
2020-12-26 13:11:49 +00:00
|
|
|
Start(ctx api.PluginContext) error
|
2020-10-02 09:56:48 +00:00
|
|
|
Shutdown(ctx context.Context) error
|
2020-04-13 22:14:56 +00:00
|
|
|
Name() string
|
2020-05-03 08:15:24 +00:00
|
|
|
Handler() string
|
|
|
|
Listen() string
|
|
|
|
Port() uint16
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type endpoint struct {
|
2020-05-03 08:15:24 +00:00
|
|
|
id uuid.UUID
|
2020-04-13 22:14:56 +00:00
|
|
|
name string
|
|
|
|
handler api.ProtocolHandler
|
2020-04-27 22:26:15 +00:00
|
|
|
config config.HandlerConfig
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 08:15:24 +00:00
|
|
|
func (e endpoint) Id() uuid.UUID {
|
|
|
|
return e.id
|
|
|
|
}
|
|
|
|
|
2020-04-13 22:14:56 +00:00
|
|
|
func (e endpoint) Name() string {
|
|
|
|
return e.name
|
|
|
|
}
|
|
|
|
|
2020-05-03 08:15:24 +00:00
|
|
|
func (e endpoint) Handler() string {
|
|
|
|
return e.config.HandlerName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e endpoint) Listen() string {
|
|
|
|
return e.config.ListenAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e endpoint) Port() uint16 {
|
|
|
|
return e.config.Port
|
|
|
|
}
|
|
|
|
|
2020-12-26 13:11:49 +00:00
|
|
|
func (e *endpoint) Start(ctx api.PluginContext) (err error) {
|
|
|
|
return e.handler.Start(ctx, e.config)
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 09:56:48 +00:00
|
|
|
func (e *endpoint) Shutdown(ctx context.Context) (err error) {
|
|
|
|
return e.handler.Shutdown(ctx)
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|