v2rayapi.go 657 B

123456789101112131415161718192021222324
  1. package experimental
  2. import (
  3. "os"
  4. "github.com/sagernet/sing-box/adapter"
  5. "github.com/sagernet/sing-box/log"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. type V2RayServerConstructor = func(logger log.Logger, options option.V2RayAPIOptions) (adapter.V2RayServer, error)
  9. var v2rayServerConstructor V2RayServerConstructor
  10. func RegisterV2RayServerConstructor(constructor V2RayServerConstructor) {
  11. v2rayServerConstructor = constructor
  12. }
  13. func NewV2RayServer(logger log.Logger, options option.V2RayAPIOptions) (adapter.V2RayServer, error) {
  14. if v2rayServerConstructor == nil {
  15. return nil, os.ErrInvalid
  16. }
  17. return v2rayServerConstructor(logger, options)
  18. }