From de933a1d48f8d6deb0065371499708ac7edbb81f Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 28 Dec 2015 15:57:20 +0100 Subject: [PATCH] Rename URI -> Config/Location --- backend/local/{uri.go => config.go} | 0 backend/s3/{uri.go => config.go} | 0 backend/s3/{uri_test.go => config_test.go} | 4 +-- backend/sftp/{uri.go => config.go} | 0 backend/sftp/{uri_test.go => config_test.go} | 4 +-- uri/uri.go => location/location.go | 18 +++++------ uri/uri_test.go => location/location_test.go | 34 ++++++++++---------- 7 files changed, 30 insertions(+), 30 deletions(-) rename backend/local/{uri.go => config.go} (100%) rename backend/s3/{uri.go => config.go} (100%) rename backend/s3/{uri_test.go => config_test.go} (88%) rename backend/sftp/{uri.go => config.go} (100%) rename backend/sftp/{uri_test.go => config_test.go} (93%) rename uri/uri.go => location/location.go (72%) rename uri/uri_test.go => location/location_test.go (56%) diff --git a/backend/local/uri.go b/backend/local/config.go similarity index 100% rename from backend/local/uri.go rename to backend/local/config.go diff --git a/backend/s3/uri.go b/backend/s3/config.go similarity index 100% rename from backend/s3/uri.go rename to backend/s3/config.go diff --git a/backend/s3/uri_test.go b/backend/s3/config_test.go similarity index 88% rename from backend/s3/uri_test.go rename to backend/s3/config_test.go index 27f1f63a3..8821f9883 100644 --- a/backend/s3/uri_test.go +++ b/backend/s3/config_test.go @@ -2,7 +2,7 @@ package s3 import "testing" -var uriTests = []struct { +var configTests = []struct { s string cfg Config }{ @@ -17,7 +17,7 @@ var uriTests = []struct { } func TestParseConfig(t *testing.T) { - for i, test := range uriTests { + for i, test := range configTests { cfg, err := ParseConfig(test.s) if err != nil { t.Errorf("test %d failed: %v", i, err) diff --git a/backend/sftp/uri.go b/backend/sftp/config.go similarity index 100% rename from backend/sftp/uri.go rename to backend/sftp/config.go diff --git a/backend/sftp/uri_test.go b/backend/sftp/config_test.go similarity index 93% rename from backend/sftp/uri_test.go rename to backend/sftp/config_test.go index 400660be6..7d5399de4 100644 --- a/backend/sftp/uri_test.go +++ b/backend/sftp/config_test.go @@ -2,7 +2,7 @@ package sftp import "testing" -var uriTests = []struct { +var configTests = []struct { s string cfg Config }{ @@ -36,7 +36,7 @@ var uriTests = []struct { } func TestParseConfig(t *testing.T) { - for i, test := range uriTests { + for i, test := range configTests { cfg, err := ParseConfig(test.s) if err != nil { t.Errorf("test %d failed: %v", i, err) diff --git a/uri/uri.go b/location/location.go similarity index 72% rename from uri/uri.go rename to location/location.go index 85d0c8a44..a4b344000 100644 --- a/uri/uri.go +++ b/location/location.go @@ -1,5 +1,5 @@ -// Package uri implements parsing the restic repository location from a string. -package uri +// Package location implements parsing the restic repository location from a string. +package location import ( "strings" @@ -9,9 +9,9 @@ import ( "github.com/restic/restic/backend/sftp" ) -// URI specifies the location of a repository, including the method of access -// and (possibly) credentials needed for access. -type URI struct { +// Location specifies the location of a repository, including the method of +// access and (possibly) credentials needed for access. +type Location struct { Scheme string Config interface{} } @@ -29,11 +29,11 @@ var parsers = []parser{ {"s3", s3.ParseConfig}, } -// ParseURI parses a repository location from the string s. If s starts with a +// ParseLocation parses a repository location from the string s. If s starts with a // backend name followed by a colon, that backend's Parse() function is called. // Otherwise, the local backend is used which interprets s as the name of a // directory. -func ParseURI(s string) (u URI, err error) { +func ParseLocation(s string) (u Location, err error) { scheme := extractScheme(s) u.Scheme = scheme @@ -44,7 +44,7 @@ func ParseURI(s string) (u URI, err error) { u.Config, err = parser.parse(s) if err != nil { - return URI{}, err + return Location{}, err } return u, nil @@ -54,7 +54,7 @@ func ParseURI(s string) (u URI, err error) { u.Scheme = "local" u.Config, err = local.ParseConfig("local:" + s) if err != nil { - return URI{}, err + return Location{}, err } return u, nil diff --git a/uri/uri_test.go b/location/location_test.go similarity index 56% rename from uri/uri_test.go rename to location/location_test.go index 8aff27b51..096f0fa16 100644 --- a/uri/uri_test.go +++ b/location/location_test.go @@ -1,4 +1,4 @@ -package uri +package location import ( "reflect" @@ -10,53 +10,53 @@ import ( var parseTests = []struct { s string - u URI + u Location }{ - {"local:/srv/repo", URI{Scheme: "local", Config: "/srv/repo"}}, - {"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}}, - {"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}}, - {"dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}}, - {"local:../dir1/dir2", URI{Scheme: "local", Config: "../dir1/dir2"}}, - {"/dir1/dir2", URI{Scheme: "local", Config: "/dir1/dir2"}}, + {"local:/srv/repo", Location{Scheme: "local", Config: "/srv/repo"}}, + {"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}}, + {"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}}, + {"dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}}, + {"local:../dir1/dir2", Location{Scheme: "local", Config: "../dir1/dir2"}}, + {"/dir1/dir2", Location{Scheme: "local", Config: "/dir1/dir2"}}, - {"sftp:user@host:/srv/repo", URI{Scheme: "sftp", + {"sftp:user@host:/srv/repo", Location{Scheme: "sftp", Config: sftp.Config{ User: "user", Host: "host", Dir: "/srv/repo", }}}, - {"sftp:host:/srv/repo", URI{Scheme: "sftp", + {"sftp:host:/srv/repo", Location{Scheme: "sftp", Config: sftp.Config{ User: "", Host: "host", Dir: "/srv/repo", }}}, - {"sftp://user@host/srv/repo", URI{Scheme: "sftp", + {"sftp://user@host/srv/repo", Location{Scheme: "sftp", Config: sftp.Config{ User: "user", Host: "host", Dir: "srv/repo", }}}, - {"sftp://user@host//srv/repo", URI{Scheme: "sftp", + {"sftp://user@host//srv/repo", Location{Scheme: "sftp", Config: sftp.Config{ User: "user", Host: "host", Dir: "/srv/repo", }}}, - {"s3://eu-central-1/bucketname", URI{Scheme: "s3", + {"s3://eu-central-1/bucketname", Location{Scheme: "s3", Config: s3.Config{ Host: "eu-central-1", Bucket: "bucketname", }}, }, - {"s3://hostname.foo/bucketname", URI{Scheme: "s3", + {"s3://hostname.foo/bucketname", Location{Scheme: "s3", Config: s3.Config{ Host: "hostname.foo", Bucket: "bucketname", }}, }, - {"s3:hostname.foo:repo", URI{Scheme: "s3", + {"s3:hostname.foo:repo", Location{Scheme: "s3", Config: s3.Config{ Host: "hostname.foo", Bucket: "repo", @@ -64,9 +64,9 @@ var parseTests = []struct { }, } -func TestParseURI(t *testing.T) { +func TestParseLocation(t *testing.T) { for i, test := range parseTests { - u, err := ParseURI(test.s) + u, err := ParseLocation(test.s) if err != nil { t.Errorf("unexpected error: %v", err) continue