# Embed Directive

This Go program uses the `embed` package to embed files and directories into the compiled binary. Let's go through the code with inline comments:

```go
// Importing the embed package.
import (
	"embed"
)

//go:embed folder/single_file.txt
var fileString string // Embedding the content of a single text file as a string.

//go:embed folder/single_file.txt
var fileByte []byte // Embedding the content of a single text file as a byte slice.

//go:embed folder/single_file.txt
//go:embed folder/*.hash
var folder embed.FS // Embedding a directory and its contents.

func main() {
	// Printing the content of the embedded string.
	print(fileString)
	// Printing the content of the embedded byte slice.
	print(string(fileByte))

	// Reading and printing the content of a specific file ("folder/file1.hash") from the embedded directory.
	content1, _ := folder.ReadFile("folder/file1.hash")
	print(string(content1))

	// Reading and printing the content of another file ("folder/file2.hash") from the embedded directory.
	content2, _ := folder.ReadFile("folder/file2.hash")
	print(string(content2))
}

// print function for convenience.
func print(s string) {
	println(s)
}
```

Explanation:

1. **Embedding a Single File as a String and Byte Slice:**
   * `fileString` is a string variable that embeds the content of the file at "folder/single\_file.txt" as a string.
   * `fileByte` is a byte slice variable that embeds the same content as a byte slice.
2. **Embedding a Directory and Its Contents:**
   * `folder` is an `embed.FS` variable that embeds the entire "folder" directory and its contents.
3. **Reading and Printing Embedded Content:**
   * The `main` function prints the content of the embedded string, byte slice, and reads and prints the content of specific files within the embedded directory.
4. **Print Function:**
   * A simple `print` function is defined for convenience to print the embedded content.

This program demonstrates how to embed files and directories into a Go program using the `embed` package.


---

# 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://ineelhere.gitbook.io/code-with-go/67-embed-directive.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.
