refactor: Extract clash/v2ray/time service form router

This commit is contained in:
世界 2024-11-10 16:46:59 +08:00
parent 1df8dfcade
commit b4f1c2a596
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
25 changed files with 299 additions and 465 deletions

View file

@ -1,13 +1,5 @@
package adapter
type LegacyPreStarter interface {
PreStart() error
}
type LegacyPostStarter interface {
PostStart() error
}
func LegacyStart(starter any, stage StartStage) error {
switch stage {
case StartStateInitialize:
@ -31,3 +23,27 @@ func LegacyStart(starter any, stage StartStage) error {
}
return nil
}
type lifecycleServiceWrapper struct {
Service
name string
}
func NewLifecycleService(service Service, name string) LifecycleService {
return &lifecycleServiceWrapper{
Service: service,
name: name,
}
}
func (l *lifecycleServiceWrapper) Name() string {
return l.name
}
func (l *lifecycleServiceWrapper) Start(stage StartStage) error {
return LegacyStart(l.Service, stage)
}
func (l *lifecycleServiceWrapper) Close() error {
return l.Service.Close()
}