-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
40 lines (34 loc) · 792 Bytes
/
query.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
package webfinger
import "net/url"
// Query represents a query request to the server
type Query struct {
Resource string
Rel []string
}
// NewQuery returns a new query for resource res
func NewQuery(res string) *Query {
return &Query{
Resource: res,
}
}
// QueryFromValues returns a new query from URL values.
// Useful when implementing the server side of the protocol
func QueryFromValues(v url.Values) *Query {
return &Query{
Resource: v.Get("resource"),
Rel: v["rel"],
}
}
// AddRel adds rel to the query
func (q *Query) AddRel(rel string) {
q.Rel = append(q.Rel, rel)
}
// ToValues converts the query to URL values
func (q *Query) ToValues() url.Values {
v := url.Values{}
v.Add("resource", q.Resource)
if q.Rel != nil {
v["rel"] = q.Rel
}
return v
}