29 lines
867 B
Go
29 lines
867 B
Go
|
|
package starter
|
||
|
|
|
||
|
|
import (
|
||
|
|
"apigo.cc/go/log"
|
||
|
|
"context"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Service defines the lifecycle of a component managed by the starter.
|
||
|
|
type Service interface {
|
||
|
|
// Start starts the service. It should block until the service is ready.
|
||
|
|
Start(ctx context.Context, logger *log.Logger) error
|
||
|
|
// Stop stops the service. It should block until the service is cleaned up.
|
||
|
|
Stop(ctx context.Context) error
|
||
|
|
// Health returns the health status of the service.
|
||
|
|
Health() error
|
||
|
|
}
|
||
|
|
|
||
|
|
// Reloader defines an optional interface for services that support configuration reloading.
|
||
|
|
type Reloader interface {
|
||
|
|
Reload() error
|
||
|
|
}
|
||
|
|
|
||
|
|
// UserSignalHandler defines an optional interface for services that handle custom user signals.
|
||
|
|
type UserSignalHandler interface {
|
||
|
|
// HandleUserSignal handles a custom signal. Return true if the signal was handled.
|
||
|
|
HandleUserSignal(sig os.Signal) bool
|
||
|
|
}
|