mirror of
https://github.com/minoplhy/duckduckgo-images-api.git
synced 2024-11-24 04:26:58 +00:00
log_err module (#1)
This commit is contained in:
parent
91097f137d
commit
a2268a0b07
38
goduckgo.go
38
goduckgo.go
@ -64,24 +64,19 @@ func Search(keyword Query) Gogo {
|
|||||||
|
|
||||||
requrl := url + "?q=" + keyword.Keyword
|
requrl := url + "?q=" + keyword.Keyword
|
||||||
req, err := http.NewRequest(http.MethodGet, requrl, nil)
|
req, err := http.NewRequest(http.MethodGet, requrl, nil)
|
||||||
if err != nil {
|
log_err(err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0")
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0")
|
||||||
|
|
||||||
res, err := netreq.Do(req)
|
res, err := netreq.Do(req)
|
||||||
if err != nil {
|
log_err(err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.Body != nil {
|
if res.Body != nil {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
body, readErr := ioutil.ReadAll(res.Body)
|
body, readErr := ioutil.ReadAll(res.Body)
|
||||||
if readErr != nil {
|
log_err(readErr)
|
||||||
log.Fatal(readErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
||||||
|
|
||||||
@ -105,23 +100,18 @@ func Search(keyword Query) Gogo {
|
|||||||
resq.Header.Add("sec-fetch-mode", "cors")
|
resq.Header.Add("sec-fetch-mode", "cors")
|
||||||
resq.Header.Add("referer", "https://duckduckgo.com/")
|
resq.Header.Add("referer", "https://duckduckgo.com/")
|
||||||
resq.Header.Add("accept-language", "en-US,enq=0.9")
|
resq.Header.Add("accept-language", "en-US,enq=0.9")
|
||||||
if err != nil {
|
log_err(err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
resqs, getErr := netreq.Do(resq)
|
resqs, getErr := netreq.Do(resq)
|
||||||
if getErr != nil {
|
log_err(getErr)
|
||||||
log.Fatal(getErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
||||||
if readErr != nil {
|
log_err(readErr)
|
||||||
log.Fatal(readErr)
|
|
||||||
}
|
|
||||||
duckduck := Gogo{}
|
duckduck := Gogo{}
|
||||||
jsonErr := json.Unmarshal(brudy, &duckduck)
|
jsonErr := json.Unmarshal(brudy, &duckduck)
|
||||||
if jsonErr != nil {
|
log_err(jsonErr)
|
||||||
log.Fatal(jsonErr)
|
|
||||||
}
|
|
||||||
log.Println("\nHitting Url Success : " + requrl)
|
log.Println("\nHitting Url Success : " + requrl)
|
||||||
return duckduck
|
return duckduck
|
||||||
}
|
}
|
||||||
@ -131,3 +121,9 @@ func regexfind(hitin regex_r) string {
|
|||||||
hunsen := gexgex.FindString(string(hitin.Body))
|
hunsen := gexgex.FindString(string(hitin.Body))
|
||||||
return hunsen
|
return hunsen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func log_err(err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user