-
Notifications
You must be signed in to change notification settings - Fork 33
/
url.go
41 lines (34 loc) · 775 Bytes
/
url.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
41
package yandex
import (
"errors"
"fmt"
"net/url"
"github.com/karust/openserp/core"
)
func BuildURL(q core.Query, page int) (string, error) {
base, _ := url.Parse("https://www.yandex.com")
base.Path += "search/"
params := url.Values{}
if q.Text != "" || q.Site != "" || q.Filetype != "" {
text := q.Text
if q.Site != "" {
text += " site:" + q.Site
}
if q.Filetype != "" {
text += " mime:" + q.Filetype
}
if q.DateInterval != "" {
text += " date:" + q.DateInterval
}
if q.LangCode != "" {
text += " lang:" + q.LangCode
}
params.Add("text", text)
params.Add("p", fmt.Sprint(page))
}
if len(params.Get("text")) == 0 {
return "", errors.New("Empty query built")
}
base.RawQuery = params.Encode()
return base.String(), nil
}