2020-05-06 22:45:37 +00:00
|
|
|
//go:generate mockgen -source=endpoint.go -destination=./../../internal/mock/endpoints/endpoint.mock.go -package=endpoints_mock
|
2020-04-13 22:14:56 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/baez90/inetmock/pkg/api"
|
2020-04-27 22:26:15 +00:00
|
|
|
"github.com/baez90/inetmock/pkg/config"
|
2020-05-03 08:15:24 +00:00
|
|
|
"github.com/google/uuid"
|
2020-04-13 22:14:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Endpoint interface {
|
2020-05-03 08:15:24 +00:00
|
|
|
Id() uuid.UUID
|
2020-04-13 22:14:56 +00:00
|
|
|
Start() error
|
|
|
|
Shutdown() error
|
|
|
|
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-04-13 22:14:56 +00:00
|
|
|
func (e *endpoint) Start() (err error) {
|
|
|
|
return e.handler.Start(e.config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *endpoint) Shutdown() (err error) {
|
|
|
|
return e.handler.Shutdown()
|
|
|
|
}
|