2022-07-20 07:12:40 +08:00
|
|
|
package experimental
|
|
|
|
|
|
|
|
|
|
import (
|
2023-04-21 17:29:00 +08:00
|
|
|
"context"
|
2022-09-26 19:37:06 +08:00
|
|
|
"os"
|
|
|
|
|
|
2022-07-20 07:12:40 +08:00
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
|
"github.com/sagernet/sing-box/option"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-01 22:39:21 +08:00
|
|
|
type ClashServerConstructor = func(ctx context.Context, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.LifecycleService, error)
|
2022-09-26 19:37:06 +08:00
|
|
|
|
|
|
|
|
var clashServerConstructor ClashServerConstructor
|
|
|
|
|
|
|
|
|
|
func RegisterClashServerConstructor(constructor ClashServerConstructor) {
|
|
|
|
|
clashServerConstructor = constructor
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-01 22:39:21 +08:00
|
|
|
func NewClashServer(ctx context.Context, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.LifecycleService, error) {
|
2022-09-26 19:37:06 +08:00
|
|
|
if clashServerConstructor == nil {
|
|
|
|
|
return nil, os.ErrInvalid
|
|
|
|
|
}
|
2024-11-09 21:16:11 +08:00
|
|
|
return clashServerConstructor(ctx, logFactory, options)
|
2022-07-20 07:12:40 +08:00
|
|
|
}
|