mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-15 01:55:35 +00:00
feat: initial backend implementation of multihost synchronization (#562)
This commit is contained in:
60
internal/api/syncapi/uriutil.go
Normal file
60
internal/api/syncapi/uriutil.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package syncapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var ErrNotBackrestURI = errors.New("not a backrest URI")
|
||||
|
||||
func CreateRemoteRepoURI(instanceUrl string) (string, error) {
|
||||
u, err := url.Parse(instanceUrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if u.Scheme == "http" {
|
||||
u.Scheme = "backrest"
|
||||
} else if u.Scheme == "https" {
|
||||
u.Scheme = "sbackrest"
|
||||
} else {
|
||||
return "", errors.New("unsupported scheme")
|
||||
}
|
||||
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func IsBackrestRemoteRepoURI(repoUri string) bool {
|
||||
u, err := url.Parse(repoUri)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return u.Scheme == "backrest"
|
||||
}
|
||||
|
||||
func InstanceForBackrestURI(repoUri string) (string, error) {
|
||||
u, err := url.Parse(repoUri)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if u.Scheme != "backrest" {
|
||||
return "", errors.New("not a backrest URI")
|
||||
}
|
||||
|
||||
return u.Hostname(), nil
|
||||
}
|
||||
|
||||
func RepoForBackrestURI(repoUri string) (string, error) {
|
||||
u, err := url.Parse(repoUri)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if u.Scheme != "backrest" {
|
||||
return "", errors.New("not a backrest URI")
|
||||
}
|
||||
|
||||
return u.Path, nil
|
||||
}
|
||||
Reference in New Issue
Block a user