Make clash api and gVisor optional

This commit is contained in:
世界
2022-07-20 07:12:40 +08:00
parent 5905ad3278
commit 98adef316a
9 changed files with 49 additions and 16 deletions

14
experimental/clashapi.go Normal file
View File

@@ -0,0 +1,14 @@
//go:build with_clash_api
package experimental
import (
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/experimental/clashapi"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
)
func NewClashServer(router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error) {
return clashapi.NewServer(router, logFactory, options), nil
}

View File

@@ -24,10 +24,7 @@ import (
"github.com/gorilla/websocket"
)
var (
_ adapter.Service = (*Server)(nil)
_ adapter.TrafficController = (*Server)(nil)
)
var _ adapter.ClashServer = (*Server)(nil)
type Server struct {
logger log.Logger
@@ -81,7 +78,7 @@ func (s *Server) Start() error {
go func() {
err = s.httpServer.Serve(listener)
if err != nil && !E.IsClosed(err) {
log.Error("external controller serve error: ", err)
s.logger.Error("external controller serve error: ", err)
}
}()
return nil
@@ -294,5 +291,5 @@ func getLogs(logFactory log.ObservableFactory) func(w http.ResponseWriter, r *ht
}
func version(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, render.M{"version": "sing-box " + C.Version, "premium": false})
render.JSON(w, r, render.M{"version": "sing-box " + C.Version, "premium": true})
}

View File

@@ -0,0 +1,14 @@
//go:build !with_clash_api
package experimental
import (
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
)
func NewClashServer(router adapter.Router, logFactory log.ObservableFactory, options option.ClashAPIOptions) (adapter.ClashServer, error) {
return nil, E.New(`clash api is not included in this build, rebuild with -tags with_clash_api`)
}