Пример #1
0
func GetMainServerConfig() (string, error) {
	if mainServer != "" {
		return mainServer, nil
	} else {
		cfg, err := ini.Load(utils.GetConfigFilePath())
		if err != nil {
			return "", err
		}

		if session, err := cfg.GetSection(MainServerSectionName); err == nil {
			ip, err := utils.GetConfigValue(session, MainServerIpKeyName)
			if err != nil {
				return "", err
			}
			port, err := utils.GetConfigValue(session, MainServerPortKeyName)
			if err != nil {
				return "", err
			}

			return fmt.Sprintf("%s:%s", ip, port), nil
		} else {
			return "", errors.New("Can not find MainServer configuration")
		}
	}
}
Пример #2
0
func getConfigValue(valueName string) (string, error) {
	cfg, err := ini.Load(utils.GetConfigFilePath())
	if err != nil {
		return "", err
	}

	if session, err := cfg.GetSection(""); err == nil {
		return utils.GetConfigValue(session, valueName)
	} else {
		return "", err
	}
}
Пример #3
0
func GetProcessNames() ([]string, error) {
	if processNames != "" {
		return strings.Split(processNames, ","), nil
	} else {
		cfg, err := ini.Load(utils.GetConfigFilePath())
		if err != nil {
			return make([]string, 0), err
		}

		if session, err := cfg.GetSection(SystemSectionName); err == nil {
			processStr, err := utils.GetConfigValue(session, SystemConcernedProcesses)
			if err != nil {
				return make([]string, 0), err
			}
			return strings.Split(processStr, ","), nil
		} else {
			return make([]string, 0), err
		}
	}
}