-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
73 lines (57 loc) · 1.63 KB
/
util.go
File metadata and controls
73 lines (57 loc) · 1.63 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
package sofa
import (
"net/url"
"strings"
)
// FutonURL attempts to correctly convert any CouchDB path into a URL to be used to
// access the same documents through the Futon web GUI.
func (con *CouchDB1Connection) FutonURL(path string) url.URL {
patharr := strings.Split(strings.Trim(path, "/"), "/")
furl := con.URL("/")
furl.Path = urlConcat(furl.Path, "_utils/")
if len(patharr) == 0 || patharr[0] == "" {
return furl
}
isDatabaseURL := false
if len(patharr) == 1 {
isDatabaseURL = true
} else {
switch patharr[1] {
case "_design", "_all_docs":
isDatabaseURL = true
}
}
furl.RawQuery = strings.TrimLeft(path, "/")
if isDatabaseURL {
furl.Path = urlConcat(furl.Path, "database.html")
return furl
}
furl.Path = urlConcat(furl.Path, "document.html")
return furl
}
// FauxtonURL attempts to correctly convert any CouchDB path into a URL to be used to
// access the same documents through the Fauxton web GUI.
func (con *CouchDB2Connection) FauxtonURL(path string) url.URL {
patharr := strings.Split(strings.Trim(path, "/"), "/")
furl := con.URL("/")
furl.Path = urlConcat(furl.Path, "_utils/")
if len(patharr) == 0 {
return furl
} else if len(patharr) == 1 {
path = path + "/_all_docs"
}
furl.Fragment = urlConcat("database", path)
return furl
}
// FromBoolean converts a standard bool value into a sofa.BooleanParameter for
// use in documents to allow not including unset booleans.
func FromBoolean(b bool) BooleanParameter {
if b {
return True
}
return False
}
// ToBoolean converts a sofa.BooleanParameter value into a standard bool.
func ToBoolean(b BooleanParameter) bool {
return b == True
}