make a http request with url parameters in go

To make an HTTP request with URL parameters in Go, you can use the net/http package's Get function with a URL that contains query parameters. Here is an example code snippet:

main.go
package main

import (
    "net/http"
    "fmt"
)

func main() {
    query := "example"
    response, err := http.Get("https://api.example.com/search?q=" + query)
    if err != nil {
        fmt.Printf("Error making GET request: %s\n", err.Error())
        return
    }
    defer response.Body.Close()
    // Do something with the response
}
342 chars
18 lines

In this example, we're making a GET request to "https://api.example.com/search?q=" + query, where query is the URL parameter we're passing. We're then checking for any errors that occur during the request (such as if the host is unreachable) and closing the response body once we're done with it. The response can be processed further depending on the application's use case.

gistlibby LogSnag