wfs.go 677 B

1234567891011121314151617181920212223242526272829303132333435
  1. package filesys
  2. import (
  3. "bazil.org/fuse/fs"
  4. "fmt"
  5. "google.golang.org/grpc"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. )
  8. type WFS struct {
  9. filer string
  10. }
  11. func NewSeaweedFileSystem(filer string) *WFS {
  12. return &WFS{
  13. filer: filer,
  14. }
  15. }
  16. func (wfs *WFS) Root() (fs.Node, error) {
  17. return &Dir{Path: "/", wfs: wfs}, nil
  18. }
  19. func (wfs *WFS) withFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
  20. grpcConnection, err := grpc.Dial(wfs.filer, grpc.WithInsecure())
  21. if err != nil {
  22. return fmt.Errorf("fail to dial %s: %v", wfs.filer, err)
  23. }
  24. defer grpcConnection.Close()
  25. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  26. return fn(client)
  27. }