Peter Kurfer
d70ba748f5
- merge packages to get a more concise layout because plugins are no more and therefore there's not a lot to be exported - fix test logger - rework config parsing to be easier and more transparent - remove unnecessary APIs because dynamic endpoint handling is rather a won't implement
42 lines
690 B
Go
42 lines
690 B
Go
package endpoint
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
const (
|
|
startupTimeoutDuration = 100 * time.Millisecond
|
|
)
|
|
|
|
type Endpoint struct {
|
|
Spec
|
|
name string
|
|
uplink Uplink
|
|
}
|
|
|
|
func (e Endpoint) Start(lifecycle Lifecycle) (err error) {
|
|
startupResult := make(chan error)
|
|
ctx, cancel := context.WithTimeout(lifecycle.Context(), startupTimeoutDuration)
|
|
defer cancel()
|
|
|
|
go func() {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
lifecycle.Logger().Fatal("Startup error recovered", zap.Any("recovered", r))
|
|
}
|
|
}()
|
|
|
|
startupResult <- e.Handler.Start(lifecycle)
|
|
}()
|
|
|
|
select {
|
|
case err = <-startupResult:
|
|
case <-ctx.Done():
|
|
err = ErrStartupTimeout
|
|
}
|
|
|
|
return
|
|
}
|