forked from ttacon/uri
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
87 lines (71 loc) · 1.54 KB
/
example_test.go
File metadata and controls
87 lines (71 loc) · 1.54 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package uri_test
import (
"fmt"
"github.com/fredbi/uri"
)
func ExampleParse() {
u, err := uri.Parse("https://example.com:8080/path")
if err != nil {
fmt.Println("Invalid URI:", err)
} else {
fmt.Println(u.String())
}
// Output: https://example.com:8080/path
}
func ExampleURI_Scheme() {
u, err := uri.Parse("https://example.com:8080/path")
if err != nil {
fmt.Println("Invalid URI:", err)
} else {
fmt.Println(u.Scheme())
}
// Output: https
}
func ExampleURI_Authority() {
u, err := uri.Parse("ftp://example.com/path")
if err != nil {
fmt.Println("Invalid URI:", err)
} else {
fmt.Println(u.Authority().Path())
}
// Output:
// /path
}
func ExampleAuthority_Path() {
u, err := uri.ParseReference("//example.com/path")
if err != nil {
fmt.Println("Invalid URI reference:", err)
} else {
fmt.Println(u.Authority().Path())
}
// Output:
// /path
}
func ExampleParseReference() {
u, err := uri.ParseReference("//example.com/path?a=1#fragment")
if err != nil {
fmt.Println("Invalid URI reference:", err)
} else {
fmt.Println(u.Fragment())
params := u.Query()
fmt.Println(params.Get("a"))
}
// Output:
// fragment
// 1
}
func ExampleIsURI() {
isValid := uri.IsURI("urn://example.com?query=x#fragment/path") // true
fmt.Println(isValid)
isValid = uri.IsURI("//example.com?query=x#fragment/path") // false
fmt.Println(isValid)
// Output:
// true
// false
}
func ExampleIsURIReference() {
isValid := uri.IsURIReference("//example.com?query=x#fragment/path") // true
fmt.Println(isValid)
// Output:
// true
}