mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-12 16:18:50 +00:00
34 lines
677 B
Go
34 lines
677 B
Go
|
package adapter
|
||
|
|
||
|
type LegacyPreStarter interface {
|
||
|
PreStart() error
|
||
|
}
|
||
|
|
||
|
type LegacyPostStarter interface {
|
||
|
PostStart() error
|
||
|
}
|
||
|
|
||
|
func LegacyStart(starter any, stage StartStage) error {
|
||
|
switch stage {
|
||
|
case StartStateInitialize:
|
||
|
if preStarter, isPreStarter := starter.(interface {
|
||
|
PreStart() error
|
||
|
}); isPreStarter {
|
||
|
return preStarter.PreStart()
|
||
|
}
|
||
|
case StartStateStart:
|
||
|
if starter, isStarter := starter.(interface {
|
||
|
Start() error
|
||
|
}); isStarter {
|
||
|
return starter.Start()
|
||
|
}
|
||
|
case StartStatePostStart:
|
||
|
if postStarter, isPostStarter := starter.(interface {
|
||
|
PostStart() error
|
||
|
}); isPostStarter {
|
||
|
return postStarter.PostStart()
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|