github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/app/subscription/entries/outbound/outbound.go (about)

     1  package outbound
     2  
     3  import (
     4  	"github.com/v2fly/v2ray-core/v5/app/subscription/entries"
     5  	"github.com/v2fly/v2ray-core/v5/app/subscription/specs"
     6  	"github.com/v2fly/v2ray-core/v5/common"
     7  )
     8  
     9  //go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
    10  
    11  // NewOutboundEntriesParser internal api
    12  func NewOutboundEntriesParser() entries.Converter {
    13  	return newOutboundEntriesParser()
    14  }
    15  
    16  func newOutboundEntriesParser() entries.Converter {
    17  	return &outboundEntriesParser{}
    18  }
    19  
    20  type outboundEntriesParser struct{}
    21  
    22  func (o *outboundEntriesParser) ConvertToAbstractServerConfig(rawConfig []byte, kindHint string) (*specs.SubscriptionServerConfig, error) {
    23  	parser := specs.NewOutboundParser()
    24  	outbound, err := parser.ParseOutboundConfig(rawConfig)
    25  	if err != nil {
    26  		return nil, newError("failed to parse outbound config").Base(err).AtWarning()
    27  	}
    28  	return parser.ToSubscriptionServerConfig(outbound)
    29  }
    30  
    31  func init() {
    32  	common.Must(entries.RegisterConverter("outbound", newOutboundEntriesParser()))
    33  }