ddgo

package module
v0.0.0-...-2bf7785 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 5 Imported by: 0

README

ddgo

ddgo is a Go package that provides a simple interface to query DuckDuckGo's search engine and retrieve search results. It allows you to perform searches and obtain relevant information such as titles, snippets, and URLs of the results.

Installation

To use the ddgo package, you need to have Go installed on your machine. You can install the package using the following command:

go get github.com/evgensoft/ddgo

Usage

Here is a basic example of how to use the ddgo package to perform a search query:

package main

import (
	"fmt"
	"log"

	"github.com/evgensoft/ddgo"
)

func main() {
	query := "Go programming language"
	maxResults := 5

	results, err := ddgo.Query(query, maxResults)
	if err != nil {
		log.Fatalf("Error querying DuckDuckGo: %v", err)
	}

	for _, result := range results {
		fmt.Printf("Title: %s\nInfo: %s\nRef: %s\n\n", result.Title, result.Info, result.Ref)
	}
}
Function: Query

The Query function is the main function of the package. It takes a search query and the maximum number of results to return.

Parameters
  • query (string): The search query string.
  • maxResult (int): The maximum number of results to return.
Returns
  • ([]Result, error): A slice of Result structs containing the search results and an error if any occurred.
Result Struct

The Result struct holds the data for each search result:

  • Title (string): The title of the search result.
  • Info (string): A snippet of information about the search result.
  • Ref (string): The URL of the search result.

Error Handling

The Query function returns an error if there are issues with the HTTP request or if the response status code is not 200. Make sure to handle errors appropriately in your application.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! If you have suggestions for improvements or find bugs, please open an issue or submit a pull request.

Documentation

Index

Constants

View Source
const DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

DefaultUserAgent defines a default value for user-agent header.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Title string
	Info  string
	URL   string
}

Result holds the returned query data

func Query

func Query(query string, maxResult int) ([]Result, error)

Requests the query and puts the results into an array

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL