forked from krakowski/ilias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_util.go
40 lines (31 loc) · 811 Bytes
/
query_util.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 ilias
import (
"net/url"
"reflect"
"github.com/PuerkitoBio/goquery"
)
func addQueryParams(path string, params interface{}) (string, error) {
v := reflect.ValueOf(params)
if v.Kind() == reflect.Ptr && v.IsNil() {
return path, nil
}
url, err := url.Parse(path)
if err != nil {
return path, err
}
values := url.Query()
if err := encoder.Encode(params, values); err != nil {
return path, err
}
url.RawQuery = values.Encode()
return url.String(), nil
}
func containsSuccessAlert(doc *goquery.Document) bool {
return containsElement(doc, "div .alert-success")
}
func containsDangerAlert(doc *goquery.Document) bool {
return containsElement(doc, "div .alert-danger")
}
func containsElement(doc *goquery.Document, selector string) bool {
return doc.Find(selector).Length() > 0
}