-
Notifications
You must be signed in to change notification settings - Fork 35
/
parse.go
47 lines (37 loc) · 941 Bytes
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xrdio
import (
"net/url"
"strings"
"github.com/pkg/errors"
)
// Parse parses name into an xrootd URL structure.
func Parse(name string) (URL, error) {
urn, err := url.Parse(name)
if err != nil {
return URL{}, errors.WithStack(err)
}
host := urn.Hostname()
port := urn.Port()
path := urn.Path
if strings.HasPrefix(path, "//") {
path = path[1:]
}
user := ""
if urn.User != nil {
user = urn.User.Username()
}
addr := host
if port != "" {
addr += ":" + port
}
return URL{Addr: addr, User: user, Path: path}, nil
}
// URL stores an absolute reference to a XRootD path.
type URL struct {
Addr string // address (host [:port]) of the server
User string // user name to use to log in
Path string // path to the remote file or directory
}