From c1a245d1c89f90100b312c9f5af108145b133c41 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 13 Jul 2014 18:58:06 +0100 Subject: [PATCH] Factor UserAgent to fs and move Version to fs --- Makefile | 3 +-- drive/drive.go | 2 +- fs/fs.go | 6 ++++++ {rclonetest => fs}/version.go | 2 +- notes.txt | 2 +- rclone.go | 4 ++-- rclonetest/rclonetest.go | 4 ++-- swift/swift.go | 7 ++++--- version.go | 3 --- 9 files changed, 18 insertions(+), 15 deletions(-) rename {rclonetest => fs}/version.go (65%) delete mode 100644 version.go diff --git a/Makefile b/Makefile index ec4170269..00102d743 100644 --- a/Makefile +++ b/Makefile @@ -45,8 +45,7 @@ serve: tag: @echo "Old tag is $(LAST_TAG)" @echo "New tag is $(NEW_TAG)" - echo -e "package main\n const Version = \"$(NEW_TAG)\"\n" | gofmt > version.go - cp -av version.go rclonetest/version.go + echo -e "package fs\n const Version = \"$(NEW_TAG)\"\n" | gofmt > fs/version.go perl -lpe 's/VERSION/${NEW_TAG}/g; s/DATE/'`date -I`'/g;' docs/content/downloads.md.in > docs/content/downloads.md git tag $(NEW_TAG) @echo "Add this to changelog in README.md" diff --git a/drive/drive.go b/drive/drive.go index bb719825d..3caed3b31 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -930,7 +930,7 @@ func (o *FsObjectDrive) Storable() bool { // Open an object for read func (o *FsObjectDrive) Open() (in io.ReadCloser, err error) { req, _ := http.NewRequest("GET", o.url, nil) - req.Header.Set("User-Agent", "rclone/1.0") + req.Header.Set("User-Agent", fs.UserAgent) res, err := o.drive.client.Do(req) if err != nil { return nil, err diff --git a/fs/fs.go b/fs/fs.go index 93434c689..7c5fd839e 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -10,6 +10,12 @@ import ( "time" ) +// Constants +const ( + // User agent for Fs which can set it + UserAgent = "rclone/" + Version +) + // Globals var ( // Filesystem registry diff --git a/rclonetest/version.go b/fs/version.go similarity index 65% rename from rclonetest/version.go rename to fs/version.go index f47ed138e..b9bfa432c 100644 --- a/rclonetest/version.go +++ b/fs/version.go @@ -1,3 +1,3 @@ -package main +package fs const Version = "v1.01" diff --git a/notes.txt b/notes.txt index a88831095..97aa8ff72 100644 --- a/notes.txt +++ b/notes.txt @@ -60,7 +60,7 @@ Making a release * cd .. * make tag * edit README.md - * git commit version.go rclonetest/version.go README.md docs/content/downloads.md + * git commit fs/version.go README.md docs/content/downloads.md * make retag * . ~/bin/go-cross * make cross diff --git a/rclone.go b/rclone.go index 4f0f3bcfc..6d89578fd 100644 --- a/rclone.go +++ b/rclone.go @@ -228,7 +228,7 @@ Syntax: [options] subcommand Subcommands: -`, Version) +`, fs.Version) for i := range Commands { cmd := &Commands[i] fmt.Fprintf(os.Stderr, " %s %s\n", cmd.Name, cmd.ArgsHelp) @@ -329,7 +329,7 @@ func StartStats() { func main() { ParseFlags() if *version { - fmt.Printf("rclone %s\n", Version) + fmt.Printf("rclone %s\n", fs.Version) os.Exit(0) } command, args := ParseCommand() diff --git a/rclonetest/rclonetest.go b/rclonetest/rclonetest.go index 7431dda6f..33feed492 100644 --- a/rclonetest/rclonetest.go +++ b/rclonetest/rclonetest.go @@ -299,7 +299,7 @@ directory under it and perform tests on it, deleting it at the end. Options: -`, Version) +`, fs.Version) pflag.PrintDefaults() } @@ -316,7 +316,7 @@ func main() { pflag.Usage = syntaxError pflag.Parse() if *version { - fmt.Printf("rclonetest %s\n", Version) + fmt.Printf("rclonetest %s\n", fs.Version) os.Exit(0) } fs.LoadConfig() diff --git a/swift/swift.go b/swift/swift.go index 1441af1f8..da0345acd 100644 --- a/swift/swift.go +++ b/swift/swift.go @@ -107,9 +107,10 @@ func swiftConnection(name string) (*swift.Connection, error) { return nil, errors.New("auth not found") } c := &swift.Connection{ - UserName: userName, - ApiKey: apiKey, - AuthUrl: authUrl, + UserName: userName, + ApiKey: apiKey, + AuthUrl: authUrl, + UserAgent: fs.UserAgent, } err := c.Authenticate() if err != nil { diff --git a/version.go b/version.go deleted file mode 100644 index f47ed138e..000000000 --- a/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -const Version = "v1.01"