go-fundamentals
Core Go programming concepts - syntax, types, interfaces, error handling
What this skill does
# Go Fundamentals Skill
Master core Go programming concepts for production-ready applications.
## Overview
Comprehensive skill covering Go syntax, type system, interfaces, and idiomatic error handling patterns following Effective Go and Google Go Style Guide.
## Parameters
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| topic | string | yes | - | Topic to learn: "types", "interfaces", "errors", "packages" |
| level | string | no | "intermediate" | Skill level: "beginner", "intermediate", "advanced" |
| include_examples | bool | no | true | Include code examples |
## Validation Rules
```go
func ValidateRequest(req SkillRequest) error {
validTopics := []string{"types", "interfaces", "errors", "packages", "structs"}
if !slices.Contains(validTopics, req.Topic) {
return fmt.Errorf("invalid topic %q: must be one of %v", req.Topic, validTopics)
}
return nil
}
```
## Core Topics
### Types & Structs
```go
type User struct {
ID int64 `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Email string `json:"email" db:"email"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
func (u *User) Validate() error {
if u.Name == "" {
return errors.New("name is required")
}
if !strings.Contains(u.Email, "@") {
return errors.New("invalid email format")
}
return nil
}
```
### Interface Design
```go
// Small, focused interfaces
type Reader interface {
Read(p []byte) (n int, err error)
}
type Writer interface {
Write(p []byte) (n int, err error)
}
// Composition over inheritance
type ReadWriter interface {
Reader
Writer
}
```
### Error Handling
```go
// Sentinel errors
var (
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
)
// Error wrapping with context
func GetUser(id int64) (*User, error) {
user, err := db.FindByID(id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrNotFound
}
return nil, fmt.Errorf("get user %d: %w", id, err)
}
return user, nil
}
// Custom error types
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("%s: %s", e.Field, e.Message)
}
```
## Retry Logic
```go
func withRetry[T any](fn func() (T, error), maxRetries int) (T, error) {
var zero T
backoff := 100 * time.Millisecond
for i := 0; i < maxRetries; i++ {
result, err := fn()
if err == nil {
return result, nil
}
if i < maxRetries-1 {
time.Sleep(backoff)
backoff *= 2
}
}
return zero, fmt.Errorf("max retries exceeded")
}
```
## Logging & Observability
```go
import "log/slog"
func ProcessRequest(ctx context.Context, req Request) error {
logger := slog.With(
"request_id", ctx.Value("request_id"),
"user_id", req.UserID,
)
logger.Info("processing request", "action", req.Action)
if err := validate(req); err != nil {
logger.Error("validation failed", "error", err)
return err
}
logger.Info("request processed successfully")
return nil
}
```
## Unit Test Template
```go
func TestUser_Validate(t *testing.T) {
tests := []struct {
name string
user User
wantErr bool
}{
{
name: "valid user",
user: User{Name: "John", Email: "[email protected]"},
wantErr: false,
},
{
name: "empty name",
user: User{Name: "", Email: "[email protected]"},
wantErr: true,
},
{
name: "invalid email",
user: User{Name: "John", Email: "invalid"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.user.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
```
## Troubleshooting
### Failure Modes
| Symptom | Cause | Fix |
|---------|-------|-----|
| `nil pointer dereference` | Uninitialized pointer | Check nil before use |
| `interface conversion panic` | Wrong type assertion | Use comma-ok idiom |
| `import cycle` | Circular dependencies | Extract to new package |
### Debug Checklist
1. Run `go vet ./...` for static analysis
2. Run `go build ./...` for compilation check
3. Check error handling covers all paths
## Usage
```
Skill("go-fundamentals")
```
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.