github.com/eagleql/xray-core@v1.4.4/infra/conf/reverse.go (about)

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