Introduce type Server

This commit is contained in:
Alexander Neumann committed 2014-12-21 17:37:29 +01:00
1 parent 661c1e9aa1
commit cc147c002e
15 files changed
+206 -106

No files matched your search

+13 -9
View File
@@ -70,13 +70,15 @@ func (cmd CmdInit) Execute(args []string) error {
os.Exit(1)
}
_, err = restic.CreateKey(be, pw)
s := restic.NewServer(be)
_, err = restic.CreateKey(s, pw)
if err != nil {
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err)
os.Exit(1)
}
fmt.Printf("created restic backend at %s\n", be.Location())
fmt.Printf("created restic backend at %s\n", opts.Repo)
return nil
}
@@ -86,7 +88,7 @@ func (cmd CmdInit) Execute(args []string) error {
// * /foo/bar -> local repository at /foo/bar
// * sftp://user@host/foo/bar -> remote sftp repository on host for user at path foo/bar
// * sftp://host//tmp/backup -> remote sftp repository on host at path /tmp/backup
func open(u string) (backend.Server, error) {
func open(u string) (backend.Backend, error) {
url, err := url.Parse(u)
if err != nil {
return nil, err
@@ -107,7 +109,7 @@ func open(u string) (backend.Server, error) {
}
// Create the backend specified by URI.
func create(u string) (backend.Server, error) {
func create(u string) (backend.Backend, error) {
url, err := url.Parse(u)
if err != nil {
return nil, err
@@ -127,18 +129,20 @@ func create(u string) (backend.Server, error) {
return backend.CreateSFTP(url.Path[1:], "ssh", args...)
}
func OpenRepo() (backend.Server, *restic.Key, error) {
func OpenRepo() (restic.Server, *restic.Key, error) {
be, err := open(opts.Repo)
if err != nil {
return nil, nil, err
return restic.Server{}, nil, err
}
key, err := restic.SearchKey(be, readPassword("RESTIC_PASSWORD", "Enter Password for Repository: "))
s := restic.NewServer(be)
key, err := restic.SearchKey(s, readPassword("RESTIC_PASSWORD", "Enter Password for Repository: "))
if err != nil {
return nil, nil, fmt.Errorf("unable to open repo: %v", err)
return restic.Server{}, nil, fmt.Errorf("unable to open repo: %v", err)
}
return be, key, nil
return s, key, nil
}
func init() {