github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/v4/reverse.go (about)

     1  package v4
     2  
     3  import (
     4  	"github.com/golang/protobuf/proto"
     5  
     6  	"github.com/v2fly/v2ray-core/v5/app/reverse"
     7  )
     8  
     9  type BridgeConfig struct {
    10  	Tag    string `json:"tag"`
    11  	Domain string `json:"domain"`
    12  }
    13  
    14  func (c *BridgeConfig) Build() (*reverse.BridgeConfig, error) {
    15  	return &reverse.BridgeConfig{
    16  		Tag:    c.Tag,
    17  		Domain: c.Domain,
    18  	}, nil
    19  }
    20  
    21  type PortalConfig struct {
    22  	Tag    string `json:"tag"`
    23  	Domain string `json:"domain"`
    24  }
    25  
    26  func (c *PortalConfig) Build() (*reverse.PortalConfig, error) {
    27  	return &reverse.PortalConfig{
    28  		Tag:    c.Tag,
    29  		Domain: c.Domain,
    30  	}, nil
    31  }
    32  
    33  type ReverseConfig struct {
    34  	Bridges []BridgeConfig `json:"bridges"`
    35  	Portals []PortalConfig `json:"portals"`
    36  }
    37  
    38  func (c *ReverseConfig) Build() (proto.Message, error) {
    39  	config := &reverse.Config{}
    40  	for _, bconfig := range c.Bridges {
    41  		b, err := bconfig.Build()
    42  		if err != nil {
    43  			return nil, err
    44  		}
    45  		config.BridgeConfig = append(config.BridgeConfig, b)
    46  	}
    47  
    48  	for _, pconfig := range c.Portals {
    49  		p, err := pconfig.Build()
    50  		if err != nil {
    51  			return nil, err
    52  		}
    53  		config.PortalConfig = append(config.PortalConfig, p)
    54  	}
    55  
    56  	return config, nil
    57  }