extended URL scheme
This commit is contained in:
parent
249d7c6844
commit
0994baf5b0
4 changed files with 39 additions and 18 deletions
22
scheme.go
22
scheme.go
|
|
@ -11,9 +11,12 @@ import (
|
|||
|
||||
const PVEScheme = "pve"
|
||||
|
||||
var ErrInvalidPVEURL = errors.New("invalid pve url scheme")
|
||||
var (
|
||||
ErrInvalidPVEURL = errors.New("invalid pve url scheme")
|
||||
ErrNoID = errors.New("missing id in url")
|
||||
)
|
||||
|
||||
func ParseURL(s string) (pool, id string, err error) {
|
||||
func ParseURL(s string) (pool, node, id string, err error) {
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -22,9 +25,18 @@ func ParseURL(s string) (pool, id string, err error) {
|
|||
err = ErrInvalidPVEURL
|
||||
return
|
||||
}
|
||||
return u.Host, strings.TrimPrefix(u.Path, "/"), nil
|
||||
a := strings.Split(u.Path, "/")
|
||||
if len(a) != 3 {
|
||||
err = ErrInvalidPVEURL
|
||||
return
|
||||
}
|
||||
if a[2] == "" {
|
||||
err = ErrNoID
|
||||
return
|
||||
}
|
||||
return u.Host, a[1], a[2], nil
|
||||
}
|
||||
|
||||
func NewURL(pool, id string) string {
|
||||
return fmt.Sprintf("%s://%s/%s", PVEScheme, pool, id)
|
||||
func NewURL(pool, node, id string) string {
|
||||
return fmt.Sprintf("%s://%s/%s/%s", PVEScheme, pool, node, id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue