func UnmarshalServerConfFromIni()

in pkg/config/server.go [238:291]


func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
	f, err := ini.LoadSources(ini.LoadOptions{
		Insensitive:         false,
		InsensitiveSections: false,
		InsensitiveKeys:     false,
		IgnoreInlineComment: true,
		AllowBooleanKeys:    true,
	}, source)
	if err != nil {
		return ServerCommonConf{}, err
	}

	s, err := f.GetSection("common")
	if err != nil {
		return ServerCommonConf{}, err
	}

	common := GetDefaultServerConf()
	err = s.MapTo(&common)
	if err != nil {
		return ServerCommonConf{}, err
	}

	// allow_ports
	allowPortStr := s.Key("allow_ports").String()
	if allowPortStr != "" {
		allowPorts, err := util.ParseRangeNumbers(allowPortStr)
		if err != nil {
			return ServerCommonConf{}, fmt.Errorf("invalid allow_ports: %v", err)
		}
		for _, port := range allowPorts {
			common.AllowPorts[int(port)] = struct{}{}
		}
	}

	// plugin.xxx
	pluginOpts := make(map[string]plugin.HTTPPluginOptions)
	for _, section := range f.Sections() {
		name := section.Name()
		if !strings.HasPrefix(name, "plugin.") {
			continue
		}

		opt, err := loadHTTPPluginOpt(section)
		if err != nil {
			return ServerCommonConf{}, err
		}

		pluginOpts[opt.Name] = *opt
	}
	common.HTTPPlugins = pluginOpts

	return common, nil
}