-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
56 lines (45 loc) · 1.6 KB
/
result.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
55
56
package services
import (
"net/http"
"github.com/zeoagency/carbon/models"
)
// keywords is an interface that includes ToStringSlice method.
// You can use models.URLset or models.KeywordSet for this interface.
// It used in SERP and DFS.
type keywords interface {
ToStringSlice() []string
}
// GetResultByUsingURLs add the result to the given URLSet by talking with Serp API or DFS.
func GetResultByUsingURLs(urls *models.URLSet, country, language string) (int, error) {
response, _, err := getResultFromSerpApi(urls, country, language, 10)
if err == nil {
parseSERPResponseToFieldsForURLs(response, urls)
if len(urls.URLs) == 0 {
return http.StatusOK, nil
}
}
// That means there is still unprocessed URLs exist.
dfsresponse, status, err := getResultFromDFSApi(urls, country, language, 10)
if err != nil {
return status, err
}
parseDFSResponseToFieldsForURLs(dfsresponse, urls)
return http.StatusOK, nil
}
// GetResultByUsingKeywords returns related 10 results for each Keywords by talking with SEPR API or DFS.
func GetResultByUsingKeywords(keywords *models.KeywordSet, country, language string) (int, error) {
response, _, err := getResultFromSerpApi(keywords, country, language, 10)
if err == nil {
parseSERPResponseToFieldsForKeywords(response, keywords)
if len(keywords.Keywords) == 0 {
return http.StatusOK, nil
}
}
// That means there is still unprocessed Keywords exist.
dfsresponse, status, err := getResultFromDFSApi(keywords, country, language, 10)
if err != nil {
return status, err
}
parseDFSResponseToFieldsForKeywords(dfsresponse, keywords)
return http.StatusOK, nil
}