# Go

In Go, we'll be using the `net/http` standard library to send HTTP requests. Here's how you can use the book search API with Go:

First, make sure you import the necessary libraries at the top of your file:

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
)

```

\
Then, you can use the following code to make the API request:

```go
type Book struct {
	Title  string `json:"title"`
	Author string `json:"author"`
}

type Query struct {
	Query string `json:"query"`
}

func searchBook(query string) ([]Book, error) {
	url := "https://api.promptjoy.com/api/mVMCpq"
	var jsonData = []byte(`{"query":"` + query + `"}`)

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
	if err != nil {
		return nil, err
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("x-api-key", os.Getenv("PROMPTJOY_API_KEY"))

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)

	var books []Book
	err = json.Unmarshal(body, &books)
	if err != nil {
		return nil, err
	}

	return books, nil
}

func main() {
	books, err := searchBook("your_search_term")
	if err != nil {
		fmt.Printf("The HTTP request failed with error %s\n", err)
	} else {
		for _, book := range books {
			fmt.Println("Title: " + book.Title + ", Author: " + book.Author)
		}
	}
}

```

\
Replace `"your_search_term"` with the book you're searching for. This function will return a slice of books.

Remember to handle exceptions and errors as needed in your actual application code.

Note: In this example, the API key is retrieved from environment variables for security reasons. Ensure that you've set the `PROMPTJOY_API_KEY` environment variable in your environment where this code will be executed.

\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.promptjoy.com/api/api-usage/go.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
