Beispiel #1
0
func ConfStringOrFatal(conf simpleconf.Config, section, key string) string {
	s, err := conf.GetString(section, key)
	if err != nil {
		log.Fatalf("Could not read config value %s.%s: %s", section, key, err)
	}
	return s
}
Beispiel #2
0
func ConfIntOrFatal(conf simpleconf.Config, section, key string) int64 {
	i, err := conf.GetInt(section, key)
	if err != nil {
		log.Fatalf("Could not read config value %s.%s: %s", section, key, err)
	}
	return i
}
Beispiel #3
0
// SendmailMailerCreator creates an SendmailMailer using configuration values in the [mail] section.
//
// 	exec - The name of the executable
// 	argX - (optional) Additional arguments for the executable. X is a ascending number starting with 1
func SendmailMailerCreator(conf simpleconf.Config) (Mailer, error) {
	rv := SendmailMailer{}
	var err error

	if rv.Exec, err = conf.GetString("mail", "exec"); err != nil {
		return rv, errors.New("Missing [mail] exec config")
	}

	for i := 1; ; i++ {
		arg, err := conf.GetString("mail", fmt.Sprintf("arg%d", i))
		if err != nil {
			break
		}

		rv.Args = append(rv.Args, arg)
	}

	return rv, nil
}
Beispiel #4
0
// SMTPMailerCreator creates an SMTPMailer using configuration values in the [mail] section.
//
// 	addr    - The address of the smtp server (go notation)
// 	user    - Username
// 	passwd  - Password
// 	crammd5 - Should CRAMMD5 (on) or PLAIN (off) be used?
// 	host    - The expected hostname of the mailserver (can be left out, if crammd5 is on)
//
func SMTPMailerCreator(conf simpleconf.Config) (Mailer, error) {
	rv := SMTPMailer{}
	var err error

	if rv.Addr, err = conf.GetString("mail", "addr"); err != nil {
		return rv, errors.New("Missing [mail] addr config")
	}
	if rv.UseCRAMMD5, err = conf.GetBool("mail", "crammd5"); err != nil {
		return rv, errors.New("Missing [mail] crammd5 config")
	}
	if rv.Username, err = conf.GetString("mail", "user"); err != nil {
		return rv, errors.New("Missing [mail] user config")
	}
	if rv.Password, err = conf.GetString("mail", "passwd"); err != nil {
		return rv, errors.New("Missing [mail] passwd config")
	}
	if !rv.UseCRAMMD5 {
		if rv.Host, err = conf.GetString("mail", "host"); err != nil {
			return rv, errors.New("Missing [mail] host config")
		}
	}

	return rv, nil
}