Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora233 committed Feb 27, 2021
1 parent 0c61d14 commit 5f9cf06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
39 changes: 28 additions & 11 deletions api.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package loliconApiPool

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Sora233/requests"
"io/ioutil"
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
Expand All @@ -13,6 +15,10 @@ import (

const Host = "https://api.lolicon.app/setu"

var c = &http.Client{
Timeout: time.Second * 60,
}

type R18Type int

const (
Expand Down Expand Up @@ -60,11 +66,11 @@ func (s *Setu) Content() ([]byte, error) {
if s == nil {
return nil, errors.New("<nil>")
}
resp, err := requests.Get(s.Url)
resp, err := c.Get(s.Url)
if err != nil {
return nil, err
}
return resp.Content(), nil
return ioutil.ReadAll(resp.Body)
}

type Response struct {
Expand All @@ -88,23 +94,34 @@ func LoliconAppSetu(apikey string, R18 R18Type, keyword string, num int) (*Respo
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
req := requests.RequestsWithContext(ctx)
resp, err := req.Get(Host, params)
req, err := http.NewRequest(http.MethodGet, Host, nil)
if err != nil {
return nil, err
}
q := make(url.Values)
for k, v := range params {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()

resp, err := c.Do(req)
if err != nil {
return nil, err
}
apiResp := new(Response)
err = resp.Json(apiResp)
bodyb, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(bodyb, &apiResp)
if err != nil {
return nil, err
}
return apiResp, nil
}

func ToParams(get interface{}) (requests.Params, error) {
params := make(requests.Params)
func ToParams(get interface{}) (map[string]string, error) {
params := make(map[string]string)

rg := reflect.ValueOf(get)
if rg.Type().Kind() == reflect.Ptr {
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/Sora233/LoliconApi-Pool

go 1.13

require (
github.com/Sora233/requests v0.0.0-20210124044507-771a1ecd2e93
github.com/sirupsen/logrus v1.8.0
)
require github.com/sirupsen/logrus v1.8.0
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/Sora233/requests v0.0.0-20210124044507-771a1ecd2e93 h1:N9X9bOcsMt/WLqSs2y2wY3/glwHDxr2PRy5+iNBLAXk=
github.com/Sora233/requests v0.0.0-20210124044507-771a1ecd2e93/go.mod h1:k/QNjrV73zXkn1r3iG0rwZLc1naFS55Q67I/Wyo/UkI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
Expand Down

0 comments on commit 5f9cf06

Please sign in to comment.