sing-box/experimental/clashapi.go

25 lines
745 B
Go
Raw Permalink Normal View History

2022-07-20 07:12:40 +08:00
package experimental
import (
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"
)
2022-09-26 19:37:06 +08:00
type ClashServerConstructor = func(router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error)
var clashServerConstructor ClashServerConstructor
func RegisterClashServerConstructor(constructor ClashServerConstructor) {
clashServerConstructor = constructor
}
2022-07-20 07:12:40 +08:00
func NewClashServer(router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error) {
2022-09-26 19:37:06 +08:00
if clashServerConstructor == nil {
return nil, os.ErrInvalid
}
return clashServerConstructor(router, logFactory, options)
2022-07-20 07:12:40 +08:00
}