Пример #1
0
// ServerFromCli uses the cli arguments to configure a server instance
func ServerFromCli(c *cli.Context) *gouncer.Server {
	CheckSSL(c)

	// Initialize configuration components from cli
	core := &gouncer.Core{c.String("hostname"), ":" + c.String("port"), c.Bool("jsonp"), c.String("log")}
	ssl := &gouncer.Ssl{c.String("certificate"), c.String("key")}

	backend := &gouncer.Backend{
		Couchdb:  c.String("couchdb"),
		Userdb:   c.String("userdb"),
		Groupdb:  c.String("groupdb"),
		Memcache: c.StringSlice("memcache"),
		Smtp:     c.String("smtp"),
	}

	token := &gouncer.Token{c.String("algorithm"), int32(c.Int("expiration"))}

	// Create configuration
	cfg := &gouncer.Config{
		Core:    core,
		Ssl:     ssl,
		Backend: backend,
		Token:   token,
	}

	return gouncer.NewServer(cfg)
}
Пример #2
0
// ServerFromConf generates a server instance with the settings
// specified in the specified config file. All other command line
// arguments are igored in this operation mode
func ServerFromConf(cfg string) *gouncer.Server {
	conf, err := ioutil.ReadFile(cfg)

	if err != nil {
		log.Fatalln("Error reading config", err.Error())
	}

	var gcfg gouncer.Config

	if err := toml.Unmarshal(conf, &gcfg); err != nil {
		log.Fatalln("Error parsing config", err.Error())
	}

	return gouncer.NewServer(&gcfg)
}