Beispiel #1
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: %s <mountpath>")
		os.Exit(1)
	}
	root := os.Args[1]

	hfs := &HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}

	nfs := pathfs.NewPathNodeFs(hfs, nil)
	fuseSrv, _, err := nodefs.MountRoot(root, nfs.Root(), nil)
	if err != nil {
		log.Fatal(err)
	}
	go fuseSrv.Serve()
	l, err := net.Listen("tcp", "127.0.0.1:50000")
	if err != nil {
		log.Fatal(err)
	}
	s := grpc.NewServer()
	pb.RegisterPathFSServer(s, server.New(hfs))
	go s.Serve(l)
	log.Printf("Listen on %s for dir %s", l.Addr(), root)
	sigCh := make(chan os.Signal)
	signal.Notify(sigCh, os.Interrupt)
	for range sigCh {
		fuseSrv.Unmount()
		s.Stop()
		os.Exit(0)
	}
}
Beispiel #2
0
func startLoopbackServer(root string) (*loopbackServer, error) {
	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		return nil, err
	}
	s := grpc.NewServer()
	nfs := pathfs.NewLoopbackFileSystem(root)
	pb.RegisterPathFSServer(s, server.New(nfs))
	go s.Serve(l)
	return &loopbackServer{
		Server: s,
		Addr:   l.Addr().String(),
	}, nil
}
Beispiel #3
0
func startServer(root string, fs pathfs.FileSystem) (*helloServer, error) {
	nfs := pathfs.NewPathNodeFs(fs, nil)
	fuseSrv, _, err := nodefs.MountRoot(root, nfs.Root(), nil)
	if err != nil {
		return nil, err
	}
	go fuseSrv.Serve()
	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		return nil, err
	}
	s := grpc.NewServer()
	pb.RegisterPathFSServer(s, server.New(fs))
	go s.Serve(l)
	return &helloServer{
		fsSrv: fuseSrv,
		gSrv:  s,
		addr:  l.Addr(),
	}, nil
}