Skip to content

Latest commit

 

History

History
123 lines (105 loc) · 3.81 KB

README.md

File metadata and controls

123 lines (105 loc) · 3.81 KB

GitHub Go version Build Status Go Report Card GoDoc GitHub tag (latest SemVer) GitHub last commit GitHub issues

The Go Tool :: Web Search 🔎

This is a simple tool to use any web search engines like Google, Yandex, Bing, Qwant, DuckDuckGo and so on.

Supports now:

  • Unofficial Qwant
  • Unofficial DuckDuckGo
  • Unofficial Google
  • More: Official Google, Yandex, Bing, Yahoo, Baidu, Shenma, Haoso, Sogou etc

⏩ Fast Start

Get It

go get github.com/the-go-tool/websearch

Then add imports:

import (
    "github.com/the-go-tool/websearch"
    "github.com/the-go-tool/websearch/provider"    
)

Configure It

web := websearch.New(provider.NewUnofficialDuckDuckGo())

Use It

res, err := web.Search("test", 25)
if err != nil {
    // ...
}

fmt.Println(res)
// [{
//		Title: string,
//		Description: string,
//		Link: url.URL,
//		Provider: string,
// },...]

▶️ More Detailed Start

Modules Importing

You will need to import several modules.

  • websearch The main package with websearch wrapper.
  • provider Contains several web search providers for Qwant, DuckDuckGo, Google etc.
  • errs Contains provider's errors
import (
    "github.com/the-go-tool/websearch"
    "github.com/the-go-tool/websearch/provider"
    "github.com/the-go-tool/websearch/provider/errs"
)

Provider Configuration

Some providers require configuration. It can be optional or not. If you have a token or any other credentials for official APIs, you can pass them by provider config.

web := websearch.New(provider.NewUnofficialQwant(provider.UnofficialQwantConfig{
    Locale: "ru_RU",
}))

Error Handling

The library has several own errors.
Every error in websearch wrapped into websearch.Error, so you can handle only errors from this library like:

res, err := web.Search("test", 25)
if err != nil {
    if errors.As(err, &websearch.Error{}) {
        // ...
    }
    // ...
}

Next, providers have common specific errors.
You can get IP ban when use unofficial API and you can check this case so:

res, err := web.Search("test", 25)
if err != nil {
    if errors.As(err, &errs.IPBannedError{}) {
        fmt.Println("your are banned by IP")
    }
    panic(err)
}

❓ Q/A

Q: Should I use unofficial providers?
A: Maybe. It depends on stability you expect. Official APIs require they token and may take taxes. Unofficial APIs are free, but they are unstable and your IP may be banned for several minutes. So, if you have your personal/home project or you don't want pay then choose unofficial.

⭐ Please, star it if you find it helpful

Similar projects

If this project doesn't fit.