// LoadWithParsers initializes config : struct fields given by reference, with args : arguments.
// Some custom parsers may be given.
187834
func LoadWithParsers(config interface{}, defaultValue interface{}, args []string, customParsers map[reflect.Type]parse.Parser) error {
	cmd := &Command{
		Config:                config,
		DefaultPointersConfig: defaultValue,
	}
	_, cmd.Name = path.Split(os.Args[0])
	return LoadWithCommand(cmd, args, customParsers, nil)
}
444761
func (c *Connection) Load(names ...string) (errors []error) {
	var tempErrors []error = make([]error, len(names))
	var numErrors int = 0
	for _, name := range names {
		err := c.Create(name)
		if err != nil {
			tempErrors = append(tempErrors, err)
			numErrors += 1
			continue
		}
		break
	}

	copy(errors, tempErrors[0:numErrors])
	return
}
1291959
func (backend *Backend) LoadTranslations() (translations []*i18n.Translation) {
	for _, content := range backend.contents {
		if results, err := backend.LoadYAMLContent(content); err == nil {
			translations = append(translations, results...)
		} else {
			panic(err)
		}
	}
	return translations
}
203463
func LoadViews(p string) *template.Template {

	var viewpath string
	if filepath.IsAbs(p) {
		viewpath = p
	} else {
		_, f, _, _ := runtime.Caller(1)
		viewpath = path.Join(path.Dir(f), p) + "/"
	}

	exp := regexp.MustCompile("[^/]+\\.html$")
	pool := template.New("")

	filepath.Walk(viewpath, func(fullpath string, info os.FileInfo, err error) error {
		if exp.MatchString(fullpath) {
			name := strings.Replace(strings.Replace(fullpath, viewpath, "", -1), filepath.Ext(fullpath), "", -1)
			name = strings.Trim(name, "/")
			tmp, err := template.ParseFiles(fullpath)
			if err != nil {
				panic(err)
			}
			if _, err = pool.AddParseTree(name, tmp.Tree); err != nil {
				panic(err)
			}
		}
		return nil
	})

	templates = pool

	return templates
}
820269
func (i18n *I18n) LoadTranslations() map[string]map[string]*Translation {
	var translations = map[string]map[string]*Translation{}

	for i := len(i18n.Backends); i > 0; i-- {
		backend := i18n.Backends[i-1]
		for _, translation := range backend.LoadTranslations() {
			if translations[translation.Locale] == nil {
				translations[translation.Locale] = map[string]*Translation{}
			}
			translations[translation.Locale][translation.Key] = translation
		}
	}
	return translations
}
1329346
func (s *Settings) Load(c context.Context) error {
	var loadMe Settings

	// Load additional global config from settings. If it's missing, that's fine,
	// since its fields are all optional.
	if err := settings.Get(c, globalConfigSettingsKey, &loadMe); err != nil {
		// The settings are missing, so let's install the empty settings.
		if err != settings.ErrNoSettings {
			log.WithError(err).Errorf(c, "Failed to load global config from settings.")
			return err
		}

		if err := settings.Set(c, globalConfigSettingsKey, &loadMe, "application", "initial empty config"); err != nil {
			log.WithError(err).Warningf(c, "Failed to initialize empty config.")
		}
	}

	*s = loadMe
	return nil
}
324228
func (b *BaggedModel) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error {
	b.lock.Lock()
	defer b.lock.Unlock()

	pI := func(n string, i int) string {
		return reader.Prefix(prefix, reader.Prefix(n, fmt.Sprintf("%d", i)))
	}

	// Read the essential info
	randomFeaturesKey := reader.Prefix(prefix, "NUM_RANDOM_FEATURES")
	randomFeatures, err := reader.GetU64ForKey(randomFeaturesKey)
	if err != nil {
		return base.DescribeError("Can't read NUM_RANDOM_FEATURES", err)
	}

	b.RandomFeatures = int(randomFeatures)

	// Reload the classifiers
	for i, m := range b.Models {
		clsPrefix := fmt.Sprintf("%s/", pI("CLASSIFIERS", i))
		err := m.LoadWithPrefix(reader, clsPrefix)
		if err != nil {
			return base.DescribeError("Can't read classifier", err)
		}
	}

	// Load the instances template
	tmp, err := reader.GetInstancesForKey(reader.Prefix(prefix, "REFERENCE_INSTANCES"))
	if err != nil {
		return base.DescribeError("Can't read REFERENCE_INSTACES", err)
	}
	b.fitOn = tmp

	// Reload the selected attributes
	selectedAttributesKey := reader.Prefix(prefix, "SELECTED_ATTRIBUTES")
	ser := make(map[int][][]byte)
	err = reader.GetJSONForKey(selectedAttributesKey, &ser)
	if err != nil {
		return base.DescribeError("Can't reload selected attributes", err)
	}

	b.selectedAttributes = make(map[int][]base.Attribute)

	for key := range ser {
		b.selectedAttributes[key] = make([]base.Attribute, len(ser[key]))
		for i, attrBytes := range ser[key] {
			attr, err := base.DeserializeAttribute(attrBytes)
			if err != nil {
				return base.DescribeError("Can't deserialize attribute", err)
			}
			attrNew, err := base.ReplaceDeserializedAttributeWithVersionFromInstances(attr, b.fitOn)
			if err != nil {
				return base.DescribeError("Can't replace attribute", err)
			}
			b.selectedAttributes[key][i] = attrNew
		}
	}
	return nil
}
544816
func (p Properties) Load(src io.Reader) error {
	lr := newLineReader(src)
	for {
		s, e := lr.readLine()
		if e == io.EOF {
			break
		}
		if e != nil {
			return e
		}

		keyLen := 0
		precedingBackslash := false
		hasSep := false
		valueStart := len(s)

		for keyLen < len(s) {
			c := s[keyLen]

			if (c == '=' || c == ':') && !precedingBackslash {
				valueStart = keyLen + 1
				hasSep = true
				break
			}
			if (c == ' ' || c == '\t' || c == '\f') && !precedingBackslash {
				valueStart = keyLen + 1
				break
			}
			if c == '\\' {
				precedingBackslash = !precedingBackslash
			} else {
				precedingBackslash = false
			}

			keyLen++
		}

		for valueStart < len(s) {
			c := s[valueStart]
			if c != ' ' && c != '\t' && c != '\f' {
				if !hasSep && (c == '=' || c == ':') {
					hasSep = true
				} else {
					break
				}
			}
			valueStart++
		}
		key, err := decodeString(s[0:keyLen])
		if err != nil {
			return err
		}
		value, err := decodeString(s[valueStart:len(s)])
		if err != nil {
			return err
		}
		p[key] = value
	}
	return nil
}
581531
func Load(v interface{}, s ...Source) error {
	if reflect.Indirect(reflect.ValueOf(v)).Kind() != reflect.Struct {
		panic("scan for non-struct type")
	}
	if len(s) == 0 {
		return nil
	}
	scn := &scanner{s}
	return scn.scan(v)
}
464152
func LoadJSON(filename string) *Graph {
	js, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil
	}
	return ParseJSON(js)
}
140928
func (KNN *KNNClassifier) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error {

	clsMetadata, err := reader.ReadMetadataAtPrefix(prefix)
	if err != nil {
		return err
	}

	if clsMetadata.ClassifierName != "KNN" {
		return fmt.Errorf("This file doesn't contain a KNN classifier")
	}
	if clsMetadata.ClassifierVersion != "1.0" {
		return fmt.Errorf("Can't understand this file format")
	}

	metadata := clsMetadata.ClassifierMetadata
	KNN.DistanceFunc = metadata["distance_func"].(string)
	KNN.Algorithm = metadata["algorithm"].(string)
	//KNN.NearestNeighbours = metadata["neighbours"].(int)
	KNN.Weighted = metadata["weighted"].(bool)
	KNN.AllowOptimisations = metadata["allow_optimizations"].(bool)

	// 101 on why JSON is a bad serialization format
	floatNeighbours := metadata["neighbours"].(float64)
	KNN.NearestNeighbours = int(floatNeighbours)

	KNN.TrainingData, err = reader.GetInstancesForKey(reader.Prefix(prefix, "TrainingInstances"))

	return err
}
1219020
func Load(file string) (config Project, err error) {
	f, err := os.Open(file) // #nosec
	if err != nil {
		return
	}
	log.WithField("file", file).Info("loading config file")
	return LoadReader(f)
}
665786
func (d *Deps) LoadResources() error {
	// Note that the translations need to be loaded before the templates.
	if err := d.translationProvider.Update(d); err != nil {
		return err
	}

	if err := d.templateProvider.Update(d); err != nil {
		return err
	}

	return nil
}
729168
func (c *Config) Load(confFile string) error {
	metaData, err := toml.DecodeFile(confFile, c)
	if c.TokenLimit <= 0 {
		c.TokenLimit = 1000
	}

	// If any items in confFile file are not mapped into the Config struct, issue
	// an error and stop the server from starting.
	undecoded := metaData.Undecoded()
	if len(undecoded) > 0 && err == nil {
		var undecodedItems []string
		for _, item := range undecoded {
			undecodedItems = append(undecodedItems, item.String())
		}
		err = &ErrConfigValidationFailed{fmt.Sprintf("config file %s contained unknown configuration options: %s", confFile, strings.Join(undecodedItems, ", "))}
	}

	return err
}
1011984
func loadConfig() (*config, []string, error) {
	// Default config.
	cfg := config{
		DataDir:       defaultDataDir,
		DbType:        defaultDbType,
		NumCandidates: defaultNumCandidates,
	}

	// Parse command line options.
	parser := flags.NewParser(&cfg, flags.Default)
	remainingArgs, err := parser.Parse()
	if err != nil {
		if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
			parser.WriteHelp(os.Stderr)
		}
		return nil, nil, err
	}

	// Multiple networks can't be selected simultaneously.
	funcName := "loadConfig"
	numNets := 0
	// Count number of network flags passed; assign active network params
	// while we're at it
	if cfg.TestNet3 {
		numNets++
		activeNetParams = &chaincfg.TestNet3Params
	}
	if cfg.RegressionTest {
		numNets++
		activeNetParams = &chaincfg.RegressionNetParams
	}
	if cfg.SimNet {
		numNets++
		activeNetParams = &chaincfg.SimNetParams
	}
	if numNets > 1 {
		str := "%s: The testnet, regtest, and simnet params can't be " +
			"used together -- choose one of the three"
		err := fmt.Errorf(str, funcName)
		fmt.Fprintln(os.Stderr, err)
		parser.WriteHelp(os.Stderr)
		return nil, nil, err
	}

	// Validate database type.
	if !validDbType(cfg.DbType) {
		str := "%s: The specified database type [%v] is invalid -- " +
			"supported types %v"
		err := fmt.Errorf(str, "loadConfig", cfg.DbType, knownDbTypes)
		fmt.Fprintln(os.Stderr, err)
		parser.WriteHelp(os.Stderr)
		return nil, nil, err
	}

	// Append the network type to the data directory so it is "namespaced"
	// per network.  In addition to the block database, there are other
	// pieces of data that are saved to disk such as address manager state.
	// All data is specific to a network, so namespacing the data directory
	// means each individual piece of serialized data does not have to
	// worry about changing names per network and such.
	cfg.DataDir = filepath.Join(cfg.DataDir, netName(activeNetParams))

	// Validate the number of candidates.
	if cfg.NumCandidates < minCandidates || cfg.NumCandidates > maxCandidates {
		str := "%s: The specified number of candidates is out of " +
			"range -- parsed [%v]"
		err = fmt.Errorf(str, "loadConfig", cfg.NumCandidates)
		fmt.Fprintln(os.Stderr, err)
		parser.WriteHelp(os.Stderr)
		return nil, nil, err
	}

	return &cfg, remainingArgs, nil
}
1071059
func (loader *ConfigLoader) Load(target interface{}) error {
	if target == nil {
		return errors.New("target is nil error")
	}
	// fetch all target's field member
	instance := reflect.ValueOf(target).Elem()

	if !instance.IsValid() || instance.Kind() != reflect.Struct {
		return errors.New("target is not a valid struct type")
	}

	// file content reader. handled line by line
	lines := readAllLines(*bufio.NewReader(loader.conf))
	if len(lines) == 0 {
		// empty file or have error
		return errors.New("configuration file is empty or read error")
	}

	for _, line := range lines {
		pair := strings.SplitN(line, "=", 2)
		key := strings.Trim(pair[0], " ")
		if len(pair) != 2 || !onlyAlpha.MatchString(key) {
			return fmt.Errorf("error confiugre key line found. key is %s", key)
		}
		value := strings.Trim(pair[1], " ")

		// key is good. look up the matching tag
		var err error
		var found string
		var genericType int
		if found, genericType, err = lookupTagMember(target, key); err != nil {
			// not found in struct, give error
			return fmt.Errorf("couldn't found structure key's tag '%s'. one must be tagged", key)
		}

		field := instance.FieldByName(found)
		if !field.IsValid() || !field.CanSet() {
			return fmt.Errorf("structure key '%s' is not accessable", key)
		}

		// set config's value
		switch field.Kind() {
		case reflect.String: // for string
			field.SetString(value)
		case reflect.Bool: // for bool
			if v, err := strconv.ParseBool(value); err == nil {
				field.SetBool(v)
			} else {
				return fmt.Errorf("boolean key %s wrong format %v", key, value)
			}
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: // for numberic
			if genericType == GenericTypeDate {
				if t, e := time.ParseInLocation(loader.format, value, time.UTC); e == nil {
					field.SetInt(t.Unix())
				} else {
					return fmt.Errorf("integer conver to date format [%s] from (%s)", loader.format, value)
				}
			} else if v, err := strconv.ParseInt(value, 10, 64); err == nil {
				field.SetInt(v)
			} else {
				return fmt.Errorf("integer key %s wrong format %v", key, value)
			}
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			if v, err := strconv.ParseUint(value, 10, 64); err == nil {
				field.SetUint(v)
			} else {
				return fmt.Errorf("unsigned integer key %s wrong format %v", key, value)
			}
		case reflect.Slice: // for slice
			if items, err := loader.extractAsList(value); err == nil {
				filtered := make([]string, 0, len(items))
				for _, item := range items {
					if s := strings.TrimSpace(item); len(s) != 0 {
						filtered = append(filtered, s)
					}
				}
				field.Set(reflect.ValueOf(filtered))
			} else {
				return err
			}
		}
	}
	return nil
}
931122
func Load(configFile string, data interface{}) (quick.Config, error) {
	return quick.LoadConfig(configFile, globalEtcdClient, data)
}