coding-go
Go 1.23+: goroutines, channels, interfaces, error handling, modules, testing, generics
What this skill does
# coding-go
## Purpose
This skill equips the AI to handle Go programming tasks using features from Go 1.23+, focusing on advanced concurrency, modular code, and robust error management. Use it to generate, debug, and optimize Go code in real-time interactions.
## When to Use
Apply this skill for concurrent programming needs, like building scalable servers with goroutines and channels. Use it when developing modular applications with interfaces and generics, or for testing and error-prone codebases in Go 1.23+. Avoid it for basic scripting; opt for other languages if Go's ecosystem isn't required.
## Key Capabilities
- **Goroutines**: Spawn lightweight threads for concurrency; e.g., use `go func() { fmt.Println("Task") }()` to run asynchronously.
- **Channels**: Facilitate safe communication between goroutines; declare with `ch := make(chan int)` and send/receive via `ch <- 5` or `<-ch`.
- **Interfaces**: Define contracts for polymorphism; e.g., `type Writer interface { Write([]byte) error }`.
- **Error Handling**: Check errors explicitly, as in `if err != nil { return err }`, with support for wrapped errors via `errors.Is()`.
- **Modules**: Manage dependencies with `go mod`; initialize via `go mod init example.com/project`.
- **Testing**: Write unit tests using the `testing` package; e.g., `func TestAdd(t *testing.T) { if add(1,2) != 3 { t.Error("Failed") } }`.
- **Generics**: Use type parameters in functions; e.g., `func Map[T any](slice []T, f func(T) T) []T { ... }`.
## Usage Patterns
To implement concurrency, always pair goroutines with channels to avoid race conditions; for example, create a channel first, then launch goroutines that send data to it. For modular code, structure packages with interfaces to decouple dependencies—import modules via `go get` and use `import "example.com/pkg"`. When handling errors, wrap them for context using `fmt.Errorf("wrap: %w", err)` and propagate up the call stack. For generics, define type constraints like `[T comparable]` to ensure type safety in functions. Test code by running `go test -v` in the package directory after writing tests in `_test.go` files.
## Common Commands/API
Use the Go CLI for building and running code:
- `go run main.go`: Compile and execute a file; add `-race` flag for detecting race conditions, e.g., `go run -race main.go`.
- `go build -o output.bin`: Compile to an executable; include `-trimpath` for security, e.g., `go build -trimpath -o app`.
- `go mod tidy`: Clean up dependencies in go.mod; run after adding imports.
- `go test -cover`: Run tests with coverage; e.g., `go test -coverprofile=coverage.out ./pkg`.
API patterns include standard library functions like `sync.WaitGroup` for goroutine synchronization (e.g., `var wg sync.WaitGroup; wg.Add(1); go func() { defer wg.Done(); ... }(); wg.Wait()`). For external tools, set environment variables like `$GO111MODULE=on` to enable modules.
## Integration Notes
Integrate this skill by ensuring the AI has access to a Go 1.23+ environment; install via `brew install go` on macOS or download from golang.org. For authenticated tools like GitHub integration with Go modules, use env vars such as `$GITHUB_TOKEN` for `go get` commands. Configure the AI's workspace with a go.mod file: create one using `go mod init myproject`, then reference it in prompts. If using IDE extensions, specify paths like `$GOPATH/src` and ensure the AI prefixes commands with the correct working directory, e.g., `cd /path/to/project && go run main.go`.
## Error Handling
Always check errors after operations that can fail, such as file I/O or API calls; use `if err := os.Open("file.txt"); err != nil { log.Fatal(err) }`. For wrapped errors, employ `errors.Unwrap()` to inspect chains. In concurrent code, handle panics with `recover()` inside goroutines: e.g., `go func() { defer func() { if r := recover(); r != nil { log.Error(r) } }(); riskyFunction() }()`. Use `go vet` to catch common issues: run `go vet ./...` in the project root.
## Concrete Usage Examples
1. **Concurrent Data Processing**: To process a list concurrently, use goroutines and channels: `ch := make(chan int); go func() { for i := 0; i < 10; i++ { ch <- i*2 } }(); result := <-ch; fmt.Println(result)`.
2. **Generic Function for Sorting**: Implement a generic sort helper: `func Sort[T []int](slice T) { sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] }) } main() { nums := []int{3,1,2}; Sort(nums); fmt.Println(nums) }`.
## Graph Relationships
- Related to: coding (cluster), specifically coding-python and coding-java via shared tags like "coding".
- Connected via tags: "go" links to general programming skills; "goroutine" and "channel" relate to concurrency-focused skills like coding-concurrency.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.