initial commit
This commit is contained in:
commit
501d579a90
35 changed files with 11357 additions and 0 deletions
30
scheme.go
Normal file
30
scheme.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue