-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexturl.go
More file actions
49 lines (36 loc) · 768 Bytes
/
texturl.go
File metadata and controls
49 lines (36 loc) · 768 Bytes
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
48
49
package main
import (
"net/url"
)
// Wrapper de-/serializing URLs from/to text
type textURL struct {
url.URL
}
func (u textURL) String() string {
return u.URL.String()
}
func (u textURL) MarshalText() ([]byte, error) {
return []byte(u.String()), nil
}
func (u *textURL) UnmarshalText(text []byte) error {
parsed, err := url.Parse(string(text))
if err != nil {
return err
}
*u = textURL{*parsed}
return nil
}
func parseTextURL(text string) (textURL, error) {
result := textURL{}
if err := result.UnmarshalText([]byte(text)); err != nil {
return result, err
}
return result, nil
}
func mustParseTextURL(text string) textURL {
result := textURL{}
if err := result.UnmarshalText([]byte(text)); err != nil {
panic(err)
}
return result
}