> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Package

A Go package is a fundamental unit of code organization, compilation, and encapsulation, consisting of one or more `.go` source files residing in the same directory. All files within a package share the same namespace and are compiled together as a single entity, allowing internal declarations to be mutually accessible regardless of the specific file in which they are defined.

## Package Declaration

Every Go source file must declare its package membership as the first non-comment line of code.

```go theme={"dark"}
package mathutils
```

By convention, the package name is a short, lowercase word that matches the base name of the directory containing the files. All `.go` files within a single directory must declare the exact same package name, with the strict exception of test files (`_test.go`), which may optionally use a `_test` suffix (e.g., `mathutils_test`).

## Visibility and Export Rules

Go does not use access modifier keywords (like `public` or `private`). Instead, it relies on lexical casing to determine the visibility of identifiers (variables, constants, functions, types, and struct fields) across package boundaries.

* **Exported (Public):** Identifiers beginning with an uppercase letter are accessible to external packages that import them.
* **Unexported (Private):** Identifiers beginning with a lowercase letter are strictly scoped to the declaring package.

```go theme={"dark"}
package config

// Exported: Accessible outside the 'config' package
var MaxConnections int = 100
func Load() {}
type Server struct {
    Host string // Exported field
    port int    // Unexported field
}

// Unexported: Accessible only within the 'config' package
var defaultTimeout int = 30
func parse() {}
```

## The `main` Package

The `main` package is a special designation that instructs the Go compiler to build an executable binary rather than a shared library archive. A `main` package must contain a `main()` function, which the Go runtime invokes as the entry point of the application.

```go theme={"dark"}
package main

import "os"

func main() {
    os.Exit(0)
}
```

## Importing Packages

To consume exported identifiers from another package, a file must declare an `import` block. The string provided is the **import path**, which is a globally unique identifier derived from the project's `go.mod` file and the directory structure.

```go theme={"dark"}
import (
    "fmt"                               // Standard library package
    "github.com/organization/repo/auth" // Third-party or internal module package
)
```

**Import Modifiers:**
Go provides specific syntax to modify how a package is imported into the current file's namespace:

```go theme={"dark"}
import (
    // Alias: Binds the package to 'log' instead of 'logrus'
    log "github.com/sirupsen/logrus" 
    
    // Dot import: Pulls all exported identifiers directly into the local namespace
    . "math" 
    
    // Blank import: Compiles the package to trigger its init() functions, 
    // but ignores its identifiers to bypass the "unused import" compiler error
    _ "github.com/lib/pq" 
)
```

## Package Initialization

A package can define one or more `init()` functions to perform setup tasks before the program executes. The Go runtime guarantees that `init()` functions are called sequentially after all package-level variable declarations are evaluated, and strictly before the `main()` function begins.

```go theme={"dark"}
package database

var connectionString string

func init() {
    connectionString = "postgres://localhost:5432"
}
```

If a package imports other packages, the imported packages are initialized first. A single package can contain multiple `init()` functions across its files, which are executed in lexical file name order.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
