
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
github.com/hvpaiva/goaoc
Go AOC is a Go library designed to simplify the process of running Advent of Code challenges. It streamlines input/output handling and lets you manage challenge execution with ease.
To install the library, you can use the following command:
go get github.com/hvpaiva/goaoc
To quickly integrate Go AOC in your workflow, execute a simple challenge:
package main
import (
"log"
"github.com/hvpaiva/goaoc"
)
func main() {
err := goaoc.Run("yourInputData", partOne, partTwo, goaoc.WithPart(1))
if err != nil {
log.Fatalf("Run failed: %v", err)
}
}
func partOne(input string) int {
// Implement your algorithm for part one here
}
func partTwo(input string) int {
// Implement your algorithm for part two here
}
Here's how to use Go AOC in a project:
package main
import (
"log"
"github.com/hvpaiva/goaoc"
)
func main() {
err := goaoc.Run("example input", partOne, partTwo)
if err != nil {
log.Fatalf("Error running challenge: %v", err)
}
}
func partOne(input string) int {
// Logic for part one
return len(input)
}
func partTwo(input string) int {
// Logic for part two (e.g., double length)
return len(input) * 2
}
Challenge functions should receive a string
input and return an int
. Design purposes or parsing can be done within
these functions.
part
ParameterMultiple strategies exist for specifying the challenge part:
Using a Flag: You can pass the --part
flag when running the challenge. Valid values are 1
or 2
.
go run main.go --part=1
Using an Environment Variable: Set the GOAOC_CHALLENGE_PART
environment variable to 1
or 2
.
export GOAOC_CHALLENGE_PART=2
go run main.go
Through Standard Input: If neither a flag nor an environment variable is provided, the program will prompt you to input the part number via the console.
Which part do you want to run? (1/2)
> 1
Using a Function Parameter: Directly specify the part by using the goaoc.WithPart(part)
option when calling goaoc.Run
.
goaoc.Run(input, partOne, partTwo, goaoc.WithPart(1))
goaoc.Run
supports configurations via options like:
Auto-copies results to clipboard—useful for quick submission.
Disable using
GOAOC_DISABLE_COPY_CLIPBOARD=true
.
Implement custom input/output handling using your own IOManager
:
type customManager struct {}
func (m *customManager) Read(arg string) (string, error) {
// Custom input logic
}
func (m *customManager) Write(output string) error {
// Custom output logic
}
customManager := &customManager{}
goaoc.Run(input, do, doAgain, goaoc.WithManager(customManager))
Alter the default environment setting for DefaultConsoleManager
:
var customEnv = goaoc.Env{
Stdin: bytes.NewBufferString(""),
Stdout: new(bytes.Buffer),
Args: []string{},
}
goaoc.Run(input, do, doAgain, goaoc.WithManager(goaoc.DefaultConsoleManager{Env: customEnv}))
The Run
function propagates errors for handling:
if err := goaoc.Run(input, do, doAgain); err != nil {
log.Fatal(err)
}
Note: All errors in internal flow are returned in goaoc.Run functions. Except for copying to clipboard, which just logs the error, but does not break the execution. The errors are also all typed, so you can check the type of the error.
If you encounter issues, consider:
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.