forked from zoom-lib-golang/zoom-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurl.go
More file actions
43 lines (35 loc) · 818 Bytes
/
url.go
File metadata and controls
43 lines (35 loc) · 818 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
package zoom
import (
"fmt"
"net/url"
"strings"
)
// URL is a custom URL type that enables JSON marshaling/unmarshaling of url.URL
type URL struct {
*url.URL
}
// UnmarshalJSON describes JSON unmarshaling for custom Time objects, handling
// empty string values
func (u *URL) UnmarshalJSON(b []byte) (err error) {
var ur *url.URL
s := strings.Trim(string(b), "\"")
if s == "null" || s == "" {
u.URL = &url.URL{}
return
}
ur, err = url.Parse(s)
if err != nil {
return
}
u.URL = ur
return
}
// MarshalJSON describes JSON unmarshaling for custom Time objects, handling
// empty string values
func (u *URL) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", u.String())), nil
}
// String defines how time is printed out
func (u *URL) String() string {
return u.URL.String()
}