// NewFs constructs an Fs from the path, container:path
NewFs constructs an Fs from the path, container:path
// NewFs constructs an Fs from the path container : path
func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
	opt := new(Options)
	err := configstruct.Set(m, opt)
	if err != nil {
		return nil, err
	}
	rootIsDir := strings.HasSuffix(root, "/")
	root = strings.Trim(root, "/")
	user := config.FileGet(name, "user")
	pass := config.FileGet(name, "pass")
	bearerToken := config.FileGet(name, "bearer_token")
	if !strings.HasSuffix(opt.URL, "/") {
		opt.URL += "/"
	}
	if opt.Pass != "" {
		var err error
		opt.Pass, err = obscure.Reveal(opt.Pass)
		if err != nil {
			return nil, errors.Wrap(err, "couldn't decrypt password")
		}
	}
	if opt.Vendor == "" {
		opt.Vendor = "other"
	}
	root = strings.Trim(root, "/")
	u, err := url.Parse(opt.URL)
	if err != nil {
		return nil, err
	}
	f := &Fs{
		name:        name,
		root:        root,
		opt:         *opt,
		endpoint:    u,
		endpointURL: u.String(),
		srv:         rest.NewClient(fshttp.NewClient(fs.Config)).SetRoot(u.String()),
		pacer:       pacer.New().SetMinSleep(minSleep).SetMaxSleep(maxSleep).SetDecayConstant(decayConstant),
		precision:   fs.ModTimeNotSupported,
	}
	f.features = (&fs.Features{
		CanHaveEmptyDirectories: true,
	}).Fill(f)
	if user != "" || pass != "" {
		f.srv.SetUserPass(opt.User, opt.Pass)
	} else if bearerToken != "" {
		f.srv.SetHeader("Authorization", "BEARER "+bearerToken)
	}
	f.srv.SetErrorHandler(errorHandler)
	err = f.setQuirks(opt.Vendor)
	if err != nil {
		return nil, err
	}
	if root != "" && !rootIsDir {
		remote := path.Base(root)
		f.root = path.Dir(root)
		if f.root == "." {
			f.root = ""
		}
		_, err := f.NewObject(remote)
		if err != nil {
			if errors.Cause(err) == fs.ErrorObjectNotFound || errors.Cause(err) == fs.ErrorNotAFile {
				f.root = root
				return f, nil
			}
			return nil, err
		}
		return f, fs.ErrorIsFile
	}
	return f, nil
}
func NewFs ( name , root string , m configmap . Mapper ) ( fs . Fs , error ) { opt := new ( Options ) err := configstruct . Set ( m , opt ) if err != nil { return nil , err } rootIsDir := strings . HasSuffix ( root , " " ) root = strings . Trim ( root , " " ) user := config . FileGet ( name , " " ) pass := config . FileGet ( name , " " ) bearerToken := config . FileGet ( name , " " ) if ! strings . HasSuffix ( opt . URL , " " ) { opt . URL += " " } if opt . Pass != " " { var err error opt . Pass , err = obscure . Reveal ( opt . Pass ) if err != nil { return nil , errors . Wrap ( err , " " ) } } if opt . Vendor == " " { opt . Vendor = " " } root = strings . Trim ( root , " " ) u , err := url . Parse ( opt . URL ) if err != nil { return nil , err } f := & Fs { name : name , root : root , opt : * opt , endpoint : u , endpointURL : u . String ( ) , srv : rest . NewClient ( fshttp . NewClient ( fs . Config ) ) . SetRoot ( u . String ( ) ) , pacer : pacer . New ( ) . SetMinSleep ( minSleep ) . SetMaxSleep ( maxSleep ) . SetDecayConstant ( decayConstant ) , precision : fs . ModTimeNotSupported , } f . features = ( & fs . Features { CanHaveEmptyDirectories : true , } ) . Fill ( f ) if user != " " || pass != " " { f . srv . SetUserPass ( opt . User , opt . Pass ) } else if bearerToken != " " { f . srv . SetHeader ( " " , " " + bearerToken ) } f . srv . SetErrorHandler ( errorHandler ) err = f . setQuirks ( opt . Vendor ) if err != nil { return nil , err } if root != " " && ! rootIsDir { remote := path . Base ( root ) f . root = path . Dir ( root ) if f . root == " " { f . root = " " } _ , err := f . NewObject ( remote ) if err != nil { if errors . Cause ( err ) == fs . ErrorObjectNotFound || errors . Cause ( err ) == fs . ErrorNotAFile { f . root = root return f , nil } return nil , err } return f , fs . ErrorIsFile } return f , nil }
NewFs constructs an Fs from the path, container:path
NewFs constructs an Fs from the path container : path
// Parse config into Options struct // Parse the endpoint // Check to see if the root actually an existing file // File doesn't exist so return old f // return an error with an fs which points to the parent