Esempio n. 1
0
func parseRESTConfig(conf *goconf.ConfigFile) (*restConfig, error) {
	var err error
	c := &restConfig{}

	c.tls.enable, err = conf.GetBool("rest", "tls")
	if err != nil {
		return nil, errors.New("invalid rest/tls value")
	}

	port, err := conf.GetInt("rest", "port")
	if err != nil || port <= 0 || port > 65535 {
		return nil, errors.New("empty or invalid rest/port value")
	}
	c.port = uint16(port)

	c.tls.certFile, err = conf.GetString("rest", "cert_file")
	if err != nil || len(c.tls.certFile) == 0 {
		return nil, errors.New("empty rest/cert_file value")
	}
	if c.tls.certFile[0] != '/' {
		return nil, errors.New("rest/cert_file should be specified as an absolute path")
	}

	c.tls.keyFile, err = conf.GetString("rest", "key_file")
	if err != nil || len(c.tls.keyFile) == 0 {
		return nil, errors.New("empty rest/key_file value")
	}
	if c.tls.keyFile[0] != '/' {
		return nil, errors.New("rest/key_file should be specified as an absolute path")
	}

	return c, nil
}
Esempio n. 2
0
// Sets global variable to enable TLS communications and other related variables (certificate path, organization)
// optional parameters:  default.certpath, default.organization, default.tls
func GlobalTls(configFile *goconf.ConfigFile) {
	certificatepath, err := configFile.GetString("default", "certpath")
	if err != nil {
		logger.Warn(err)
	} else {
		certpath = certificatepath
	}
	logger.Printf("certpath=[%v]", certpath)

	certificateorg, err := configFile.GetString("default", "organization")
	if err != nil {
		logger.Warn(err)
		if certificateorg, err = os.Hostname(); err != nil {
			logger.Warn(err)
			certificateorg = "golem.googlecode.com"
		}
	}
	certorg = certificateorg
	logger.Printf("certorg=[%v]", certorg)

	useTlsl, err := configFile.GetBool("default", "tls")
	if err != nil {
		logger.Warn(err)
		useTls = true
	} else {
		useTls = useTlsl
	}
	logger.Printf("TLS=[%v]", useTls)
}
Esempio n. 3
0
// sets global logger based on verbosity level in configuration
// optional parameter:  default.verbose (defaults to true if not present or incorrectly set)
func GlobalLogger(configFile *goconf.ConfigFile) {
	verbose, err := configFile.GetBool("default", "verbose")
	logger = log4go.NewVerboseLogger(verbose, nil, "")
	if err != nil {
		logger.Warn(err)
		verbose = true
	}
	logger.Printf("verbose set [%v]", verbose)
}
Esempio n. 4
0
func MongoLogger(configFile *goconf.ConfigFile) {
	verbose, err := configFile.GetBool("mgodb", "verbose")
	if err != nil {
		logger.Warn(err)
		verbose = false
	}

	logger.Printf("mongo logger verbose set [%v]", verbose)
	if verbose {
		mgo.SetLogger(logger)
		mgo.SetDebug(verbose)
	}
}