-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsearch_term.go
54 lines (46 loc) · 1009 Bytes
/
search_term.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
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"reflect"
)
// SearchTerm is search term in GitHub object
// See: https://developer.github.com/v3/search/#parameters-2
type SearchTerm struct {
in string
language string
fork string
size string
path string
filename string
extension string
user string
repo string
}
// NewSearchTerm creates SearchTerm
func NewSearchTerm() *SearchTerm {
return &SearchTerm{}
}
func (s *SearchTerm) debugf() {
v := reflect.Indirect(reflect.ValueOf(s))
t := v.Type()
var name, value string
for i := 0; i < t.NumField(); i++ {
name = t.Field(i).Name
value = v.Field(i).String()
Debugf("%s: %s", name, value)
}
}
func (s *SearchTerm) query(keyword string) string {
q := keyword
v := reflect.Indirect(reflect.ValueOf(s))
t := v.Type()
var name, value string
for i := 0; i < t.NumField(); i++ {
name = t.Field(i).Name
value = v.Field(i).String()
if value != "" {
q = fmt.Sprintf("%s %s:%s", q, name, value)
}
}
return q
}