no this isn't about alexandria ocasio-cortez
1package internal
2
3import (
4 "fmt"
5 "io"
6 "net/http"
7 "os"
8)
9
10// GetInput fetches the Advent of Code input for the specified day.
11// Requires AOC_SESSION environment variable to be set with your session cookie.
12func GetInput(day int) (string, error) {
13 session := os.Getenv("AOC_SESSION")
14 if session == "" {
15 return "", fmt.Errorf("AOC_SESSION environment variable not set")
16 }
17
18 url := fmt.Sprintf("https://adventofcode.com/2025/day/%d/input", day)
19
20 req, err := http.NewRequest("GET", url, nil)
21 if err != nil {
22 return "", fmt.Errorf("failed to create request: %w", err)
23 }
24
25 req.AddCookie(&http.Cookie{Name: "session", Value: session})
26
27 client := &http.Client{}
28 resp, err := client.Do(req)
29 if err != nil {
30 return "", fmt.Errorf("failed to fetch input: %w", err)
31 }
32 defer resp.Body.Close()
33
34 if resp.StatusCode != http.StatusOK {
35 return "", fmt.Errorf("unexpected status code: %d", resp.StatusCode)
36 }
37
38 body, err := io.ReadAll(resp.Body)
39 if err != nil {
40 return "", fmt.Errorf("failed to read response body: %w", err)
41 }
42
43 return string(body), nil
44}