You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
665 B

  1. package filesys
  2. import (
  3. "bazil.org/fuse/fs"
  4. "fmt"
  5. "google.golang.org/grpc"
  6. "github.com/chrislusf/seaweedfs/weed/filer"
  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.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.NewSeaweedFilerClient(grpcConnection)
  26. return fn(client)
  27. }