From dfdb3593e1e2388020736c362ba2bd21d4b6222e Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Sat, 27 May 2023 17:31:50 +1000 Subject: [PATCH] Pull request issues resolved * Remove contect from tests * Resorted package dependacy for TestSearch * Removed extra notes from README --- README.md | 9 --------- example_test.go | 15 ++++++++------- go.mod | 6 +----- go.sum | 3 +++ search_test.go | 12 ++++++------ 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index a10426e..697ddc9 100644 --- a/README.md +++ b/README.md @@ -88,15 +88,6 @@ Also note, that if you call this function too quickly, Google detects that it is -## Using a Fork - -If you are wanting to use an active Fork you can replace it in your gomod.go by doing the following - -```bash -go get github.com/chrisjoyce911/google-search -go mod edit -replace github.com/rocketlaunchr/google-search=github.com/chrisjoyce911/google-search@master -go mod tidy -``` ## Credits diff --git a/example_test.go b/example_test.go index 5ec24c9..8dad19f 100644 --- a/example_test.go +++ b/example_test.go @@ -1,7 +1,6 @@ package googlesearch import ( - "context" "fmt" "strings" ) @@ -12,14 +11,15 @@ func ExampleSearch() { CountryCode: "au", } - serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + //lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). + serp, err := Search(nil, "First Aid Course Australia Wide First Aid", opt) if err != nil { fmt.Print(err.Error()) } - for _, resault := range serp { - if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { + for _, result := range serp { + if strings.Contains(result.URL, "australiawidefirstaid.com.au") { fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") break } @@ -42,14 +42,15 @@ func ExampleUserAgent() { UserAgent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36", } - serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + //lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). + serp, err := Search(nil, "First Aid Course Australia Wide First Aid", opt) if err != nil { fmt.Print(err.Error()) } - for _, resault := range serp { - if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { + for _, result := range serp { + if strings.Contains(result.URL, "australiawidefirstaid.com.au") { fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") break } diff --git a/go.mod b/go.mod index 55cfa15..b6afd61 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rocketlaunchr/google-search -go 1.20 +go 1.16 require ( github.com/gocolly/colly/v2 v2.1.0 @@ -13,14 +13,10 @@ require ( github.com/antchfx/htmlquery v1.3.0 // indirect github.com/antchfx/xmlquery v1.3.15 // indirect github.com/antchfx/xpath v1.2.4 // indirect - github.com/gobwas/glob v0.2.3 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/kennygrant/sanitize v1.2.4 // indirect github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect github.com/temoto/robotstxt v1.1.2 // indirect golang.org/x/net v0.10.0 // indirect - golang.org/x/text v0.9.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect ) diff --git a/go.sum b/go.sum index 2655b8a..0c6ae2e 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI= github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA= github.com/gocolly/colly/v2 v2.1.0 h1:k0DuZkDoCsx51bKpRJNEmcxcp+W5N8ziuwGaSDuFoGs= github.com/gocolly/colly/v2 v2.1.0/go.mod h1:I2MuhsLjQ+Ex+IzK3afNS8/1qP3AedHOusRPcRdC5o0= @@ -119,11 +120,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/search_test.go b/search_test.go index 99b9f1a..f56a030 100644 --- a/search_test.go +++ b/search_test.go @@ -1,23 +1,23 @@ // Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved. -package googlesearch +package googlesearch_test import ( - "context" "testing" -) -var ctx = context.Background() + googlesearch "github.com/rocketlaunchr/google-search" +) func TestSearch(t *testing.T) { q := "Hello World" - opts := SearchOptions{ + opts := googlesearch.SearchOptions{ Limit: 20, } - returnLinks, err := Search(ctx, q, opts) + //lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). + returnLinks, err := googlesearch.Search(nil, q, opts) if err != nil { t.Errorf("something went wrong: %v", err) return