> ## 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 Variable

A package variable in Go is a variable declared at the package level, outside of any function body. Its lexical scope encompasses all source files belonging to the same package, meaning it can be accessed and mutated by any function within that package.

## Declaration Syntax

Package variables must be declared using the `var` keyword. The short variable declaration operator (`:=`) is strictly prohibited at the package level and will result in a compilation error.

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

// Valid package variable declaration with explicit type
var maxConnections int = 100

// Valid package variable with type inference
var defaultTimeout = 30

// INVALID: Short declaration cannot be used at the package level
// retryLimit := 5 
```

## Visibility and Export Rules

Go uses identifier casing to determine the visibility of package variables across package boundaries.

* **Exported:** If the variable name begins with an uppercase letter, it is exported and can be accessed by external packages that import the declaring package.
* **Unexported:** If the variable name begins with a lowercase letter or an underscore, it is unexported and strictly confined to the package in which it is declared.

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

// Exported: Accessible via server.Port from other packages
var Port string = ":8080"

// Unexported: Accessible only within the 'server' package
var connectionCount int = 0
```

## Grouping

Multiple package variables can be grouped within a single `var` block. This is the idiomatic approach for declaring multiple package-level variables, as it reduces keyword repetition.

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

var (
    // Exported variables
    Host string = "localhost"
    User string = "admin"
    
    // Unexported variables
    poolSize int  = 20
    isActive bool = false
)
```

## Initialization and Zero Values

Package variables are initialized exactly once per package, during the package initialization phase. This occurs prior to the execution of any `init()` functions and before the `main()` function begins.

If a package variable is declared without an explicit initial value, the Go compiler automatically assigns it the zero value for its respective type (e.g., `0` for numeric types, `""` for strings, `false` for booleans, and `nil` for pointers, slices, maps, and channels).

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

// Implicitly initialized to 0
var requestCounter int

// Implicitly initialized to nil
var activeConnections []string
```

<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>
