drive: Finish refactor
This commit is contained in:
parent
025e5f3f0c
commit
b98923a20f
1 changed files with 11 additions and 6 deletions
17
drive/fs.go
17
drive/fs.go
|
@ -41,6 +41,14 @@ import (
|
||||||
"time"
|
"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
|
// FsDrive represents a remote drive server
|
||||||
type FsDrive struct {
|
type FsDrive struct {
|
||||||
svc *drive.Service // the connection to the drive server
|
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)
|
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'
|
// parseParse parses a drive 'url'
|
||||||
func parseDrivePath(path string) (root string, err error) {
|
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 {
|
if len(parts) != 1 || len(parts[0]) != 2 {
|
||||||
err = fmt.Errorf("Couldn't parse drive url %q", path)
|
err = fmt.Errorf("Couldn't parse drive url %q", path)
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,8 +222,8 @@ func MakeNewToken(t *oauth.Transport) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFsDrive contstructs an FsDrive from the path, container:path
|
// NewFs contstructs an FsDrive from the path, container:path
|
||||||
func NewFsDrive(path string) (*FsDrive, error) {
|
func NewFs(path string) (fs.Fs, error) {
|
||||||
if *driveClientId == "" {
|
if *driveClientId == "" {
|
||||||
return nil, errors.New("Need -drive-client-id or environmental variable GDRIVE_CLIENT_ID")
|
return nil, errors.New("Need -drive-client-id or environmental variable GDRIVE_CLIENT_ID")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue