mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-06 11:14:56 +03:00
Make clash api and gVisor optional
This commit is contained in:
14
experimental/clashapi.go
Normal file
14
experimental/clashapi.go
Normal 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
|
||||
}
|
||||
@@ -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})
|
||||
}
|
||||
|
||||
14
experimental/clashapi_stub.go
Normal file
14
experimental/clashapi_stub.go
Normal 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`)
|
||||
}
|
||||
Reference in New Issue
Block a user