Пример #1
0
func init() {
	flag.Parse()
	c, err := goconfig.ReadConfigFile("config")
	if err != nil {
		glog.Warningf("init(): readconfigfile(config)")
		oauthCfg.ClientSecret = "a"
		oauthCfg.ClientId = "b"
		MyURL = "c"
		oauthCfg.RedirectURL = "d"
		return
	}
	oauthCfg.ClientId, err = c.GetString("Google", "ClientId")
	if err != nil {
		glog.Fatal("init(): readconfigfile(Google.ClientId), using dummy")
	}
	oauthCfg.ClientSecret, err = c.GetString("Google", "ClientSecret")
	if err != nil {
		glog.Fatal("init(): readconfigfile(Google.ClientSecret)")
	}
	url, err := c.GetString("Web", "url")
	MyURL = url
	if err != nil {
		glog.Fatal("init(): readconfigfile(Web.url)")
	}
	oauthCfg.RedirectURL = url + "/oauth2callback"
}
Пример #2
0
func (conf *Config) ReadConf(file string) (*Config, error) {
	if file == "" {
		file = filepath.Join(DEFAULT_CONF_PATH, DEFAULT_CONF)
	}

	c, err := goconf.ReadConfigFile(file)
	if err != nil {
		return nil, err
	}

	//TODO: check
	conf.log, _ = c.GetString("default", "log")
	conf.level, _ = c.GetString("default", "level")
	conf.topic, _ = c.GetString("default", "topic")
	conf.kaddr, _ = c.GetString("default", "kafka_addr")
	conf.sport, _ = c.GetString("default", "ssh_port")
	conf.suser, _ = c.GetString("default", "ssh_user")
	conf.skey, _ = c.GetString("default", "ssh_key")
	conf.sto, err = c.GetInt64("default", "ssh_timeout")
	if err != nil {
		conf.sto = DEFAULT_SSH_TIMEOUT
	}
	conf.daemon, _ = c.GetBool("default", "daemon")

	return conf, nil
}
Пример #3
0
func init() {
	var err error
	flag.Parse()
	c, err := goconfig.ReadConfigFile("../config")
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.db): %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.Host): %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.user): %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.pass): %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		glog.Fatalf("Init():sql.Open(mysql, %s:%s@%s/%s: %s", db_user, db_pass, db_host, db_name, err)
	}
	ebay_application_id, err = c.GetString("Ebay", "ApplicationID")
	if err != nil {
		glog.Fatalf("init():Config.GetString(Ebay,ApplicationID): %s", err)
	}
	eb = ebay.New(ebay_application_id)
	ebay_url, err := c.GetString("Ebay", "URL")
	if err == nil {
		eb.URL = ebay_url
	}
}
Пример #4
0
func init() {
	var err error
	flag.Parse()
	c, err := goconfig.ReadConfigFile("config")
	if port, err = c.GetString("Web", "port"); err != nil {
		glog.Fatalf("init(): config.GetString(web.portal): %s", err)
	}
	if environment, err = c.GetString("Web", "environment"); err != nil {
		glog.Fatalf("init(): config.GetString(Web.environment): %s", err)
	}
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.db): %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.Host): %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.user): %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.pass): %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		glog.Fatalf("Init():sql.Open(mysql, %s:%s@%s/%s: %s", db_user, db_pass, db_host, db_name, err)
	}
	cookieName = "gameslist_auth_" + environment
	auth.Config("config")
	auth.CookieName(cookieName)
	auth.Environment(environment)
}
Пример #5
0
func ReadOptions(fpath string) {
	c, err := goconfig.ReadConfigFile(fpath)
	if err != nil {
		panic("Could not read config.cfg at " + fpath)
	}
	UseRadians, err = c.GetBool("math", "UseRadians")
	if err != nil {
		panic("Bad config statement UseRadians")
	}
	SigFigs, err = c.GetInt64("math", "SignificantFigures")
	if err != nil {
		panic("Bad config statement SignificantFigures")
	}
	UseColoredOutput, err = c.GetBool("latex", "UseColoredOutput")
	if err != nil {
		panic("Bad config statement UseColoredOutput")
	}
	OutputColor, err = c.GetString("latex", "OutputColor")
	if err != nil {
		panic("Bad config statement OutputColor")
	}
	OrSymbol, err = c.GetString("latex", "OrSymbol")
	if err != nil {
		panic("Bad config statement OrSymbol")
	}
	DefinitionSymbol, err = c.GetString("latex", "DefinitionSymbol")
	if err != nil {
		panic("Bad config statement DefinitionSymbol")
	}
}
Пример #6
0
func NewFromConfigFile(file string, client bool) Mgollective {
	conf, err := goconfig.ReadConfigFile(file)
	if err != nil {
		log.Fatal("Couldn't open config ", err)
	}

	mgo := Mgollective{
		logger: seelog.Disabled,
		client: client,
		config: *conf,
	}

	connectorname := mgo.GetStringDefault("connector", "class", "redis")

	if factory, exists := connectorRegistry[connectorname]; exists {
		mgo.Connector = factory(&mgo)
	} else {
		fmt.Printf("No connector called %s", connectorname)
		panic("panic")
	}

	mgo.Connector.Connect()
	mgo.Connector.Subscribe()

	return mgo
}
Пример #7
0
func init() {
	var err error
	c, err := goconfig.ReadConfigFile("config")
	if err != nil {
		err.Error()
	}
	db_name, err = c.GetString("DB", "db")
	if err != nil {
		err.Error()
	}
	db_host, err = c.GetString("DB", "host")
	if err != nil {
		err.Error()
	}
	db_user, err = c.GetString("DB", "user")
	if err != nil {
		err.Error()
	}
	db_pass, err = c.GetString("DB", "pass")
	if err != nil {
		err.Error()
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@"+db_host+"/"+db_name)
	if err != nil {
		panic(err)
	}
}
Пример #8
0
func Config(config string) {
	c, err := goconfig.ReadConfigFile(config)
	googleEnabled = true
	facebookEnabled = true
	if err != nil {
		glog.Fatalf("init(): readconfigfile(config)")
	}
	GoogOauthCfg.ClientID, err = c.GetString("Google", "ClientID")
	if err != nil {
		googleEnabled = false
		glog.Errorf("init(): readconfigfile(Google.ClientID)")
	}
	GoogOauthCfg.ClientSecret, err = c.GetString("Google", "ClientSecret")
	if err != nil {
		googleEnabled = false
		glog.Errorf("init(): readconfigfile(Google.ClientSecret)")
	}
	FBOauthCfg.ClientID, err = c.GetString("Facebook", "ClientID")
	if err != nil {
		facebookEnabled = false
		glog.Errorf("init(): readconfigfile(Facebook.ClientID)")
	}
	FBOauthCfg.ClientSecret, err = c.GetString("Facebook", "ClientSecret")
	if err != nil {
		facebookEnabled = false
		glog.Errorf("init(): readconfigfile(Facebook.ClientSecret)")
	}
	url, err := c.GetString("Web", "url")
	MyURL = url
	if err != nil {
		glog.Fatalf("init(): readconfigfile(Web.url)")
	}
	GoogOauthCfg.RedirectURL = url + "oauth2callback"
	FBOauthCfg.RedirectURL = url + "fboauth2callback"
}
Пример #9
0
func new_address_matcher() *address_matcher {
	// honor NOTMUCH_CONFIG
	home := os.Getenv("NOTMUCH_CONFIG")
	if home == "" {
		home = os.Getenv("HOME")
	}

	cfg, err := goconfig.ReadConfigFile(path.Join(home, ".notmuch-config"))
	if err != nil {
		log.Fatalf("error loading config file:", err)
	}

	db_path, _ := cfg.GetString("database", "path")
	primary_email, _ := cfg.GetString("user", "primary_email")
	addrbook_tag, err := cfg.GetString("user", "addrbook_tag")
	if err != nil {
		addrbook_tag = "addressbook"
	}

	self := &address_matcher{db: nil,
		user_db_path:       db_path,
		user_primary_email: primary_email,
		user_addrbook_tag:  addrbook_tag}
	return self
}
Пример #10
0
func initGame() {
	g, err := goconfig.ReadConfigFile("test_config")
	db_name, err := g.GetString("DB", "db")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_host, err := g.GetString("DB", "host")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_user, err := g.GetString("DB", "user")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_pass, err := g.GetString("DB", "pass")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		panic(err)
	}
	out, err := exec.Command("sh", "create_tables.sh").Output()
	if err != nil {
		glog.Errorf("sh create_tables.sh %s\n%s", err, out)
		return
	}

	ConsoleDB(db)
	GameDB(db)
}
Пример #11
0
func parseConfig() {
	VERSION = "0.1.0.beta.5"
	c, _ := goconfig.ReadConfigFile("config.ini")
	nats_uri, _ = c.GetString("statistics", "nats_uri")
	logname, _ := c.GetString("logging", "file")
	logfile, err := os.OpenFile(logname, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)

	if err != nil {
		fmt.Printf("%s\r\n", err.Error())
	}

	logger = log.New(logfile, "\r", log.Ldate|log.Ltime)

	//debug config
	debug, _ := c.GetBool("debug", "enable")
	node, _ := c.GetString("debug", "debug_node")
	debug_node = node
	fmt.Println(debug_node)

	//puller config
	ft, _ := c.GetInt64("puller", "fetch_interval")
	fetch_interv = time.Duration(ft)
	varz_user, _ := c.GetString("puller", "varz_user")
	varz_pswd, _ := c.GetString("puller", "varz_pswd")
	varz_api, _ := c.GetString("puller", "varz_api")
	varz_port, _ := c.GetInt64("puller", "varz_port")
	node_addr, _ = localIP(debug)
	varz_uri = fmt.Sprintf("http://%s:%s@%s:%d/%s", varz_user,
		varz_pswd, node_addr, varz_port, varz_api)

	//sender config
	nt, _ := c.GetInt64("sender", "node_data_interval")
	ut, _ := c.GetInt64("sender", "instance_data_interval")
	isd, _ := c.GetInt64("sender", "instance_data_delay")
	collector_send_interv = time.Duration(ut)
	node_interv = time.Duration(nt)
	instance_data_delay = time.Duration(isd)

	//checker config
	it, _ := c.GetInt64("checker", "instance_interval")
	ic, _ := c.GetInt64("checker", "instance_check_delay")
	instance_check_interv = time.Duration(it)
	instance_check_delay = time.Duration(ic)

	//collector config
	col_addr, _ := c.GetString("collector", "address")
	base_full_data_api, _ := c.GetString("collector", "full_data_api")
	base_incre_data_api, _ := c.GetString("collector", "incre_data_api")
	base_node_data_api, _ := c.GetString("collector", "node_data_api")
	base_ins_check_api, _ := c.GetString("collector", "ins_check_api")
	ctm, _ := c.GetInt64("collector", "conn_timeout")
	rwtm, _ := c.GetInt64("collector", "rw_timeout")
	full_data_api = col_addr + base_full_data_api
	incre_data_api = col_addr + base_incre_data_api
	node_data_api = col_addr + base_node_data_api
	ins_check_api = col_addr + base_ins_check_api
	conn_timeout = time.Duration(ctm)
	rw_timeout = time.Duration(rwtm)
}
Пример #12
0
func getConfig() *goconfig.ConfigFile {
	confFile := filepath.Join(assetDir(), "gits3.ini")
	conf, err := goconfig.ReadConfigFile(confFile)
	if err != nil {
		log.Fatal(err)
	}
	return conf
}
Пример #13
0
func initPool() {
	configs, err := goconfig.ReadConfigFile(configFileName)

	if err != nil {
		logger.Criticalf("Can not read nsq configs from %s. Error: %s", configFileName, err)
		panic(err)
	}

	options, err := configs.GetOptions(nsqdConfigSection)

	if err != nil {
		logger.Criticalf("Can not read nsqd config in %s. Error: $s", configFileName, err)
		panic(err)
	}

	addrs := make([]string, 0, len(options))

	for _, option := range options {
		value, err := configs.GetString(nsqdConfigSection, option)

		if err != nil {
			logger.Errorf("Get error when reading section %s option %s in %s. Error: %s", nsqdConfigSection, option, configFileName, err)
			continue
		}

		addrs = append(addrs, value)
	}

	if len(addrs) <= 0 {
		logger.Criticalf("Read 0 configs for nsqd address in %s.", configFileName)
		panic("Read 0 configs for nsqd address in config file " + configFileName)
	}

	pool = make(map[string]*gonsq.Producer)
	lostConns = make([]string, 0)

	for _, addr := range addrs {
		config := gonsq.NewConfig()
		producer, err := gonsq.NewProducer(addr, config)

		if err != nil {
			logger.Errorf("Can not create nsq producer for address: %s. Error: %s", addr, err)
			continue
		}

		err = producer.Ping()

		if err != nil {
			logger.Errorf("Can not connect to address %s. Error: %s", addr, err)
			lostConns = append(lostConns, addr)
		}

		pool[addr] = producer
	}

	go autoReconnect()
}
Пример #14
0
func ParseConfig() APPLICATION_MODE {
	var aws_config_file string
	var base_config_file string
	var register bool
	var send bool
	var input_file string
	var output_file string
	var message_file string

	flag.StringVar(&base_config_file, "baseConfig", "./config/base.conf", "The path to the base configuration file")
	flag.StringVar(&aws_config_file, "awsConfig", "./config/aws.conf", "The path to the aws configuration file")

	flag.BoolVar(&register, "register", false, "Set flag to run in client mode and register a set of devices. If true inputFile and outputFile must be set.")
	flag.BoolVar(&send, "send", false, "Set flag to run in client mode and send push notifications to a set of arns. If true inputFile and outputFile must be set.")

	flag.StringVar(&input_file, "inputFile", "", "The path to the Device IDs or Arns file")
	flag.StringVar(&output_file, "outputFile", "", "The path to the Device IDs or Arns file")
	flag.StringVar(&message_file, "messageFile", "", "The path to the file containing the notificaito message to be sent out")

	flag.Parse()

	log.Printf("Using base configuration file: %s", base_config_file)
	baseConfig, err := goconfig.ReadConfigFile(base_config_file)
	checkError("Unable to parse base config", err)

	log.Printf("Using aws configuration file: %s", aws_config_file)
	awsConfig, err := goconfig.ReadConfigFile(aws_config_file)
	checkError("Unable to parse AWS config", err)

	parseBaseConfig(baseConfig)
	parseAwsConfig(awsConfig)

	if register {
		log.Printf("Running in client mode, registering devices listed in %s, and printing arns in %s", input_file, output_file)
		return REGISTER_MODE
	} else if send {
		log.Printf("Running in client mode, sending pusn notes to ARNs listed in %s, and printing results in %s", input_file, output_file)
		return SEND_MODE
	} else {
		log.Printf("Running in server mode")
		return SERVER_MODE
	}

}
Пример #15
0
func ConfigFile() {
	c, err := goconfig.ReadConfigFile("config.cfg")
	if err != nil {
		fmt.Println(err)
	}

	RedisAddress, _ = c.GetString("Redis", "RedisAddress")
	RedisPort, _ = c.GetString("Redis", "RedisPort")
	ESAPI, _ = c.GetString("ES", "API")
	//fmt.Println(RedisAddress + ":" + RedisPort + ":" + ESAPI)
}
Пример #16
0
func main() {
	c, err := goconfig.ReadConfigFile("config.cfg")
	if err != nil {
		fmt.Println("err")
	}
	// result is string :http://www.example.com/some/path"
	str, _ := c.GetString("service-1", "url")
	i, _ := c.GetInt64("service-1", "maxclients") // result is int 200
	b, _ := c.GetBool("service-1", "delegation")  // result is bool true

	fmt.Println(str, i, b)
}
Пример #17
0
func initTest(t *testing.T) {
	c, err := goconfig.ReadConfigFile("config")
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@"+db_host+"/"+db_name)
	if err != nil {
		panic(err)
	}
	_, err = db.Query("Drop table if exists users;")
	ec(t, "drop table things", err)
	_, err = db.Query("Drop table if exists sessions;")
	ec(t, "drop table sessions", err)
	DB(db)
	userDB()
	_, err = AddUser("a")
	_, err = AddUser("1")
	_, err = AddUser("2")
	_, err = AddUser("3")
	_, err = AddUser("4")
	_, err = AddUser("5")
	_, err = AddUser("6")
	_, err = AddUser("7")
	_, err = AddUser("8")
	_, err = AddUser("9")
	_, err = AddUser("0")
	_, err = AddUser(te)
	u, err := GetUserByEmail(te)
	if err := u.AddSession(sid); err != nil {
		t.Errorf("user.AddSession(%s): %s", sid, err)
	}
}
func main() {
	config, configError := goconfig.ReadConfigFile("spot-ec2-proxifier.ini")

	if configError != nil {
		fmt.Println(configError)
		return
	}

	// Setup our AWS credentials
	ak, _ := config.GetString("IAM", "access")
	sk, _ := config.GetString("IAM", "secret")
	rn, _ := config.GetString("EC2", "region")

	e, err := setupEC2(ak, sk, rn)
	if err != nil {
		fmt.Println("Something wrong in EC2 config:", err)
		return
	}

	// Get all current running instances
	rep, err := e.Instances(nil, nil)
	if err != nil {
		fmt.Println("Couldn't list instances", err)
		return
	}

	// Find whether any are ours
	tag, _ := config.GetString("EC2", "tag")
	inst, found := findTaggedInstance(rep.Reservations, tag)

	if found {
		fmt.Println("Found tagged instance:", inst.DNSName)

		// Launch plink on that instance
		bindPort, _ := config.GetInt64("Proxy", "bind_port")
		keyPath, _ := config.GetString("Proxy", "key_file")
		username, _ := config.GetString("EC2", "username")

		if username == "" {
			username = "******"
		}

		connectPlink(username, inst.DNSName, keyPath, int(bindPort))

	} else {
		fmt.Println("No instance up, creating a new one")
	}
}
Пример #19
0
func initConsumer() {
	configs, err := goconfig.ReadConfigFile(configFileName)

	if err != nil {
		logger.Criticalf("Can not read nsqlookup config from %s. Error: %s", configFileName, err)
		panic(err)
	}

	options, err := configs.GetOptions(nsqlookupSection)

	if err != nil {
		logger.Criticalf("Can not find configs for nsqlookup in %s. Error: %s", configFileName, err)
		panic(err)
	}

}
Пример #20
0
func GetConfig(path string) *goconfig.ConfigFile {
	if Config != nil {
		return Config
	}

	if path == "" {
		path = "gobb.conf"
	}

	var err error
	Config, err = goconfig.ReadConfigFile(path)
	if err != nil {
		log.Fatalln("Could not read config file", err)
	}

	return Config
}
Пример #21
0
func main() {
	flag.Parse()
	var err error
	var conn broker.Connection

	config_file := os.Getenv("GOGIX_CONF")
	if strings.TrimSpace(config_file) == "" {
		config_file = "/etc/gogix/gogix.conf"
	}

	Cfg, err = goconfig.ReadConfigFile(config_file)
	utils.CheckPanic(err, "File not found")

	bind_addr, err := Cfg.GetString("server", "bind_addr")
	utils.CheckPanic(err, "Unable to get bind_addr from gogix.conf")
	conn.Queue, err = Cfg.GetString("transport", "queue")
	utils.CheckPanic(err, "Unable to get queue from gogix.conf")
	conn.Uri, err = Cfg.GetString("transport", "uri")
	utils.CheckPanic(err, "Unable to get transport from gogix.conf")
	conn.Expiration, err = Cfg.GetString("transport", "message_ttl")
	utils.CheckPanic(err, "Unable to get message_ttl from gogix.conf")
	addr, err := net.ResolveUDPAddr("udp", bind_addr)
	utils.CheckPanic(err, "Unable to resolve bind address")
	l, err := net.ListenUDP("udp", addr)
	utils.CheckPanic(err, fmt.Sprintf("Unable to bind %s", addr))

	if *debug == true {
		fmt.Printf("Setting-Up Broker %s\n", conn.Uri)
	}
	conn.SetupBroker()
	go conn.ReconnectOnClose()

	for {
		recv := make([]byte, 1024)
		_, remote_addr, err := l.ReadFromUDP(recv)
		utils.Check(err, "Problem receiving data")
		fmt.Println(recv)
		if err == nil {
			ip := fmt.Sprintf("%s", remote_addr.IP)
			go handle_data(string(recv), conn, ip)
		}
	}

	conn.Close()
}
Пример #22
0
func (c *ConfigConf) parseFile(filename string) {

	config, err := goconfig.ReadConfigFile(filename)

	if err != nil {
		fmt.Println(err)
		log.Fatal(err.Error())
	} else {
		username, _ := config.GetString("default", "Username")
		password, _ := config.GetString("default", "Password")
		smtp, _ := config.GetString("default", "Smtphost")

		c.EmailCfg.SetUsername(username)
		c.EmailCfg.SetPassword(password)
		c.EmailCfg.SetSmtp(smtp)
		fmt.Println(username)
	}

}
Пример #23
0
func init() {
	var err error
	flag.Parse()
	c, err := goconfig.ReadConfigFile("config")
	if err != nil {
		err.Error()
	}
	port, err = c.GetString("Web", "port")
	if err != nil {
		err.Error()
	}
	environment, err = c.GetString("Web", "environment")
	if err != nil {
		err.Error()
	}
	cookieName = "feedinator_auth_" + environment
	mc.Prefix = (environment)
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	feed.Categoryinit(db, &mc)
	feed.Feedinit()
	feed.Entryinit()
	auth.DB(db)
}
Пример #24
0
func (conf *Config) ReadConf(file string) (*Config, error) {
	if file == "" {
		file = filepath.Join(DEFAULT_CONF_PATH, DEFAULT_CONF)
	}

	c, err := goconf.ReadConfigFile(file)
	if err != nil {
		return nil, err
	}

	//TODO: check
	conf.log, _ = c.GetString("default", "log")
	conf.level, _ = c.GetString("default", "level")
	//conf.timeout, _		= c.GetInt64("default", "timeout")
	//conf.timeout		= time.Duration(timeout) * time.Millisecond
	conf.lport, _ = c.GetString("default", "listen_port")
	conf.kaddr, _ = c.GetString("default", "kafka_addr")

	return conf, nil
}
Пример #25
0
func init() {
	var err error
	flag.IntVar(&feed_id, "feed_id", 0, "Feed Id to update")
	flag.IntVar(&feed_id, "f", 0, "Feed Id to update")
	flag.StringVar(&config_file, "config", "../config", "Config file")
	flag.StringVar(&config_file, "c", "../config", "Config file")

	c, err := goconfig.ReadConfigFile(config_file)
	if err != nil {
		glog.Fatalf("Couldn't parse config file %s: %s", config_file, err)
	}
	environment, err = c.GetString("Web", "environment")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)

	if err != nil {
		glog.Fatalf("Config: %s", err)
	}
	feed.Categoryinit(db, &mc)
	feed.Feedinit()
	feed.Entryinit()
	mc.Prefix = (environment)
}
Пример #26
0
func init() {

	//初始化配置
	var configError error
	config, configError = goconfig.ReadConfigFile("conf.ini")
	if configError != nil {
		log.Panic("can not read the config file")
	}

	//初始化主机名
	var errHost error
	hostname, errHost = os.Hostname()
	if errHost != nil {
		log.Fatal("Hostname can not obtain!")
	}
	AppCommUnitInit()

	//端口
	Port, _ = config.GetString("server", "port")

	//初始化指令接收者
	configConsumer := nsq.NewConfig()
	consumerTopic, _ := config.GetString("message", "consumerTopic")
	log.Println("aaaaaaa")
	log.Println(consumerTopic)
	q, _ = nsq.NewConsumer(consumerTopic, "ch", configConsumer)

	//初始化指令发送者
	configProducer := nsq.NewConfig()
	nsq_url, _ := config.GetString("message", "nsq_url")
	w, _ = nsq.NewProducer(nsq_url, configProducer)

	delay, _ = config.GetInt64("message", "delay_time")

	//指令回复处理handler
	Receive(cs)
}
Пример #27
0
func GetEmailCfg(filename string) EmailCfg {
	var cfg EmailCfg

	config, err := goconfig.ReadConfigFile(filename)

	if err != nil {
		fmt.Println(err)
		log.Fatal(err.Error())
	} else {
		username, _ := config.GetString("default", "Username")
		password, _ := config.GetString("default", "Password")
		smtp, _ := config.GetString("default", "Smtphost")

		cfg.SetUsername(username)
		cfg.SetPassword(password)
		cfg.SetSmtp(smtp)

		//fmt.Println(username, password, smtp)

	}

	return cfg

}
Пример #28
0
func main() {
	var bytes int64
	var bytesDone int64

	flag.Parse()
	debug = *debug_flag

	log.Printf("loading config file from %s\n", *configFile)
	configF, err := goconfig.ReadConfigFile(*configFile)
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}

	pool_config, err := configF.GetInt64("Client", "threads")
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}
	if *pool_flag != 0 {
		pool = *pool_flag
	} else {
		pool = int(pool_config)
	}
	runtime.GOMAXPROCS(pool)

	dirList, err := configF.GetString("Client", "backup_dirs_secure")
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}

	excludeList, err := configF.GetString("Client", "exclude_dirs")
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}

	dataBaseName, err := configF.GetString("Client", "sql_file")
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}

	queueBlobDir, err := configF.GetString("Client", "queue_blobs")
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	} else {
		os.Mkdir(queueBlobDir+"/tmp", 0700)
		os.Mkdir(queueBlobDir+"/blob", 0700)
	}

	db, err := bdrsql.Init_db(dataBaseName, *newDB, debug)
	if err != nil {
		log.Printf("could not open %s, error: %s", dataBaseName, err)
	} else {
		log.Printf("opened database %v\n", dataBaseName)
	}

	err = bdrsql.CreateClientTables(db)
	if err != nil && debug == true {
		log.Printf("couldn't create tables: %s", err)
	} else {
		log.Printf("created tables\n")
	}

	log.Printf("backing up these directories: %s\n", dirList)
	log.Printf("start walking...")
	t0 := time.Now()
	err = backupDir(db, dirList, excludeList, dataBaseName)
	t1 := time.Now()
	duration := t1.Sub(t0)
	if err != nil {
		log.Printf("walking didn't finished successfully. Error: %s", err)
	} else {
		log.Printf("walking successfully finished")
	}
	log.Printf("walking took: %v\n", duration)

	// shutdown database, make a copy, open it, backup copy of db
	// db, _ = bdrsql.BackupDB(db,dataBaseName)
	// launch server to receive uploads
	tn0 := time.Now().UnixNano()
	for i := 0; i < pool; i++ {
		go bdrupload.Uploader(upchan, done, debug, queueBlobDir)
	}
	log.Printf("started %d uploaders\n", pool)
	// send all files to be uploaded to server.

	log.Printf("started sending files to uploaders...\n")
	bdrsql.SQLUpload(db, upchan)
	bytesDone = 0
	bytes = 0
	for i := 0; i < pool; i++ {
		bytes = <-done
		bytesDone += bytes
	}
	tn1 := time.Now().UnixNano()
	if debug == true {
		seconds := float64(tn1-tn0) / 1000000000
		log.Printf("%d threads %s %s/sec in %4.2f seconds\n", pool, ByteSize(float64(bytesDone)), ByteSize(float64(bytesDone)/seconds), seconds)
	}
	log.Printf("uploading successfully finished\n")
}
Пример #29
0
func init() {
	TaskBoardService = new(TaskBoardServiceImpl)

	c, err := goconfig.ReadConfigFile("taskboard.ini")
	if err != nil {
		panic(err)
	}
	/*
	 * =======
	 * WEB
	 * =======
	 */
	ContentDir, _ = c.GetString("web", "dir")
	ContentDir = replaceOsEnv(ContentDir)
	fmt.Println("[web]dir=", ContentDir)
	IpPort, _ = c.GetString("web", "ip_port")
	IpPort = replaceOsEnv(IpPort)
	fmt.Println("[web]ip_port=", IpPort)
	HttpsOnly, _ = c.GetBool("web", "https_only")
	fmt.Println("[web]https_only=", HttpsOnly)
	postLimit, _ = c.GetInt64("web", "post_limit")
	fmt.Println("[web]post_limit=", postLimit)

	/*
	 * =======
	 * LOG
	 * =======
	 */
	//// log configuration - its the same the default
	level, _ := c.GetString("log", "level")
	level = replaceOsEnv(level)
	fmt.Println("[log]level=", level)
	file, _ := c.GetString("log", "file")
	file = replaceOsEnv(file)
	fmt.Println("[log]file=", file)
	count, _ := c.GetInt64("log", "count")
	fmt.Println("[log]count=", count)
	size, _ := c.GetInt64("log", "size")
	fmt.Println("[log]size=", size)
	logToConsole, _ := c.GetBool("log", "console")
	fmt.Println("[log]console=", logToConsole)

	logLevel := log.ParseLevel(level, log.ERROR)
	if logLevel <= log.INFO {
		log.ShowCaller(true)
	}

	// setting root writers
	writers := make([]log.LogWriter, 0)
	writers = append(writers, log.NewRollingFileAppender(file, size, int(count), true))
	if logToConsole {
		writers = append(writers, log.NewConsoleAppender(false))
	}
	log.Register("/", logLevel, writers...)

	//log.Register("/", logLevel, log.NewRollingFileAppender(file, size, int(count), true))

	//master.SetLevel("pqp", log.LogLevel(level))
	logger = log.LoggerFor("taskboad/biz/impl")

	// smtp
	SmtpHost, _ = c.GetString("smtp", "host")
	SmtpHost = replaceOsEnv(SmtpHost)
	fmt.Println("[smtp]host=", SmtpHost)
	SmtpPort, _ = c.GetString("smtp", "port")
	SmtpPort = replaceOsEnv(SmtpPort)
	fmt.Println("[smtp]port=", SmtpPort)
	SmtpUser, _ = c.GetString("smtp", "user")
	SmtpUser = replaceOsEnv(SmtpUser)
	fmt.Println("[smtp]user="******"smtp", "pass")
	SmtpPass = replaceOsEnv(SmtpPass)
	SmtpFrom, _ = c.GetString("smtp", "from")
	SmtpFrom = replaceOsEnv(SmtpFrom)
	fmt.Println("[smtp]from=", SmtpFrom)

	/*
	 * =======================
	 * BEGIN DATABASE CONFIG
	 * =======================
	 */
	// database configuration
	driverName, _ := c.GetString("database", "driver_name")
	driverName = replaceOsEnv(driverName)
	fmt.Println("[database]driver_name=", driverName)
	dataSourceName, _ := c.GetString("database", "data_source_name")
	dataSourceName = replaceOsEnv(dataSourceName)
	fmt.Println("[database]data_source_name=", dataSourceName)
	statementCache, _ := c.GetInt64("database", "statement_cache")
	fmt.Println("[database]statement_cache=", statementCache)
	idle, _ := c.GetInt64("database", "idle_connections")
	fmt.Println("[database]idle_connections=", idle)

	appDB, err := sql.Open(driverName, dataSourceName)
	if err != nil {
		panic(err)
	}

	if idle > 0 {
		appDB.SetMaxIdleConns(int(idle))
	}

	// wake up the database pool
	err = appDB.Ping()
	if err != nil {
		panic(err)
	}

	var translator = trx.NewMySQL5Translator()
	TM = db.NewTransactionManager(
		// database
		appDB,
		// databse context factory - called for each transaction
		func(inTx *bool, c dbx.IConnection) db.IDb {
			return db.NewDb(inTx, c, translator)
		},
		// statement cache
		int(statementCache),
	)
	/*
	 * =======================
	 * END DATABASE CONFIG
	 * =======================
	 */

	Poll = poller.NewPoller(30 * time.Second)
}
Пример #30
0
package util

import (
	"database/sql"
	"fmt"
	"github.com/hoisie/mustache"
	_ "github.com/jbarham/gopgsqldriver"
	"github.com/msbranco/goconfig"
)

var Config, _ = goconfig.ReadConfigFile("goblog.conf")
var db *sql.DB

type Entry struct {
	Id             int
	Title, Content string
}

func GetDb() *sql.DB {
	if db != nil {
		return db
	}

	db_username, _ := Config.GetString("db", "username")
	db_password, _ := Config.GetString("db", "password")
	db_database, _ := Config.GetString("db", "database")
	db_hostname, _ := Config.GetString("db", "hostname")
	db_port, _ := Config.GetString("db", "port")

	db, err := sql.Open("postgres", "user="******" password="******" dbname="+db_database+" host="+db_hostname+" port="+db_port)