Go compiles to static binaries — ideal for containers. Cross-compilation is built in via GOOS/GOARCH.

Cross Compile

  GOOS=linux GOARCH=amd64 go build -o app-linux .
GOOS=windows GOARCH=amd64 go build -o app.exe .
  

Static Binary

  CGO_ENABLED=0 go build -ldflags='-s -w' -o app .
  

Dockerfile

  FROM golang:1.22 AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o /app

FROM scratch
COPY --from=builder /app /app
ENTRYPOINT ["/app"]
  

Health Checks

Expose /health endpoint. Use readiness vs liveness probes in Kubernetes.

Configuration

Use environment variables or flags (flag package). Never hardcode secrets.

Common Pitfalls

  • Ignoring returned errors in Go or fighting the borrow checker in Rust.
  • Premature optimization before profiling.
  • Skipping tests for concurrent and error paths.
  • Not reading standard library documentation.

Best Practices

  • Follow language idioms (Go: explicit errors; Rust: ownership).
  • Write table-driven tests.
  • Use go fmt / cargo fmt consistently.
  • Keep functions small and focused.

Memory and Performance Notes

Static binary ~5-15MB. UPX compression possible but affects startup.

Exercise

Create a multi-stage Dockerfile for a Go HTTP server. Image should be under 10MB.

Hint: Use FROM scratch or distroless for minimal images.

Summary

Practice these concepts in small programs before building production services.

Debugging Checklist

  1. Read the full error message.
  2. Reduce to minimal reproduction.
  3. Check types and return values.
  4. Add logging at decision points.
  5. Write a test that catches the bug.

Real-World Application

Production services combine these fundamentals with logging, metrics, and graceful degradation.

Further Reading

Official language documentation, effective guides, and mature open-source projects.

Additional Examples

Consider how this topic applies in a larger project:

  // Break the problem into smaller functions
// Test each function independently
// Integrate incrementally
  

Working through variations of the examples above builds deeper understanding than reading alone.

Interview and Review Questions

  1. Explain the core concept of this topic in your own words.
  2. What happens when this code runs with edge-case input (empty, null, zero, max value)?
  3. How would you debug a bug related to this topic in production?
  4. What are the performance implications of the approach shown here?
  5. How does this feature compare to the equivalent in another language you know?

Review adjacent pages in the learning path before and after this one. Concepts build on each other — skipping ahead often leads to confusion when later pages assume mastery of earlier material.

Return to the section index if you need to fill gaps in prerequisite knowledge.

Tooling Tips

  • Enable all compiler or analyzer warnings during development.
  • Use version control with small, focused commits for each exercise.
  • Pair reading with typing — reproduce every code example by hand.
  • Run tests or compile after every change to catch errors early.
  • Keep a personal notes file linking concepts to your own project experiences.

Additional Examples

Consider how this topic applies in a larger project:

  // Break the problem into smaller functions
// Test each function independently
// Integrate incrementally
  

Working through variations of the examples above builds deeper understanding than reading alone.

Interview and Review Questions

  1. Explain the core concept of this topic in your own words.
  2. What happens when this code runs with edge-case input (empty, null, zero, max value)?
  3. How would you debug a bug related to this topic in production?
  4. What are the performance implications of the approach shown here?
  5. How does this feature compare to the equivalent in another language you know?