Skip to content

FlavioCFOliveira/user-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

user-agents

This module provides an easy-to-use interface for managing and utilizing correct user agents when making HTTP requests. It ensures that the user agents used are appropriate and up-to-date, enhancing the reliability and accuracy of the requests.

Installation

go get -u github.com/FlavioCFOliveira/user-agents

Usage

Obtaining a random user agent string

import (
    "github.com/FlavioCFOliveira/user-agents"
)

func main() {
    // Obtain a random User-Agent string
    randomUA := useragents.GetRandomUserAgent()

    // Print the random User-Agent string
    fmt.Println("Random User-Agent:", randomUA)
}

Setting The User-Agent Header of a http Request

import (
    "github.com/FlavioCFOliveira/user-agents"
)

func main() {
     // Create a new HTTP client
    client := &http.Client{}

    // Create a new HTTP request
    req, err := http.NewRequest("GET", "https://example.com", nil)
    if err != nil {
        fmt.Println("Error creating request:", err)
        return
    }

    // Set a random User-Agent header
    useragents.SetRandomUserAgent(req)

    // Perform the HTTP request
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error performing request:", err)
        return
    }
    defer resp.Body.Close()

    // do something with the response
}

License

This project is licensed under the BSD 3-Clause - see the LICENSE file for details.

About

Module dedicated to deal with user agents of http requests

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages