github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/main/confloader/confloader.go (about)

     1  package confloader
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  )
     7  
     8  type configFileLoader func(string) (io.Reader, error)
     9  type extconfigLoader func([]string) (io.Reader, error)
    10  
    11  var (
    12  	EffectiveConfigFileLoader configFileLoader
    13  	EffectiveExtConfigLoader  extconfigLoader
    14  )
    15  
    16  // LoadConfig reads from a path/url/stdin
    17  // actual work is in external module
    18  func LoadConfig(file string) (io.Reader, error) {
    19  	if EffectiveConfigFileLoader == nil {
    20  		newError("external config module not loaded, reading from stdin").AtInfo().WriteToLog()
    21  		return os.Stdin, nil
    22  	}
    23  	return EffectiveConfigFileLoader(file)
    24  }
    25  
    26  // LoadExtConfig calls v2ctl to handle multiple config
    27  // the actual work also in external module
    28  func LoadExtConfig(files []string) (io.Reader, error) {
    29  	if EffectiveExtConfigLoader == nil {
    30  		return nil, newError("external config module not loaded").AtError()
    31  	}
    32  
    33  	return EffectiveExtConfigLoader(files)
    34  }