github.com/moqsien/xraycore@v1.8.5/main/confloader/confloader.go (about)

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