Pull request issues resolved
* Remove contect from tests * Resorted package dependacy for TestSearch * Removed extra notes from README
This commit is contained in:
		| @@ -88,15 +88,6 @@ Also note, that if you call this function too quickly, Google detects that it is | |||||||
| </svg> | </svg> | ||||||
| </details> | </details> | ||||||
|  |  | ||||||
| ## 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 | ## Credits | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,6 @@ | |||||||
| package googlesearch | package googlesearch | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
| @@ -12,14 +11,15 @@ func ExampleSearch() { | |||||||
| 		CountryCode: "au", | 		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 { | 	if err != nil { | ||||||
| 		fmt.Print(err.Error()) | 		fmt.Print(err.Error()) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, resault := range serp { | 	for _, result := range serp { | ||||||
| 		if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { | 		if strings.Contains(result.URL, "australiawidefirstaid.com.au") { | ||||||
| 			fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | 			fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | ||||||
| 			break | 			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", | 		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 { | 	if err != nil { | ||||||
| 		fmt.Print(err.Error()) | 		fmt.Print(err.Error()) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, resault := range serp { | 	for _, result := range serp { | ||||||
| 		if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { | 		if strings.Contains(result.URL, "australiawidefirstaid.com.au") { | ||||||
| 			fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | 			fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								go.mod
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| module github.com/rocketlaunchr/google-search | module github.com/rocketlaunchr/google-search | ||||||
|  |  | ||||||
| go 1.20 | go 1.16 | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/gocolly/colly/v2 v2.1.0 | 	github.com/gocolly/colly/v2 v2.1.0 | ||||||
| @@ -13,14 +13,10 @@ require ( | |||||||
| 	github.com/antchfx/htmlquery v1.3.0 // indirect | 	github.com/antchfx/htmlquery v1.3.0 // indirect | ||||||
| 	github.com/antchfx/xmlquery v1.3.15 // indirect | 	github.com/antchfx/xmlquery v1.3.15 // indirect | ||||||
| 	github.com/antchfx/xpath v1.2.4 // 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/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/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect | ||||||
| 	github.com/temoto/robotstxt v1.1.2 // indirect | 	github.com/temoto/robotstxt v1.1.2 // indirect | ||||||
| 	golang.org/x/net v0.10.0 // 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/appengine v1.6.7 // indirect | ||||||
| 	google.golang.org/protobuf v1.30.0 // indirect | 	google.golang.org/protobuf v1.30.0 // indirect | ||||||
| ) | ) | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								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/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 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= | ||||||
| github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= | 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 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 h1:k0DuZkDoCsx51bKpRJNEmcxcp+W5N8ziuwGaSDuFoGs= | ||||||
| github.com/gocolly/colly/v2 v2.1.0/go.mod h1:I2MuhsLjQ+Ex+IzK3afNS8/1qP3AedHOusRPcRdC5o0= | 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.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
| golang.org/x/sys v0.5.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.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-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.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.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.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.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.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.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||||
|   | |||||||
| @@ -1,23 +1,23 @@ | |||||||
| // Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved. | // Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved. | ||||||
|  |  | ||||||
| package googlesearch | package googlesearch_test | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" |  | ||||||
| 	"testing" | 	"testing" | ||||||
| ) |  | ||||||
|  |  | ||||||
| var ctx = context.Background() | 	googlesearch "github.com/rocketlaunchr/google-search" | ||||||
|  | ) | ||||||
|  |  | ||||||
| func TestSearch(t *testing.T) { | func TestSearch(t *testing.T) { | ||||||
|  |  | ||||||
| 	q := "Hello World" | 	q := "Hello World" | ||||||
|  |  | ||||||
| 	opts := SearchOptions{ | 	opts := googlesearch.SearchOptions{ | ||||||
| 		Limit: 20, | 		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 { | 	if err != nil { | ||||||
| 		t.Errorf("something went wrong: %v", err) | 		t.Errorf("something went wrong: %v", err) | ||||||
| 		return | 		return | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user