예제 #1
0
파일: counter.go 프로젝트: alexclear/rpc
func main() {
	address := flag.String("address", ":65534", "")
	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCustomCodec(&rpc.CompressionSelector{}), "application/json")
	s.RegisterService(new(Counter), "")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./"))))
	http.Handle("/jsonrpc/", s)
	log.Fatal(http.ListenAndServe(*address, nil))
}
예제 #2
0
파일: main.go 프로젝트: sbinet/romba
func main() {
	config := new(Config)

	err := gcfg.ReadFileInto(config, "romba.ini")
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}

	for i := 0; i < len(config.Depot.MaxSize); i++ {
		config.Depot.MaxSize[i] *= int64(archive.GB)
	}

	runtime.GOMAXPROCS(config.General.Workers)

	flag.Set("log_dir", config.General.LogDir)
	flag.Set("alsologtostderr", "true")

	romDB, err := db.New(config.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "opening db failed: %v\n", err)
		os.Exit(1)
	}

	depot, err := archive.NewDepot(config.Depot.Root, config.Depot.MaxSize, romDB)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	go signalCatcher(romDB)

	rs := service.NewRombaService(romDB, depot, config.Index.Dats, config.General.Workers, config.General.LogDir)

	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCustomCodec(&rpc.CompressionSelector{}), "application/json")
	s.RegisterService(rs, "")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./web"))))
	http.Handle("/jsonrpc/", s)
	http.Handle("/progress", websocket.Handler(rs.SendProgress))

	fmt.Printf("starting romba server at localhost:%d/romba.html\n", config.Server.Port)

	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Server.Port), nil))
}
예제 #3
0
파일: main.go 프로젝트: uwedeportivo/romba
func main() {
	cfg := new(config.Config)

	iniPath, err := findINI()
	if err != nil {
		fmt.Fprintf(os.Stderr, "finding romba ini failed: %v\n", err)
		os.Exit(1)
	}

	err = gcfg.ReadFileInto(cfg, iniPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini from %s failed: %v\n", iniPath, err)
		os.Exit(1)
	}

	for i := 0; i < len(cfg.Depot.MaxSize); i++ {
		cfg.Depot.MaxSize[i] *= int64(archive.GB)
	}

	cfg.General.LogDir, err = filepath.Abs(cfg.General.LogDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.TmpDir, err = filepath.Abs(cfg.General.TmpDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	for i, pv := range cfg.Depot.Root {
		cfg.Depot.Root[i], err = filepath.Abs(pv)
		if err != nil {
			fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
			os.Exit(1)
		}
	}
	cfg.Index.Dats, err = filepath.Abs(cfg.Index.Dats)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.Index.Db, err = filepath.Abs(cfg.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.WebDir, err = filepath.Abs(cfg.General.WebDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}
	cfg.General.BadDir, err = filepath.Abs(cfg.General.BadDir)
	if err != nil {
		fmt.Fprintf(os.Stderr, "reading romba ini failed: %v\n", err)
		os.Exit(1)
	}

	config.GlobalConfig = cfg

	runtime.GOMAXPROCS(cfg.General.Cores)

	flag.Set("log_dir", cfg.General.LogDir)
	flag.Set("alsologtostderr", "true")
	flag.Set("v", strconv.Itoa(cfg.General.Verbosity))

	flag.Parse()

	romDB, err := db.New(cfg.Index.Db)
	if err != nil {
		fmt.Fprintf(os.Stderr, "opening db failed: %v\n", err)
		os.Exit(1)
	}

	depot, err := archive.NewDepot(cfg.Depot.Root, cfg.Depot.MaxSize, romDB)
	if err != nil {
		fmt.Fprintf(os.Stderr, "creating depot failed: %v\n", err)
		os.Exit(1)
	}

	rs := service.NewRombaService(romDB, depot, cfg)

	go signalCatcher(rs)

	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCustomCodec(&rpc.CompressionSelector{}), "application/json")
	s.RegisterService(rs, "")
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(cfg.General.WebDir))))
	http.Handle("/jsonrpc/", s)
	http.Handle("/progress", websocket.Handler(rs.SendProgress))

	fmt.Printf("starting romba server version %s at localhost:%d/romba.html\n", service.Version, cfg.Server.Port)

	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Server.Port), nil))
}