예제 #1
0
파일: client.go 프로젝트: ushis/viscum
// 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)
	}
}
예제 #2
0
파일: server.go 프로젝트: ushis/viscum
// 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()
}