コード例 #1
0
ファイル: ios_push.go プロジェクト: jinhao/apns
func read_cfg(cfg_file string) error {
	c, err := goconfig.ReadConfigFile(cfg_file)
	if err != nil {
		log.Infof("read_cfg | read_cfg | err:", err)
		return err
	}
	saddr, _ := c.GetString("server", "addr")
	z_addr, _ := c.GetString("zookeeper", "addr")
	z_path, _ := c.GetString("zookeeper", "path")
	m_addr, _ := c.GetString("mongodb", "addr")
	d_xpush, _ := c.GetString("mongodb", "db_xpush")
	c_xpush, _ := c.GetString("mongodb", "collection_xpush")

	if saddr != "" {
		server_addr = &saddr
	}
	if z_addr != "" {
		zk_addr = &z_addr
	}
	if z_path != "" {
		zk_path = &z_path
	}
	if m_addr != "" {
		mgo_addr = &m_addr
	}
	if d_xpush != "" {
		db_xpush = &d_xpush
	}
	if c_xpush != "" {
		collection_xpush = &c_xpush
	}
	return nil
}
コード例 #2
0
ファイル: main.go プロジェクト: chenzhe07/qtunnel
func main() {
	var faddr, baddr, cryptoMethod, secret, logTo, conf string
	var clientMode, daemon bool
	flag.StringVar(&logTo, "logto", "stdout", "stdout or syslog")
	flag.StringVar(&faddr, "listen", ":9001", "host:port qtunnel listen on")
	flag.StringVar(&baddr, "backend", "127.0.0.1:6400", "host:port of the backend")
	flag.StringVar(&cryptoMethod, "crypto", "rc4", "encryption method")
	flag.StringVar(&secret, "secret", "secret", "password used to encrypt the data")
	flag.StringVar(&conf, "conf", "", "read connection setup from config file")
	flag.BoolVar(&clientMode, "clientmode", false, "if running at client mode")
	flag.BoolVar(&daemon, "daemon", false, "running in daemon mode")
	flag.Parse()

	log.SetOutput(os.Stdout)
	if logTo == "syslog" {
		w, err := syslog.New(syslog.LOG_INFO, "qtunnel")
		if err != nil {
			log.Fatal(err)
		}
		log.SetOutput(w)
	}
	CurDir, _ := os.Getwd()

	if daemon == true {
		godaemon.MakeDaemon(&godaemon.DaemonAttr{})
	}
	// start from config file for multi-front-port
	if len(conf) > 0 {
		if match, _ := regexp.MatchString("^[^/]", conf); match {
			conf = CurDir + "/" + conf
		}
		c, err := goconfig.ReadConfigFile(conf)
		if err != nil {
			log.Printf("read error from %s file", conf)
			os.Exit(1)
		}
		sections := c.GetSections()
		for _, s := range sections {
			if s == "default" {
				continue
			}
			fdr, _ := c.GetString(s, "faddr")
			bdr, _ := c.GetString(s, "baddr")
			cld, _ := c.GetBool(s, "clientmode")
			crt, _ := c.GetString(s, "cryptoMethod")
			set, _ := c.GetString(s, "secret")

			go func() {
				t := tunnel.NewTunnel(fdr, bdr, cld, crt, set, 4096)
				log.Printf("qtunnel start from %s to %s.", fdr, bdr)
				t.Start()
			}()
		}
	} else {
		t := tunnel.NewTunnel(faddr, baddr, clientMode, cryptoMethod, secret, 4096)
		log.Println("qtunnel started.")
		go t.Start()
	}
	waitSignal()
}