Skip to content

Commit

Permalink
feat: new Get req
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Nov 22, 2022
1 parent 29181b7 commit 74d776e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
18 changes: 0 additions & 18 deletions pkg/netx/http.go

This file was deleted.

39 changes: 39 additions & 0 deletions pkg/netx/httpx/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package httpx

import (
"io"
"io/ioutil"
"net/http"
)

func GET(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}

var _defaultUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

func SetDefaultUA(ua string) {
_defaultUA = ua
}

func GetDefaultUA() string {
return _defaultUA
}

func NewGetJsonRequest(url string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequest("GET", url, body)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", _defaultUA)
req.Header.Set("Accept", "application/json")
return req, nil
}

0 comments on commit 74d776e

Please sign in to comment.