github.com/sagernet/sing-box@v1.9.0-rc.20/experimental/v2rayapi.go (about)

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