backend

package
v2.1.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backend provides a means of allowing backend filesystems to self-register on load via an init() call to backend.Register("some name", vfs.Filesystem)

In this way, a caller of vfs backends can simply load the backend filesystem (and ONLY those needed) and begin using it:

package main

// import backend and each backend you intend to use
import(
    "github.com/c2fo/vfs/backend"
    "github.com/c2fo/vfs/backend/os"
    "github.com/c2fo/vfs/backend/s3"
)

func main() {
   var err error
   var osfile, s3file vfs.File

    // THEN begin using the filesystems
    osfile, err = backend.Backend(os.Scheme).NewFile("", "/path/to/file.txt")
    if err != nil {
        panic(err)
    }

    s3file, err = backend.Backend(s3.Scheme).NewFile("mybucket", "/some/file.txt")
    if err != nil {
        panic(err)
    }

    err = osfile.CopyTo(s3file)
    if err != nil {
        panic(err)
    }
}

Development

To create your own backend, you must create a package that implements the interfaces: vfs.Filesystem, vfs.Location, and vfs.File. Then ensure it registers itself on load:

package myexoticfilesystem

import(
    ...
    "github.com/c2fo/vfs"
    "github.com/c2fo/vfs/backend"
)

// IMPLEMENT vfs interfaces
...

// register backend
func init() {
    backend.Register("exfs", &MyExoticFilesystem{})
}

Then do use it in some other package do

package MyExoticFilesystem

import(
    "github.com/c2fo/vfs/backend"
    "github.com/acme/myexoticfilesystem"
)

...

func useNewBackend() error {
    myExoticFs, err = backend.Backend(myexoticfilesystem.Scheme)
    ...
}

That's it. Simple.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backend

func Backend(name string) vfs.FileSystem

Backend returns the backend filesystem by name

func Register

func Register(name string, v vfs.FileSystem)

Register a new filesystem in backend map

func RegisteredBackends

func RegisteredBackends() []string

RegisteredBackends returns an array of backend names

func Unregister

func Unregister(name string)

Unregister unregisters a filesystem from backend map

func UnregisterAll

func UnregisterAll()

UnregisterAll unregisters all filesystems from backend map

Types

This section is empty.

Directories

Path Synopsis
Package all imports all VFS implementations.
Package all imports all VFS implementations.
Package gs Google Cloud Storage VFS implementation.
Package gs Google Cloud Storage VFS implementation.
Package os built-in os lib VFS implementation.
Package os built-in os lib VFS implementation.
Package s3 AWS S3 VFS implementation.
Package s3 AWS S3 VFS implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL