aegistudio / go-winfsp

WinFSP's native API binding for Golang
MIT License
16 stars 0 forks source link

hi #1

Open user1121114685 opened 1 year ago

user1121114685 commented 1 year ago

Hello, aegistudio! Sorry to bother you, I have checked a lot of information, but none of them can be directly mounted from webdav to the window disk. Winfsp is indeed difficult to get started. So it would be more friendly to all if there was a demonstration!

webdav: http://127.0.01/dav
userName:user
Password:123456

Looking forward to your response

aegistudio commented 1 year ago

Do you mean to access a WebDAV server via a pseudo Windows local disk?

I think you should have a look at the github.com/aegistudio/go-winfsp/gofs package, and implement a gofs.FileSystem which is a WebDAV client to request the server.

user1121114685 commented 1 year ago

Thank you very much for your reply, I will try it right away.

user1121114685 commented 1 year ago

Hello, I didn't find the mount function, is there a simple usage example?

aegistudio commented 1 year ago

You could use this function: https://pkg.go.dev/github.com/aegistudio/go-winfsp?GOOS=windows#Mount

If you are not a master in Windows filesystem API's protocol (and/or 100% familiar with winfsp API), it's recommended to incorporate the helper package gofs with your code: https://pkg.go.dev/github.com/aegistudio/go-winfsp@v1.0.0/gofs?GOOS=windows

Something like:

package main

import (
  "context"

  "github.com/aegistudio/go-winfsp"
  "github.com/aegistudio/go-winfsp/gofs"
)

type mygoFs struct {
}

func (*mygoFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
    // open your file implementing gofs.File here.
    ....
}

... // Also implement other interfaces of gofs.FileSystem for mygoFs

// Wrap it with main or cobra.Command.RunE?
func run(ctx context.Context) error {
  fileSystem, err := winfsp.Mount(gofs.New(&mygoFs{}), 'X:\')
  if err != nil {
    return err
  }
  defer fileSystem.Unmount()
  <-ctx.Done() // Maybe waiting for Ctrl-C.
}