mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
first working version
This commit is contained in:
parent
6ea370db8f
commit
71163e75d1
1 changed files with 49 additions and 0 deletions
49
variables.go
Normal file
49
variables.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
)
|
||||
|
||||
// Returns the repository name for a given path
|
||||
func RepositoryName(u string) (string, error) {
|
||||
s := strings.Split(u, "/")
|
||||
if len(s) <= 1 {
|
||||
return "", errors.New("path does not contain repository name")
|
||||
}
|
||||
return ParseRepositoryName(s[1])
|
||||
}
|
||||
|
||||
func ParseRepositoryName(n string) (string, error) {
|
||||
if len(n) < 1 {
|
||||
return "", errors.New("repository name should contain at least 1 character")
|
||||
}
|
||||
match, err := regexp.MatchString("^[a-zA-Z0-9_-]*$", n)
|
||||
if !match || err != nil {
|
||||
return "", errors.New("repository name should not contains special characters")
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Returns the backend type for a given path
|
||||
func BackendType(u string) backend.Type {
|
||||
s := strings.Split(u, "/")
|
||||
var bt backend.Type
|
||||
if len(s) > 2 {
|
||||
bt, _ = backend.ParseType(s[2])
|
||||
}
|
||||
return bt
|
||||
}
|
||||
|
||||
// Returns the blob ID for a given path
|
||||
func BlobID(u string) backend.ID {
|
||||
s := strings.Split(u, "/")
|
||||
var id backend.ID
|
||||
if len(s) > 3 {
|
||||
id, _ = backend.ParseID(s[3])
|
||||
}
|
||||
return id
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue