From 8c85da5472a0cc4f1a387edf7ccf45d6a3b8ccb0 Mon Sep 17 00:00:00 2001 From: long Date: Sat, 24 Jan 2026 15:00:30 -0600 Subject: [PATCH] Revert "initial attempt to integrate surf http client" This reverts commit 538d52d064d52f2d09336f66dce4d507719cdc49. --- Makefile | 13 ++- examples/client-on-request-completed/main.go | 2 +- go.mod | 30 +------ go.sum | 63 +++------------ reddit/account.go | 2 +- reddit/account_test.go | 2 +- reddit/collection.go | 2 +- reddit/collection_test.go | 2 +- reddit/comment.go | 2 +- reddit/comment_test.go | 2 +- reddit/emoji.go | 13 ++- reddit/emoji_test.go | 2 +- reddit/errors.go | 2 +- reddit/flair.go | 2 +- reddit/flair_test.go | 2 +- reddit/gold.go | 2 +- reddit/gold_test.go | 2 +- reddit/listings_test.go | 2 +- reddit/live-thread.go | 2 +- reddit/live-thread_test.go | 2 +- reddit/message.go | 2 +- reddit/message_test.go | 2 +- reddit/moderation.go | 2 +- reddit/moderation_test.go | 2 +- reddit/multi.go | 2 +- reddit/multi_test.go | 2 +- reddit/post-and-comment.go | 2 +- reddit/post.go | 2 +- reddit/post_test.go | 2 +- reddit/reddit-oauth.go | 4 +- reddit/reddit-options.go | 13 +++ reddit/reddit-options_test.go | 9 +++ reddit/reddit-user-agent.go | 2 +- reddit/reddit.go | 85 +++++--------------- reddit/reddit_test.go | 4 +- reddit/stream.go | 1 - reddit/stream_test.go | 2 +- reddit/subreddit.go | 2 +- reddit/subreddit_test.go | 2 +- reddit/user.go | 2 +- reddit/user_test.go | 2 +- reddit/widget.go | 2 +- reddit/widget_test.go | 2 +- reddit/wiki.go | 2 +- reddit/wiki_test.go | 2 +- 45 files changed, 109 insertions(+), 196 deletions(-) diff --git a/Makefile b/Makefile index 72203ca..18361d4 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ define log endef .PHONY: all -all: fmt vet test test-coverage +all: lint fmt vet test test-coverage .PHONY: usage usage: - @echo "make [all|fmt|vet|test|test-coverage]" + @echo "make [all|fmt|vet|lint|test|test-coverage]" .PHONY: fmt fmt: @@ -28,13 +28,18 @@ 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 +test: fmt vet lint @$(call log,"Running tests") @go test -v -race -short -timeout $(TEST_TIMEOUT)s $(ARGS) $(LIST_PKG) .PHONY: test-coverage -test-coverage: fmt vet +test-coverage: fmt vet lint @$(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 diff --git a/examples/client-on-request-completed/main.go b/examples/client-on-request-completed/main.go index e91f016..5f6a231 100644 --- a/examples/client-on-request-completed/main.go +++ b/examples/client-on-request-completed/main.go @@ -3,8 +3,8 @@ package main import ( "context" "fmt" - "github.com/enetx/http" "log" + "net/http" "github.com/vartanbeno/go-reddit/v2/reddit" ) diff --git a/go.mod b/go.mod index 66672e5..abf47d4 100644 --- a/go.mod +++ b/go.mod @@ -1,34 +1,10 @@ module github.com/vartanbeno/go-reddit/v2 -go 1.24.0 +go 1.15 require ( - github.com/enetx/surf v1.0.173 github.com/google/go-querystring v1.0.0 - github.com/stretchr/testify v1.11.1 - golang.org/x/net v0.49.0 + github.com/stretchr/testify v1.5.1 + golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e 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 -) diff --git a/go.sum b/go.sum index df78e0c..e52bd76 100644 --- a/go.sum +++ b/go.sum @@ -1,69 +1,26 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -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/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/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/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= +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= 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/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= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/reddit/account.go b/reddit/account.go index f2b641d..a4ed04d 100644 --- a/reddit/account.go +++ b/reddit/account.go @@ -2,7 +2,7 @@ package reddit import ( "context" - "github.com/enetx/http" + "net/http" "net/url" ) diff --git a/reddit/account_test.go b/reddit/account_test.go index b522af4..a555210 100644 --- a/reddit/account_test.go +++ b/reddit/account_test.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/collection.go b/reddit/collection.go index 7244fbd..d05087e 100644 --- a/reddit/collection.go +++ b/reddit/collection.go @@ -3,7 +3,7 @@ package reddit import ( "context" "errors" - "github.com/enetx/http" + "net/http" "net/url" "strings" diff --git a/reddit/collection_test.go b/reddit/collection_test.go index ce8966f..f75acc6 100644 --- a/reddit/collection_test.go +++ b/reddit/collection_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/comment.go b/reddit/comment.go index d47215a..ca6389d 100644 --- a/reddit/comment.go +++ b/reddit/comment.go @@ -3,7 +3,7 @@ package reddit import ( "context" "errors" - "github.com/enetx/http" + "net/http" "net/url" "strings" ) diff --git a/reddit/comment_test.go b/reddit/comment_test.go index 286150f..e902550 100644 --- a/reddit/comment_test.go +++ b/reddit/comment_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/emoji.go b/reddit/emoji.go index f2f511f..7c72690 100644 --- a/reddit/emoji.go +++ b/reddit/emoji.go @@ -6,15 +6,16 @@ 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 @@ -241,18 +242,14 @@ func (s *EmojiService) Upload(ctx context.Context, subreddit string, createReque return nil, err } - req, err := http.NewRequest(http.MethodPost, uploadURL, body) - if err != nil { - return nil, err - } - resp, err = s.client.Do(ctx, req, nil) + httpResponse, err := ctxhttp.Post(ctx, nil, uploadURL, writer.FormDataContentType(), body) if err != nil { return nil, err } - err = CheckResponse(resp.Response) + err = CheckResponse(httpResponse) if err != nil { - return newResponse(resp.Response), err + return newResponse(httpResponse), err } return s.upload(ctx, subreddit, createRequest, fields["key"]) diff --git a/reddit/emoji_test.go b/reddit/emoji_test.go index 3dc815a..1edb9fe 100644 --- a/reddit/emoji_test.go +++ b/reddit/emoji_test.go @@ -3,9 +3,9 @@ package reddit import ( "bytes" "fmt" - "github.com/enetx/http" "io" "io/ioutil" + "net/http" "net/url" "os" "testing" diff --git a/reddit/errors.go b/reddit/errors.go index bcd67cc..3b20418 100644 --- a/reddit/errors.go +++ b/reddit/errors.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "strings" "time" ) diff --git a/reddit/flair.go b/reddit/flair.go index f484315..0ecc8e8 100644 --- a/reddit/flair.go +++ b/reddit/flair.go @@ -6,7 +6,7 @@ import ( "encoding/csv" "errors" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "github.com/google/go-querystring/query" diff --git a/reddit/flair_test.go b/reddit/flair_test.go index d83c780..dd92533 100644 --- a/reddit/flair_test.go +++ b/reddit/flair_test.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" diff --git a/reddit/gold.go b/reddit/gold.go index 868257f..6b63b44 100644 --- a/reddit/gold.go +++ b/reddit/gold.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "strconv" ) diff --git a/reddit/gold_test.go b/reddit/gold_test.go index e266153..11de810 100644 --- a/reddit/gold_test.go +++ b/reddit/gold_test.go @@ -1,7 +1,7 @@ package reddit import ( - "github.com/enetx/http" + "net/http" "net/url" "testing" diff --git a/reddit/listings_test.go b/reddit/listings_test.go index c724da2..3cac649 100644 --- a/reddit/listings_test.go +++ b/reddit/listings_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/live-thread.go b/reddit/live-thread.go index 0fbcfed..5dac208 100644 --- a/reddit/live-thread.go +++ b/reddit/live-thread.go @@ -5,8 +5,8 @@ import ( "encoding/json" "errors" "fmt" - "github.com/enetx/http" "io" + "net/http" "net/url" "reflect" "strings" diff --git a/reddit/live-thread_test.go b/reddit/live-thread_test.go index 9b50b32..dc52715 100644 --- a/reddit/live-thread_test.go +++ b/reddit/live-thread_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/message.go b/reddit/message.go index 0442fa3..c4fc86c 100644 --- a/reddit/message.go +++ b/reddit/message.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "errors" - "github.com/enetx/http" + "net/http" "net/url" "strings" diff --git a/reddit/message_test.go b/reddit/message_test.go index d457d5a..b624653 100644 --- a/reddit/message_test.go +++ b/reddit/message_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/moderation.go b/reddit/moderation.go index a93cabd..a1af7d2 100644 --- a/reddit/moderation.go +++ b/reddit/moderation.go @@ -3,7 +3,7 @@ package reddit import ( "context" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "reflect" diff --git a/reddit/moderation_test.go b/reddit/moderation_test.go index 1aebd98..0966be8 100644 --- a/reddit/moderation_test.go +++ b/reddit/moderation_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/multi.go b/reddit/multi.go index a30d0ab..6e7c3a8 100644 --- a/reddit/multi.go +++ b/reddit/multi.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "github.com/google/go-querystring/query" diff --git a/reddit/multi_test.go b/reddit/multi_test.go index b3973f1..72423b6 100644 --- a/reddit/multi_test.go +++ b/reddit/multi_test.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/post-and-comment.go b/reddit/post-and-comment.go index 7ae1dac..209604b 100644 --- a/reddit/post-and-comment.go +++ b/reddit/post-and-comment.go @@ -2,7 +2,7 @@ package reddit import ( "context" - "github.com/enetx/http" + "net/http" "net/url" "strconv" ) diff --git a/reddit/post.go b/reddit/post.go index c0754e5..ef55224 100644 --- a/reddit/post.go +++ b/reddit/post.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "strings" diff --git a/reddit/post_test.go b/reddit/post_test.go index fdf0adb..78d26b3 100644 --- a/reddit/post_test.go +++ b/reddit/post_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/reddit-oauth.go b/reddit/reddit-oauth.go index 0339abc..13030d6 100644 --- a/reddit/reddit-oauth.go +++ b/reddit/reddit-oauth.go @@ -33,10 +33,9 @@ to https://www.reddit.com/api/v1/access_token with the following form values: package reddit -/* import ( "context" - "github.com/enetx/http" + "net/http" "golang.org/x/oauth2" ) @@ -76,4 +75,3 @@ func oauthTransport(client *Client) http.RoundTripper { Base: client.client.Transport, } } -*/ diff --git a/reddit/reddit-options.go b/reddit/reddit-options.go index bf8d833..25d397b 100644 --- a/reddit/reddit-options.go +++ b/reddit/reddit-options.go @@ -1,6 +1,8 @@ package reddit import ( + "errors" + "net/http" "net/url" "os" ) @@ -8,6 +10,17 @@ 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: // :: (by /u/) diff --git a/reddit/reddit-options_test.go b/reddit/reddit-options_test.go index c5ec0b5..3db5ce8 100644 --- a/reddit/reddit-options_test.go +++ b/reddit/reddit-options_test.go @@ -2,6 +2,7 @@ package reddit import ( "fmt" + "net/http" "net/url" "os" "testing" @@ -9,6 +10,14 @@ 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) diff --git a/reddit/reddit-user-agent.go b/reddit/reddit-user-agent.go index f56fccd..0e69b67 100644 --- a/reddit/reddit-user-agent.go +++ b/reddit/reddit-user-agent.go @@ -1,6 +1,6 @@ package reddit -import "github.com/enetx/http" +import "net/http" // cloneRequest returns a clone of the provided *http.Request. // The clone is a shallow copy of the struct and its Header map, diff --git a/reddit/reddit.go b/reddit/reddit.go index be41853..bafda0c 100644 --- a/reddit/reddit.go +++ b/reddit/reddit.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "net/url" "reflect" "strconv" @@ -14,9 +15,6 @@ 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" ) @@ -62,7 +60,7 @@ type Credentials struct { // Client manages communication with the Reddit API. type Client struct { // HTTP client used to communicate with the Reddit API. - client *surf.Client + client *http.Client BaseURL *url.URL TokenURL *url.URL @@ -112,15 +110,7 @@ func newClient() *Client { baseURL, _ := url.Parse(defaultBaseURL) tokenURL, _ := url.Parse(defaultTokenURL) - surf_client := surf.NewClient(). - Builder(). - Impersonate(). - RandomOS(). - Firefox(). - Build(). - Unwrap() - - client := &Client{client: surf_client, BaseURL: baseURL, TokenURL: tokenURL} + client := &Client{client: &http.Client{}, BaseURL: baseURL, TokenURL: tokenURL} client.Account = &AccountService{client: client} client.Collection = &CollectionService{client: client} @@ -163,20 +153,18 @@ func NewClient(credentials Credentials, opts ...Opt) (*Client, error) { } } - /* - userAgentTransport := &userAgentTransport{ - userAgent: client.UserAgent(), - Base: client.client.Transport, - } - client.client.Transport = userAgentTransport + userAgentTransport := &userAgentTransport{ + userAgent: client.UserAgent(), + Base: client.client.Transport, + } + client.client.Transport = userAgentTransport - if client.client.CheckRedirect == nil { - client.client.CheckRedirect = client.redirect - } + if client.client.CheckRedirect == nil { + client.client.CheckRedirect = client.redirect + } - oauthTransport := oauthTransport(client) - client.client.Transport = oauthTransport - */ + oauthTransport := oauthTransport(client) + client.client.Transport = oauthTransport return client, nil } @@ -194,17 +182,15 @@ func NewReadonlyClient(opts ...Opt) (*Client, error) { } } - /* - if client.client == nil { - client.client = &http.Client{} - } + if client.client == nil { + client.client = &http.Client{} + } - userAgentTransport := &userAgentTransport{ - userAgent: client.UserAgent(), - Base: client.client.Transport, - } - client.client.Transport = userAgentTransport - */ + userAgentTransport := &userAgentTransport{ + userAgent: client.UserAgent(), + Base: client.client.Transport, + } + client.client.Transport = userAgentTransport return client, nil } @@ -348,33 +334,6 @@ 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. @@ -386,7 +345,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res }, err } - resp, err := c.request(ctx, req) + resp, err := DoRequestWithClient(ctx, c.client, req) if err != nil { return nil, err } diff --git a/reddit/reddit_test.go b/reddit/reddit_test.go index 65205ed..f119004 100644 --- a/reddit/reddit_test.go +++ b/reddit/reddit_test.go @@ -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" diff --git a/reddit/stream.go b/reddit/stream.go index 09c4d32..14f5b85 100644 --- a/reddit/stream.go +++ b/reddit/stream.go @@ -16,7 +16,6 @@ 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()) { diff --git a/reddit/stream_test.go b/reddit/stream_test.go index 50d731d..9ae48c6 100644 --- a/reddit/stream_test.go +++ b/reddit/stream_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "testing" "time" diff --git a/reddit/subreddit.go b/reddit/subreddit.go index 8ac212d..dc94838 100644 --- a/reddit/subreddit.go +++ b/reddit/subreddit.go @@ -6,9 +6,9 @@ import ( "encoding/json" "errors" "fmt" - "github.com/enetx/http" "io" "mime/multipart" + "net/http" "net/url" "os" "path/filepath" diff --git a/reddit/subreddit_test.go b/reddit/subreddit_test.go index 978567a..9bf9049 100644 --- a/reddit/subreddit_test.go +++ b/reddit/subreddit_test.go @@ -3,9 +3,9 @@ package reddit import ( "bytes" "fmt" - "github.com/enetx/http" "io" "io/ioutil" + "net/http" "net/url" "os" "strings" diff --git a/reddit/user.go b/reddit/user.go index 77d8d3c..f1839f5 100644 --- a/reddit/user.go +++ b/reddit/user.go @@ -3,7 +3,7 @@ package reddit import ( "context" "fmt" - "github.com/enetx/http" + "net/http" "net/url" ) diff --git a/reddit/user_test.go b/reddit/user_test.go index 0607d5d..81a2fd0 100644 --- a/reddit/user_test.go +++ b/reddit/user_test.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time" diff --git a/reddit/widget.go b/reddit/widget.go index dcc115a..34436d6 100644 --- a/reddit/widget.go +++ b/reddit/widget.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/enetx/http" + "net/http" ) // WidgetService handles communication with the widget diff --git a/reddit/widget_test.go b/reddit/widget_test.go index 7ee798e..40692b6 100644 --- a/reddit/widget_test.go +++ b/reddit/widget_test.go @@ -3,7 +3,7 @@ package reddit import ( "encoding/json" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" diff --git a/reddit/wiki.go b/reddit/wiki.go index 0390cac..ef7acda 100644 --- a/reddit/wiki.go +++ b/reddit/wiki.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/enetx/http" + "net/http" "net/url" "strings" diff --git a/reddit/wiki_test.go b/reddit/wiki_test.go index 6eb0b3d..cc9b961 100644 --- a/reddit/wiki_test.go +++ b/reddit/wiki_test.go @@ -2,7 +2,7 @@ package reddit import ( "fmt" - "github.com/enetx/http" + "net/http" "net/url" "testing" "time"