initial attempt to integrate surf http client
This commit is contained in:
@@ -12,11 +12,11 @@ define log
|
||||
endef
|
||||
|
||||
.PHONY: all
|
||||
all: lint fmt vet test test-coverage
|
||||
all: fmt vet test test-coverage
|
||||
|
||||
.PHONY: usage
|
||||
usage:
|
||||
@echo "make [all|fmt|vet|lint|test|test-coverage]"
|
||||
@echo "make [all|fmt|vet|test|test-coverage]"
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
@@ -28,18 +28,13 @@ vet:
|
||||
@$(call log,"Running vet")
|
||||
@go vet -all $(LIST_PKG)
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@$(call log,"Running linter")
|
||||
@golint -set_exit_status $(LIST_PKG)
|
||||
|
||||
.PHONY: test
|
||||
test: fmt vet lint
|
||||
test: fmt vet
|
||||
@$(call log,"Running tests")
|
||||
@go test -v -race -short -timeout $(TEST_TIMEOUT)s $(ARGS) $(LIST_PKG)
|
||||
|
||||
.PHONY: test-coverage
|
||||
test-coverage: fmt vet lint
|
||||
test-coverage: fmt vet
|
||||
@$(call log,"Running tests with coverage")
|
||||
@go test -v -race -short -timeout $(TEST_TIMEOUT)s $(ARGS) -coverprofile=coverage.out $(LIST_PKG)
|
||||
@go tool cover -func=coverage.out
|
||||
|
||||
@@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/vartanbeno/go-reddit/v2/reddit"
|
||||
)
|
||||
|
||||
@@ -1,10 +1,34 @@
|
||||
module github.com/vartanbeno/go-reddit/v2
|
||||
|
||||
go 1.15
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/enetx/surf v1.0.173
|
||||
github.com/google/go-querystring v1.0.0
|
||||
github.com/stretchr/testify v1.5.1
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e
|
||||
github.com/stretchr/testify v1.11.1
|
||||
golang.org/x/net v0.49.0
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.2.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/enetx/g v1.0.202 // indirect
|
||||
github.com/enetx/http v1.0.24 // indirect
|
||||
github.com/enetx/http2 v1.0.24 // indirect
|
||||
github.com/enetx/http3 v1.0.6 // indirect
|
||||
github.com/enetx/iter v0.0.0-20250912135656-f1583323588f // indirect
|
||||
github.com/enetx/utls v0.0.0-20260115181616-c525a7d559c8 // indirect
|
||||
github.com/golang/protobuf v1.2.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/quic-go v0.59.0 // indirect
|
||||
github.com/wzshiming/socks5 v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.47.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
golang.org/x/text v0.33.0 // indirect
|
||||
google.golang.org/appengine v1.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,26 +1,69 @@
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
|
||||
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
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/enetx/g v1.0.202 h1:E32/PWp542wHh7c5VYPGohK0Nu6CpiRm34vr0P1F6dU=
|
||||
github.com/enetx/g v1.0.202/go.mod h1:6/HQeRy+tIJVGY+oRPQVJ/vOSruAi0aldFggurT6jBY=
|
||||
github.com/enetx/http v1.0.24 h1:sMeJ0rN00HlUYLIhUTHx36KumAlkaZu7vsQe5+GMTNM=
|
||||
github.com/enetx/http v1.0.24/go.mod h1:1f4mytfF/SfjATEJnynpwGS6aa1ALjb8DtmYgFVblY0=
|
||||
github.com/enetx/http2 v1.0.24 h1:MpNGZxD8wz2zg2bR4RSyB/4YJukZ91wIsQE2GLwQjCI=
|
||||
github.com/enetx/http2 v1.0.24/go.mod h1:t54ex5HIS8V1+2j6cvEOv6umlrHsbUPFKQ54nYB58Nk=
|
||||
github.com/enetx/http3 v1.0.6 h1:zOmCIOHqImGz0U3QTjvxyWIcPq7d4iTQ3sKZYejax8g=
|
||||
github.com/enetx/http3 v1.0.6/go.mod h1:sqpVGZ9F1/wCiW6sjBUS2errKAh3SUYn6VlWE7LL6KM=
|
||||
github.com/enetx/iter v0.0.0-20250912135656-f1583323588f h1:GUW+4AWfECIEJ9oAxgEAVGCpaozMCjRiUYnuR6Q0bCQ=
|
||||
github.com/enetx/iter v0.0.0-20250912135656-f1583323588f/go.mod h1:oMZN8hGLUpi7QBlMEUqailocNy0NFAO/7Lu+Nwh9HMM=
|
||||
github.com/enetx/surf v1.0.173 h1:36U3d5bGzncQJE8iqNAahIt6SlUYBYPJ90uigf7hqCw=
|
||||
github.com/enetx/surf v1.0.173/go.mod h1:7kQlsgHH2OT69AB/9w9/9Nppx3wijRFOAPnH4IhwMBM=
|
||||
github.com/enetx/utls v0.0.0-20260115181616-c525a7d559c8 h1:jN2LdG4CG7cXOMAkQVDencj67Gdt7FFwDP1UaPcYyV8=
|
||||
github.com/enetx/utls v0.0.0-20260115181616-c525a7d559c8/go.mod h1:jsHaW4RX6DteSbAHT/pW7iJxv7YXLf2NTr3k9PsmXoc=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
|
||||
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
|
||||
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/wzshiming/socks5 v0.7.0 h1:euJ+U48WrvVngi+opC8vAnpZ5sK12y1C2hPvb1f48Rg=
|
||||
github.com/wzshiming/socks5 v0.7.0/go.mod h1:BvCAqlzocQN5xwLjBZDBbvWlrx8sCYSSbHEOf2wZgT0=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
|
||||
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
|
||||
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
||||
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
+8
-5
@@ -6,16 +6,15 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
)
|
||||
|
||||
// EmojiService handles communication with the emoji
|
||||
@@ -242,14 +241,18 @@ func (s *EmojiService) Upload(ctx context.Context, subreddit string, createReque
|
||||
return nil, err
|
||||
}
|
||||
|
||||
httpResponse, err := ctxhttp.Post(ctx, nil, uploadURL, writer.FormDataContentType(), body)
|
||||
req, err := http.NewRequest(http.MethodPost, uploadURL, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err = s.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = CheckResponse(httpResponse)
|
||||
err = CheckResponse(resp.Response)
|
||||
if err != nil {
|
||||
return newResponse(httpResponse), err
|
||||
return newResponse(resp.Response), err
|
||||
}
|
||||
|
||||
return s.upload(ctx, subreddit, createRequest, fields["key"])
|
||||
|
||||
@@ -3,9 +3,9 @@ package reddit
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package reddit
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -33,9 +33,10 @@ to https://www.reddit.com/api/v1/access_token with the following form values:
|
||||
|
||||
package reddit
|
||||
|
||||
/*
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
@@ -75,3 +76,4 @@ func oauthTransport(client *Client) http.RoundTripper {
|
||||
Base: client.client.Transport,
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package reddit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
@@ -10,17 +8,6 @@ import (
|
||||
// Opt is used to further configure a client upon initialization.
|
||||
type Opt func(*Client) error
|
||||
|
||||
// WithHTTPClient sets the HTTP client which will be used to make requests.
|
||||
func WithHTTPClient(httpClient *http.Client) Opt {
|
||||
return func(c *Client) error {
|
||||
if httpClient == nil {
|
||||
return errors.New("*http.Client: cannot be nil")
|
||||
}
|
||||
c.client = httpClient
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithUserAgent sets the User-Agent header for requests made with the client.
|
||||
// Reddit recommends the following format for the user agent:
|
||||
// <platform>:<app ID>:<version string> (by /u/<reddit username>)
|
||||
|
||||
@@ -2,7 +2,6 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -10,14 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWithHTTPClient(t *testing.T) {
|
||||
_, err := NewClient(Credentials{}, WithHTTPClient(nil))
|
||||
require.EqualError(t, err, "*http.Client: cannot be nil")
|
||||
|
||||
_, err = NewClient(Credentials{}, WithHTTPClient(&http.Client{}))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestWithUserAgent(t *testing.T) {
|
||||
c, err := NewClient(Credentials{}, WithUserAgent("test"))
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package reddit
|
||||
|
||||
import "net/http"
|
||||
import "github.com/enetx/http"
|
||||
|
||||
// cloneRequest returns a clone of the provided *http.Request.
|
||||
// The clone is a shallow copy of the struct and its Header map,
|
||||
|
||||
+45
-4
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -15,6 +14,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/enetx/g"
|
||||
"github.com/enetx/http"
|
||||
"github.com/enetx/surf"
|
||||
"github.com/google/go-querystring/query"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
@@ -60,7 +62,7 @@ type Credentials struct {
|
||||
// Client manages communication with the Reddit API.
|
||||
type Client struct {
|
||||
// HTTP client used to communicate with the Reddit API.
|
||||
client *http.Client
|
||||
client *surf.Client
|
||||
|
||||
BaseURL *url.URL
|
||||
TokenURL *url.URL
|
||||
@@ -110,7 +112,15 @@ func newClient() *Client {
|
||||
baseURL, _ := url.Parse(defaultBaseURL)
|
||||
tokenURL, _ := url.Parse(defaultTokenURL)
|
||||
|
||||
client := &Client{client: &http.Client{}, BaseURL: baseURL, TokenURL: tokenURL}
|
||||
surf_client := surf.NewClient().
|
||||
Builder().
|
||||
Impersonate().
|
||||
RandomOS().
|
||||
Firefox().
|
||||
Build().
|
||||
Unwrap()
|
||||
|
||||
client := &Client{client: surf_client, BaseURL: baseURL, TokenURL: tokenURL}
|
||||
|
||||
client.Account = &AccountService{client: client}
|
||||
client.Collection = &CollectionService{client: client}
|
||||
@@ -153,6 +163,7 @@ func NewClient(credentials Credentials, opts ...Opt) (*Client, error) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
userAgentTransport := &userAgentTransport{
|
||||
userAgent: client.UserAgent(),
|
||||
Base: client.client.Transport,
|
||||
@@ -165,6 +176,7 @@ func NewClient(credentials Credentials, opts ...Opt) (*Client, error) {
|
||||
|
||||
oauthTransport := oauthTransport(client)
|
||||
client.client.Transport = oauthTransport
|
||||
*/
|
||||
|
||||
return client, nil
|
||||
}
|
||||
@@ -182,6 +194,7 @@ func NewReadonlyClient(opts ...Opt) (*Client, error) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if client.client == nil {
|
||||
client.client = &http.Client{}
|
||||
}
|
||||
@@ -191,6 +204,7 @@ func NewReadonlyClient(opts ...Opt) (*Client, error) {
|
||||
Base: client.client.Transport,
|
||||
}
|
||||
client.client.Transport = userAgentTransport
|
||||
*/
|
||||
|
||||
return client, nil
|
||||
}
|
||||
@@ -334,6 +348,33 @@ func parseRate(r *http.Response) Rate {
|
||||
return rate
|
||||
}
|
||||
|
||||
func (c *Client) request(ctx context.Context, req *http.Request) (*http.Response, error) {
|
||||
switch req.Method {
|
||||
case http.MethodGet:
|
||||
resp, err := c.client.
|
||||
Get(g.String(req.URL.String())).
|
||||
WithContext(ctx).
|
||||
Do().
|
||||
Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.GetResponse(), nil
|
||||
case http.MethodPost:
|
||||
resp, err := c.client.
|
||||
Post(g.String(req.URL.String()), nil).
|
||||
WithContext(ctx).
|
||||
Do().
|
||||
Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.GetResponse(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("fork does not support %s http method right now", req.Method)
|
||||
}
|
||||
}
|
||||
|
||||
// Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value
|
||||
// pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface,
|
||||
// the raw response will be written to v, without attempting to decode it.
|
||||
@@ -345,7 +386,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
|
||||
}, err
|
||||
}
|
||||
|
||||
resp, err := DoRequestWithClient(ctx, c.client, req)
|
||||
resp, err := c.request(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"github.com/enetx/http/httptest"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -16,6 +16,7 @@ type StreamService struct {
|
||||
// - a channel into which new posts will be sent
|
||||
// - a channel into which any errors will be sent
|
||||
// - a function that the client can call once to stop the streaming and close the channels
|
||||
//
|
||||
// Because of the 100 post limit imposed by Reddit when fetching posts, some high-traffic
|
||||
// streams might drop submissions between API requests, such as when streaming r/all.
|
||||
func (s *StreamService) Posts(subreddit string, opts ...StreamOpt) (<-chan *Post, <-chan error, func()) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
||||
+1
-1
@@ -6,9 +6,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -3,9 +3,9 @@ package reddit
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/enetx/http"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
)
|
||||
|
||||
// WidgetService handles communication with the widget
|
||||
|
||||
@@ -3,7 +3,7 @@ package reddit
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package reddit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/enetx/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
Reference in New Issue
Block a user