mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 03:51:31 +00:00
26 lines
803 B
Go
26 lines
803 B
Go
package experimental
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
"github.com/sagernet/sing-box/log"
|
|
"github.com/sagernet/sing-box/option"
|
|
)
|
|
|
|
type ClashServerConstructor = func(ctx context.Context, router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error)
|
|
|
|
var clashServerConstructor ClashServerConstructor
|
|
|
|
func RegisterClashServerConstructor(constructor ClashServerConstructor) {
|
|
clashServerConstructor = constructor
|
|
}
|
|
|
|
func NewClashServer(ctx context.Context, router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error) {
|
|
if clashServerConstructor == nil {
|
|
return nil, os.ErrInvalid
|
|
}
|
|
return clashServerConstructor(ctx, router, logFactory, options)
|
|
}
|