示例#1
0
func read_cfg() {
	app_cfg := make(map[string]string)
	err := cfg.Load("log.cfg", app_cfg)
	if err != nil {
		log.Fatal(err)
	}
	root, present := app_cfg["root"]
	if !present {
		fmt.Println("need config root directory")
		os.Exit(1)
	}
	ROOT = root

	port, present := app_cfg["port"]
	if !present {
		fmt.Println("need config listen port")
		os.Exit(1)
	}
	nport, err := strconv.Atoi(port)
	if err != nil {
		fmt.Println("need config listen port")
		os.Exit(1)
	}
	PORT = nport
	fmt.Printf("root:%s port:%d\n", ROOT, PORT)

	if _, present = app_cfg["bind_addr"]; present {
		BIND_ADDR = app_cfg["bind_addr"]
	}
	fmt.Printf("root:%s bind addr:%s port:%d\n", ROOT, BIND_ADDR, PORT)

}
示例#2
0
func read_cfg(cfg_path string) {
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	port, present := app_cfg["port"]
	if !present {
		fmt.Println("need config listen port")
		os.Exit(1)
	}
	nport, err := strconv.Atoi(port)
	if err != nil {
		fmt.Println("need config listen port")
		os.Exit(1)
	}
	PORT = nport
	fmt.Println("port:", PORT)
	peers, present := app_cfg["peers"]
	if !present {
		return
	}
	arr := strings.Split(peers, ",")
	for _, item := range arr {
		t := strings.Split(item, ":")
		host := t[0]
		port, _ := strconv.Atoi(t[1])
		ip := net.ParseIP(host)
		addr := &net.TCPAddr{ip, port, ""}
		PEER_ADDRS = append(PEER_ADDRS, addr)
	}

	fmt.Println("addrs:", PEER_ADDRS)
}
示例#3
0
func read_cfg(cfg_path string) *Config {
	config := new(Config)
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	config.port = get_int(app_cfg, "port")
	config.http_listen_address = get_string(app_cfg, "http_listen_address")
	config.redis_address = get_string(app_cfg, "redis_address")
	config.mysqldb_datasource = get_string(app_cfg, "mysqldb_source")
	config.mysqldb_appdatasource = get_string(app_cfg, "mysqldb_appsource")
	config.socket_io_address = get_string(app_cfg, "socket_io_address")

	str := get_string(app_cfg, "storage_pool")
	array := strings.Split(str, " ")
	config.storage_addrs = array
	if len(config.storage_addrs) == 0 {
		log.Fatal("storage pool config")
	}

	str = get_string(app_cfg, "route_pool")
	array = strings.Split(str, " ")
	config.route_addrs = array
	if len(config.route_addrs) == 0 {
		log.Fatal("route pool config")
	}

	return config
}
示例#4
0
func main() {
	mymap := make(map[string]string)
	err := cfg.Load("test.cfg", mymap)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v\n", mymap)
}
示例#5
0
// loadConfig load the config file "bees.cfg""
func loadConfig() map[string]string {
	m := make(map[string]string)
	err := cfg.Load("21tweet.cfg", m)
	if err != nil {
		log.Fatal(err)
	}

	return m
}
示例#6
0
func read_route_cfg(cfg_path string) *RouteConfig {
	config := new(RouteConfig)
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	config.listen = get_string(app_cfg, "listen")
	return config
}
示例#7
0
func read_cfg(cfg_path string) *Config {
	config := new(Config)
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	config.port = get_int(app_cfg, "port")
	config.tunnel_port = get_int(app_cfg, "tunnel_port")
	config.tunnel_port_v2 = get_int(app_cfg, "tunnel_port_v2")
	config.redis_address = get_string(app_cfg, "redis_address")
	return config
}
示例#8
0
func read_storage_cfg(cfg_path string) *StorageConfig {
	config := new(StorageConfig)
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	config.listen = get_string(app_cfg, "listen")
	config.storage_root = get_string(app_cfg, "storage_root")
	config.redis_address = get_string(app_cfg, "redis_address")
	config.mysqldb_datasource = get_string(app_cfg, "mysqldb_source")
	config.sync_listen = get_string(app_cfg, "sync_listen")
	config.master_address = get_opt_string(app_cfg, "master_address")
	return config
}
示例#9
0
func read_api_cfg(cfg_path string) *APIConfig {
	config := new(APIConfig)
	app_cfg := make(map[string]string)
	err := cfg.Load(cfg_path, app_cfg)
	if err != nil {
		log.Fatal(err)
	}

	config.port = get_int(app_cfg, "port")
	config.redis_address = get_string(app_cfg, "redis_address")
	config.mysqldb_datasource = get_string(app_cfg, "mysqldb_source")
	config.appdb_datasource = get_string(app_cfg, "appdb_source")
	config.im_url = get_string(app_cfg, "im_url")

	return config
}
示例#10
0
func main() {
	//load the configuration
	configs := make(map[string]string)
	err := cfg.Load("iotfc.cfg", configs)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v\n", configs)

	//create a ClientOptions struct setting the broker address, clientid, turn
	//off trace output and set the default message handler
	opts := MQTT.NewClientOptions().AddBroker(configs["url"])
	opts.SetClientID("go-simple")
	opts.SetDefaultPublishHandler(f)

	//create and start a client using the above ClientOptions
	c := MQTT.NewClient(opts)
	if token := c.Connect(); token.Wait() && token.Error() != nil {
		panic(token.Error())
	}

	//subscribe to the topic /go-mqtt/sample and request messages to be delivered
	//at a maximum qos of zero, wait for the receipt to confirm the subscription
	if token := c.Subscribe("go-mqtt/sample", 0, nil); token.Wait() && token.Error() != nil {
		fmt.Println(token.Error())
		os.Exit(1)
	}

	//Publish 5 messages to /go-mqtt/sample at qos 1 and wait for the receipt
	//from the server after sending each message
	for i := 0; i < 5; i++ {
		text := fmt.Sprintf("this is msg #%d!", i)
		token := c.Publish("go-mqtt/sample", 0, false, text)
		token.Wait()
	}

	time.Sleep(3 * time.Second)

	//unsubscribe from /go-mqtt/sample
	if token := c.Unsubscribe("go-mqtt/sample"); token.Wait() && token.Error() != nil {
		fmt.Println(token.Error())
		os.Exit(1)
	}

	c.Disconnect(250)
}
示例#11
0
文件: APIMeal.go 项目: vayan/11Meal
func load_conf() {
	if len(os.Args) < 2 {
		log.Fatalln("Usage :", os.Args[0], "path/server.cfg")
	}
	log.Println("=== Start loading conf files")
	conf := make(map[string]string)
	err := cfg.Load(os.Args[1], conf)
	checkFatal(err)
	if conf["gcm_api"] == "" || conf["place_api"] == "" {
		log.Fatalln("Please put the API key in the config file")
	}
	GCM_API_KEY = conf["gcm_api"]
	GPLACES_API_KEY = conf["place_api"]
	if len(conf["port"]) > 0 {
		port = ":" + conf["port"]
	}
	log.Println("=== Conf loaded, contain : \n", conf)
}
示例#12
0
func (this *TransformExecutor) startProducer() {
	producerConfig, err := kafka.ProducerConfigFromFile(this.config.ProducerConfig)
	if err != nil {
		panic(err)
	}

	cfgMap := make(map[string]string)
	err = cfg.Load(this.config.ProducerConfig, cfgMap)
	if err != nil {
		panic(err)
	}

	this.avroDecoder = kafka.NewKafkaAvroDecoder(cfgMap["schema.registry.url"])

	producerConfig.KeyEncoder = kafka.NewKafkaAvroEncoder(cfgMap["schema.registry.url"])
	producerConfig.ValueEncoder = producerConfig.KeyEncoder
	producerConfig.SendBufferSize = 10000
	producerConfig.BatchSize = 2000
	producerConfig.MaxMessagesPerRequest = 5000

	this.producer = kafka.NewSaramaProducer(producerConfig)
	go this.produceRoutine()
}
示例#13
0
// Loads a property file located at Path. Returns a map[string]string or error.
func LoadConfiguration(Path string) (map[string]string, error) {
	cfgMap := make(map[string]string)
	err := cfg.Load(Path, cfgMap)

	return cfgMap, err
}
示例#14
0
func (rc *ReadConfig) ReadConfigFile() error {
	if err := cfg.Load(rc.FileName, rc.ConfigMap); err != nil {
		return err
	}
	return nil
}
示例#15
0
func main() {
	configOptions := &ConfigOptions{}

	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}

	mymap := make(map[string]string)
	propFilename := filepath.Join(usr.HomeDir, ".tecsim")
	err = cfg.Load(propFilename, mymap)
	if err != nil {
		log.Fatal(err)
	}

	if val, ok := mymap["installed-chips"]; ok {
		configOptions.installed_chips = val
	} else {
		configOptions.installed_chips = filepath.Join(usr.HomeDir, "installed-chips")
	}

	chips.Init("And gate")
	chips.VerboseOutput()

	output, _ := chips.NewChip("Out")
	output.SetInputs("a")

	nand, _ := chips.NewChip("Nand", chips.ChipOut{Name: "a", ConnectedTo: output})
	nand.SetNickname("nand")

	not1, _ := chips.NewChip("Nand", chips.ChipOut{Name: "a", ConnectedTo: nand})
	not1.SetNickname("not1")

	not2, _ := chips.NewChip("Nand", chips.ChipOut{Name: "b", ConnectedTo: nand})
	not2.SetNickname("not2")

	input, _ := chips.NewChip("In",
		chips.ChipOut{"a", not1, "a"}, chips.ChipOut{"b", not1, "a"},
		chips.ChipOut{"a", not2, "b"}, chips.ChipOut{"b", not2, "b"})
	input.SetInputs("a", "b")
	input.SetInput("a", 1)
	input.SetInput("b", 1)

	chips.Process()

	chips.Reset()

	input.SetInput("a", 0)
	input.SetInput("b", 0)

	chips.Process()

	chips.Reset()

	input.SetInput("a", 1)
	input.SetInput("b", 0)

	chips.Process()

	chips.Reset()

	input.SetInput("a", 0)
	input.SetInput("b", 1)

	chips.Process()

	chips.Reset()

	input.SetInput("a", 1)
	input.SetInput("b", 1)

	chips.Process()
}