Example #1
0
func (s *UsersTestSuite) TearDownTest() {
	s.server.Close()
	datastore.DropTables()
	datastore.Exit()
}
Example #2
0
func (s *EnvelopeTokenTestSuite) TearDownTest() {
	s.server.Close()
	datastore.DropTables()
	datastore.Exit()
}
Example #3
0
func main() {
	// command usage
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, `
chatable

Usage:
        chatable [options] command [arg...]

Commands
`)
		for _, cmd := range subcmds {
			fmt.Fprintf(os.Stderr, "\t%s - %s\n", cmd.name, cmd.desc)
		}
		fmt.Fprintf(os.Stderr, `
Use "chatable command -h" for command help.

Options:
`)
		flag.PrintDefaults()
		os.Exit(1)
	}
	flag.Parse()
	if flag.NArg() == 0 {
		flag.Usage()
	}

	// parse the configuration file
	err := cfg.parse(*configFile)
	if err != nil {
		glog.Fatal(err)
	}

	// initialize database connection
	datastore.Init(cfg.Postgres)
	defer datastore.Exit()

	// initialize redis
	rds.Init(cfg.RedisHost)

	rdsPool := rds.NewRdsPool(nil)
	rdsPool.AddToQM(cfg.QueueManagerKey, cfg.MessageQueueKey)
	defer rdsPool.RemoveFromQM(cfg.QueueManagerKey, cfg.MessageQueueKey)

	go api.Hub.Run(cfg.SharedQueueKey)

	qm := api.QueueManager{}
	go qm.Dispatch(cfg.SharedQueueKey, cfg.QueueManagerKey)
	go qm.Pop(cfg.MessageQueueKey)

	subcmd := flag.Arg(0)
	for _, c := range subcmds {
		if c.name == subcmd {
			c.exec(flag.Args()[1:])
			return
		}
	}

	fmt.Fprintf(os.Stderr, "Unknown command %q\n", subcmd)
	flag.Usage()
	os.Exit(1)
}