Ejemplo n.º 1
0
// Parse ini settings section to global setting.
func parseSettings(config ini.Section) (err error) {
	for fieldName := range config {
		if _, found := settingsFields[fieldName]; !found {
			return errutil.NewNoPosf(errFieldNotExist, fieldName)
		}
	}

	// Get time setting from INI.
	// If interval setting wasn't found, default value is 1 minute
	intervalStr := config.S(fieldInterval, settings.DefaultInterval.String())
	// Parse string to duration.
	settings.Global.Interval, err = time.ParseDuration(intervalStr)
	if err != nil {
		return errutil.Err(err)
	}

	// Set global file permissions.
	settings.Global.FilePerms = os.FileMode(config.I(fieldFilePerms, int(settings.DefaultFilePerms)))

	// Set port number.
	settings.Global.PortNum = config.S(fieldPortNum, settings.DefaultPortNum)

	// Set browser path.
	settings.Global.Browser = config.S(fieldBrowser, "")

	return nil
}
Ejemplo n.º 2
0
// Parse ini mail section to global setting.
func parseMail(mail ini.Section) (err error) {
	for fieldName := range mail {
		if _, found := mailFields[fieldName]; !found {
			return errutil.NewNoPosf(errFieldNotExist, fieldName)
		}
	}

	// Set global sender mail.
	settings.Global.SenderMail.Address = mail.S(fieldSendMail, "")
	if settings.Global.SenderMail.Address == "" {
		return errutil.NewNoPosf(errMailAddressNotFound)
	} else if !strings.Contains(settings.Global.SenderMail.Address, "@") {
		return errutil.NewNoPosf(errInvalidMailAddress, settings.Global.SenderMail.Address)
	}

	// Set global sender mail password.
	settings.Global.SenderMail.Password = mail.S(fieldSendPass, "")

	// Set global sender authorization server.
	settings.Global.SenderMail.AuthServer = mail.S(fieldSendAuthServer, "")
	if settings.Global.SenderMail.AuthServer == "" {
		return errutil.NewNoPosf(errMailAuthServerNotFound)
	}

	// Set global sender mail outgoing server.
	settings.Global.SenderMail.OutServer = mail.S(fieldSendOutServer, "")
	if settings.Global.SenderMail.OutServer == "" {
		return errutil.NewNoPosf(errMailOutServerNotFound)
	}

	// Set global receive mail.
	settings.Global.RecvMail = mail.S(fieldRecvMail, "")
	if settings.Global.RecvMail == "" {
		return errutil.NewNoPosf(errMailAddressNotFound)
	} else if !strings.Contains(settings.Global.RecvMail, "@") {
		return errutil.NewNoPosf(errInvalidMailAddress, settings.Global.RecvMail)
	}

	return nil
}