Types & Variables
Gopher says
Before a connector can talk to an API, it needs configuration - names, page sizes, flags. In Go, every value has a fixed type that the compiler checks before your code runs. Let’s start there.
In baton-junction, typed constants like ConnectorName and variables like
default page sizes and API base URLs are the first things defined - they
configure how the connector talks to the target system.
Basic Types
Go keeps its type system simple and practical, with no magic or surprises. The built-in types below are the building blocks you’ll use everywhere, from config values to API responses.
Go’s built-in types cover the essentials:
| Type | Example | Used in baton-junction |
|---|---|---|
string | "baton-junction" | connector name, field labels |
int | 50 | page sizes, counts |
bool | true | required flags, feature toggles |
float64 | 3.14 | numeric precision |
Go is statically typed - every variable has a fixed type determined at compile time. The compiler catches type mismatches before your code ever runs.
Variable Declaration
Go offers two ways to declare variables. Both are valid, but they serve different purposes: use the explicit var form when you need clarity or when declaring at package level, and the short := form when you want concise, type-inferred code inside functions.
var name string = "baton-junction" // explicit type
name := "baton-junction" // short declaration (type inferred)
The long form var can be used anywhere. The short form := is only allowed inside functions - the compiler infers the type from the value on the right side.
You can also group multiple var declarations into a block:
var (
pageSize int = 50
verbose bool = false
baseURL string = "https://api.example.com"
)
The explicit type is optional when the compiler can infer it from the value:
var pageSize = 50 // compiler knows this is int
var verbose = false // compiler knows this is bool
When to Use Which
These three forms cover every situation you’ll encounter. The key is knowing which context you’re in: are you declaring something new, reassigning an existing variable, or working outside a function?
name := "baton-junction"
name = "new-name"
var name string = "baton" Use := when declaring a new variable inside a function. Use = when reassigning an existing one. Use var at the package level or when you want to specify the type explicitly.
Constants
Constants give you safety and clarity: the compiler knows they never change, so you get compile-time guarantees instead of runtime surprises. Values that never change use const:
const connectorName = "baton-junction"
const defaultPageSize = 100
Both of these appear in the baton-junction code - connectorName in cmd/baton-junction/main.go and defaultPageSize in pkg/client/client.go. Constants are evaluated at compile time and cannot be reassigned.
Format String Substitution
Go doesn’t have string interpolation like Python’s f-strings or JavaScript’s template literals. Instead, you use fmt.Sprintf with placeholders to build strings from variables:
name := "baton-junction"
size := 50
msg := fmt.Sprintf("Connector %s with page size %d", name, size)
%s inserts a string, %d inserts an integer, and %v inserts any value in its default format. You’ll use this constantly - from building error messages to formatting display names. The full set of format verbs is covered in the Standard Library lesson.
If connectorName is "baton-junction", what does fmt.Sprintf("Running %s", connectorName) return?
Zero Values
Go never leaves you with uninitialized variables. Every type has a sensible default, so you can safely declare var status string without assigning anything. Every type in Go has a zero value - the default when no value is assigned:
| Type | Zero Value | Meaning |
|---|---|---|
string | "" | empty string |
int | 0 | zero |
bool | false | off |
float64 | 0.0 | zero |
| pointer | nil | no value |
This means you never have uninitialized variables in Go. A var status string is always "", never garbage memory.
Exercise: Declare Connector Config Values
Declare the following four connector configuration values. Replace the comments in the starter code with actual declarations:
- A constant
ConnectorNameset to"baton-junction" - A variable
DefaultPageSizeset to50 - A variable
Verboseset tofalse - A variable
BaseURLset to"https://api.example.com"
Go doesn’t convert between types automatically. To turn an int into a
float64, you write float64(pageSize). To turn an int into a string
for a URL query parameter, you use strconv.Itoa(pageSize) from the
standard library - not string(pageSize), which gives you a Unicode
character. You’ll see strconv in action when we build URL helpers later.
Gopher says
You’ve got the building blocks: basic types, variables, constants, zero values, and format strings. These are the raw materials Go programs are made from.
In baton-junction, you’ll see string for IDs and emails, int for page
sizes, bool for status flags, and fmt.Sprintf for building URL paths
and display names.
Next: functions and error handling!
Next Lesson
Functions & Errors

