Exemplo n.º 1
0
// Lets go.
func main() {
	flag.Parse()

	// Read the config.
	conf, err := util.ReadConfig(configFile)
	if err != nil {
		util.Fatal(err)
	}

	// Find the correct function for the command.
	cmd, ok := commands[flag.Arg(0)]
	if !ok {
		usage()
	}

	// Connect to the server.
	client := rpc.NewClient(conf.Get("rpc", "socket"))

	if err := client.Connect(); err != nil {
		util.Fatal(err)
	}
	defer client.Close()

	// Execute the command.
	reply, err := cmd(client)

	if err != nil {
		util.Fatal(err)
	}

	for _, line := range reply.Response() {
		fmt.Println(line)
	}
}
Exemplo n.º 2
0
// Sets up everything and waits for SIGINT.
func main() {
	flag.Parse()

	// Read the config.
	conf, err := util.ReadConfig(configFile)
	if err != nil {
		util.Fatal(err)
	}

	// Connect to the database.
	database := db.New(conf.Get("database", "driver"))

	if err = database.Open(conf.Get("database", "auth")); err != nil {
		util.Fatal(err)
	}
	defer database.Close()

	// Set up the mailer.
	m := mailer.New(database, conf)
	go m.Start()

	// Set up the fetcher.
	f := fetcher.New(database, conf, m.Ctrl)
	go f.Start()

	// Set up the rpc.
	r := rpc.New(database, conf.Get("rpc", "socket"), m.Ctrl, f.Ctrl)
	go r.Start()

	// Listen to SIGINT
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGINT)

	// Wait for SIGINT and notify goroutines.
	<-sig
	r.Stop()
	f.Stop()
	m.Stop()
}