From b98923a20ff85ba813376ebb10b651c1c6226355 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 29 Jun 2013 12:15:31 +0100 Subject: [PATCH] drive: Finish refactor --- drive/fs.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drive/fs.go b/drive/fs.go index 6599efb99..a717de7c6 100644 --- a/drive/fs.go +++ b/drive/fs.go @@ -41,6 +41,14 @@ import ( "time" ) +// Pattern to match a drive url +var Match = regexp.MustCompile(`^drive://(.*)$`) + +// Register with Fs +func init() { + fs.Register(Match, NewFs) +} + // FsDrive represents a remote drive server type FsDrive struct { svc *drive.Service // the connection to the drive server @@ -133,12 +141,9 @@ func (f *FsDrive) String() string { return fmt.Sprintf("Google drive root '%s'", f.root) } -// Pattern to match a drive url -var driveMatch = regexp.MustCompile(`^drive://(.*)$`) - // parseParse parses a drive 'url' func parseDrivePath(path string) (root string, err error) { - parts := driveMatch.FindAllStringSubmatch(path, -1) + parts := Match.FindAllStringSubmatch(path, -1) if len(parts) != 1 || len(parts[0]) != 2 { err = fmt.Errorf("Couldn't parse drive url %q", path) } else { @@ -217,8 +222,8 @@ func MakeNewToken(t *oauth.Transport) error { return err } -// NewFsDrive contstructs an FsDrive from the path, container:path -func NewFsDrive(path string) (*FsDrive, error) { +// NewFs contstructs an FsDrive from the path, container:path +func NewFs(path string) (fs.Fs, error) { if *driveClientId == "" { return nil, errors.New("Need -drive-client-id or environmental variable GDRIVE_CLIENT_ID") }