pve-go/scheme.go
2020-06-01 12:18:20 +02:00

30 lines
519 B
Go

// Copyright (C) 2020 Marius Schellenberger
package pve
import (
"errors"
"fmt"
"net/url"
"strings"
)
const PVEScheme = "pve"
var ErrInvalidPVEURL = errors.New("invalid pve url scheme")
func ParseURL(s string) (node, id string, err error) {
u, err := url.Parse(s)
if err != nil {
return
}
if u.Scheme != PVEScheme {
err = ErrInvalidPVEURL
return
}
return u.Host, strings.TrimPrefix(u.Path, "/"), nil
}
func NewURL(node, id string) string {
return fmt.Sprintf("%s://%s/%s", PVEScheme, node, id)
}