package
1.0.5
Repository: https://github.com/yitsushi/go-aoc.git
Documentation: pkg.go.dev

# README

Advent of Code helper

You can also get the [JSON] for this private leaderboard. Please don't make frequent automated requests to this service - avoid sending requests more often than once every 15 minutes (900 seconds). If you do this from a script, you'll have to provide your session cookie in the request; a fresh session cookie lasts for about a month. Timestamps use Unix time.

Source: adventofcode.com

Download input file

targetDir := fmt.Sprintf("input/day%02d", dayNumber)
targetFile := fmt.Sprintf("%s/input", targetDir)

ensurePath(targetDir)

client := aoc.NewClient(os.Getenv("AOC_SESSION"))

err := client.DownloadAndSaveInput(currentYear, dayNumber, targetFile)
if err != nil {
    logrus.Fatal(err.Error())

    return
}

Submit a solution

client := aoc.NewClient(os.Getenv("AOC_SESSION"))

valid, err := client.SubmitSolution(currentYear, dayNumber, partNumber, solution)
if err != nil {
    fmt.Printf("%s\n", err.Error())

    return
}

if valid {
    fmt.Println("Done \\o/")
} else {
    fmt.Println("Something is wrong :(")
}

# Functions

NewClient creates a new client.

# Constants

AlreadySolved means our solution is already there.
CorrectAnswer is the goal.
NoSession means the provided token was not valid.
RequestTimout is the timeout of a request in seconds.
WaitMore means you have to wait more.
WrongAnswer means the solution was incorrect.

# Structs

Client for Advent of Code.
DownloadError occurs when the AoC server returns with a status code other than 200.
IncorrectAnswerError occurs when the provided answer is not correct.
NetworkError occurs when something went wrong with the HTTP request.
SubmitError occurs when the AoC server returns with a status code other than 200.

# Interfaces

HTTPClient is a simple interface for http.Client.