NewFs creates a new Fs object from the name and root. It connects to the host specified in the config file.
(ctx context.Context, name, root string, m configmap.Mapper)
| 308 | // NewFs creates a new Fs object from the name and root. It connects to |
| 309 | // the host specified in the config file. |
| 310 | func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, error) { |
| 311 | // Parse config into Options struct |
| 312 | opt := new(Options) |
| 313 | err := configstruct.Set(m, opt) |
| 314 | if err != nil { |
| 315 | return nil, err |
| 316 | } |
| 317 | |
| 318 | ci := fs.GetConfig(ctx) |
| 319 | f := &Fs{ |
| 320 | name: name, |
| 321 | root: root, |
| 322 | opt: *opt, |
| 323 | ci: ci, |
| 324 | } |
| 325 | f.features = (&fs.Features{ |
| 326 | ReadMetadata: true, |
| 327 | CanHaveEmptyDirectories: true, |
| 328 | }).Fill(ctx, f) |
| 329 | |
| 330 | // Make the http connection |
| 331 | isFile, err := f.httpConnection(ctx, opt) |
| 332 | if err != nil { |
| 333 | return nil, err |
| 334 | } |
| 335 | |
| 336 | if isFile { |
| 337 | // return an error with an fs which points to the parent |
| 338 | return f, fs.ErrorIsFile |
| 339 | } |
| 340 | |
| 341 | if !strings.HasSuffix(f.endpointURL, "/") { |
| 342 | return nil, errors.New("internal error: url doesn't end with /") |
| 343 | } |
| 344 | |
| 345 | return f, nil |
| 346 | } |
| 347 | |
| 348 | // Name returns the configured name of the file system |
| 349 | func (f *Fs) Name() string { |
searching dependent graphs…