Course Outline
1. Introduction to Go
- Overview of Go (Golang).
- Historical context and design philosophy.
- Go as a language for web and systems programming.
- Key characteristics:
- Static typing.
- Emphasis on simplicity and readability.
- Fast compilation times.
- Native concurrency support.
- Automatic garbage collection.
- Cross-platform compilation capabilities.
- Common use cases for Go.
- Advantages and limitations of the language.
- Comparison with C/C++, JavaScript, Ruby, Python, and Java.
- Understanding the Go ecosystem.
- Overview of the Go standard library.
- Go modules and dependency management.
- Anatomy of a Go application.
- Hands-on: Examine and execute a simple Go program.
2. Setting Up the Go Development Environment
- Installing Go.
- Understanding the Go toolchain.
- Configuring environment variables.
- Selecting an IDE or code editor.
- Utilizing the command line with Go.
- Creating a Go workspace.
- Understanding Go project structure.
- Initializing projects with Go Modules.
- Using
go mod init. - Managing dependencies with
go get. - Updating and inspecting dependencies.
- Formatting source code with
gofmt. - Running programs with
go run. - Building applications with
go build. - Installing Go applications.
- Cross-compiling applications.
- Hands-on: Create and configure a Go project within a container.
3. Go Variables, Constants, and Types
- Variable declaration.
- Explicit versus inferred types.
- Short variable declarations.
- Constants.
- Zero values.
- Variable scope and lifetime.
- Primitive data types:
- Integers.
- Floating-point numbers.
- Complex numbers.
- Booleans.
- Strings.
- Type conversions.
- Working with Unicode and UTF-8.
- Runes and bytes.
- Multiple variable assignment.
- Understanding type safety.
- Exercise: Develop a small command-line data-processing program.
4. Operators and Expressions
- Arithmetic operators.
- Comparison operators.
- Logical operators.
- Assignment operators.
- Increment and decrement operators.
- Operator precedence.
- Integer and floating-point calculations.
- Avoiding common type-conversion errors.
- Exercise: Implement calculation and validation logic.
5. Dates, Times, and Formatting
- Using the
timepackage. - Creating and manipulating dates.
- Retrieving the current time.
- Time zones and locations.
- Parsing dates and times.
- Formatting dates and times.
- Calculating durations.
- Working with Unix timestamps.
- Handling timeouts.
- Exercise: Add timestamps and duration calculations to an application.
6. Arrays, Slices, Maps, and Structs
Arrays
- Declaring arrays.
- Initializing arrays.
- Iterating over arrays.
- Multi-dimensional arrays.
Slices
- Understanding slices versus arrays.
- Creating slices.
- Appending elements.
- Copying slices.
- Slice length and capacity.
- Slicing slices.
- Common slice pitfalls.
Maps
- Creating maps.
- Adding and removing entries.
- Checking for key existence.
- Iterating over maps.
- Maps containing complex data.
Structs
-
Defining structures.
-
Struct fields.
-
Initializing structs.
-
Nested structs.
-
Anonymous structs.
-
Struct methods.
-
JSON struct tags.
-
Hands-on: Model users, products, and application data using structs, slices, and maps.
7. Conditional Logic and Loops
ifstatements.elseandelse if.- Variable declarations within conditions.
forloops.- Infinite loops.
- Loop conditions.
breakandcontinue.- Iterating with
range. - Nested loops.
switchstatements.- Expression-based switches.
- Multiple cases.
- Default cases.
- Type switches.
- Exercise: Implement application validation and processing logic.
8. Functions
- Defining functions.
- Function parameters.
- Return values.
- Multiple return values.
- Named return values.
- Variadic functions.
- Anonymous functions.
- Function values.
- Closures.
- Recursion.
- Passing functions as arguments.
- Error-returning functions.
- Designing small, reusable functions.
- Exercise: Refactor existing code into reusable functions.
9. Pointers and Memory Concepts
- What is a pointer?
- Address-of and dereference operators.
- Pointers and function parameters.
- Pointer receivers.
- Pointers to structs.
- Nil pointers.
- When to use pointers.
- Value versus reference semantics.
- Understanding Go's memory management and garbage collection.
- Common pointer mistakes.
- Hands-on: Modify application data using pointers.
10. Creating a Web Application in Go
- Overview of Go's web capabilities.
- Introduction to the
net/httppackage. - Creating an HTTP server.
- HTTP requests and responses.
- HTTP methods.
- Request URLs and query parameters.
- HTTP headers.
- HTTP status codes.
- Routing fundamentals.
- Creating handlers.
- Handling form data.
- Serving static files.
- Working with HTML templates.
- Template variables and control structures.
- Structuring a web application.
- Hands-on: Build a basic Go web server.
11. Building a RESTful Web Service
- REST architecture fundamentals.
- Designing API endpoints.
- GET, POST, PUT, PATCH, and DELETE methods.
- Working with JSON.
- Encoding and decoding JSON.
- Request validation.
- HTTP status codes.
- Error responses.
- Query parameters and path parameters.
- API response structures.
- Separating handlers from business logic.
- Hands-on: Build a CRUD REST API.
12. Go Runtime, Compilation, and Project Builds
- Understanding the Go compiler.
- Go's build process.
go run.go build.go install.go test.- Build flags.
- Environment-specific configuration.
- Building for different operating systems and architectures.
- Producing standalone binaries.
- Managing application configuration.
- Exercise: Compile the application for multiple platforms.
13. Working with Files and the Web
- Opening and closing files.
- Reading files.
- Writing files.
- Creating directories.
- File metadata.
- Buffered I/O.
- Working with streams.
- Reading and writing JSON files.
- HTTP clients.
- Making outbound HTTP requests.
- Handling HTTP client errors.
- Timeouts and cancellation.
- Processing API responses.
- Hands-on: Retrieve data from an external API and persist it locally.
14. Error Handling and Debugging
- Go's approach to errors.
- Returning errors from functions.
- Checking errors.
- Creating custom errors.
- Wrapping errors.
- Adding context to errors.
errors.Isanderrors.As.- Panic and recovery.
- When to use
panic. - Debugging common Go problems.
- Logging application activity.
- Using Go debugging tools.
- Exercise: Diagnose and fix deliberately introduced application errors.
15. Interfaces and Abstraction
- What is an interface?
- Implicit interface implementation.
- Defining interfaces.
- Interface values.
- Empty interfaces /
any. - Type assertions.
- Type switches.
- Pointer versus value implementations.
- Designing small interfaces.
- Dependency inversion.
- Using interfaces for testing.
- Reducing application coupling.
- Hands-on: Introduce interfaces into the sample web application.
16. Packages and Project Organization
- Creating packages.
- Package naming conventions.
- Exported and unexported identifiers.
- Importing packages.
- Package initialization.
- Organizing application layers.
- Internal packages.
- Managing dependencies with Go Modules.
- Semantic versioning.
- Using third-party packages.
- Avoiding circular dependencies.
- Designing maintainable Go projects.
- Exercise: Refactor the application into separate packages.
17. Concurrency with Goroutines
- What is concurrency?
- Goroutines.
- Starting goroutines.
- Understanding lightweight concurrent execution.
- Synchronization challenges.
- Shared state.
- Race conditions.
- Using
sync.WaitGroup. - Mutexes and read/write mutexes.
- Atomic operations.
- Hands-on: Convert a sequential task into concurrent processing.
18. Channels
- Understanding channels.
- Sending and receiving values.
- Buffered versus unbuffered channels.
- Blocking behavior.
- Closing channels.
- Ranging over channels.
- Directional channels.
- Channel-based communication.
- Select statements.
- Timeouts and cancellation.
- Worker-pool patterns.
- Producer/consumer patterns.
- Hands-on: Build a concurrent worker system.
19. Context and Request Management
- Why contexts are important in web applications.
context.Context.- Request-scoped context.
- Cancellation.
- Deadlines.
- Timeouts.
- Propagating context through application layers.
- Cancelling database or HTTP operations.
- Avoiding context misuse.
- Exercise: Add request cancellation and timeouts to the web application.
20. Testing Go Applications
- Why automated testing matters.
- Writing unit tests.
- The
testingpackage. - Test functions.
- Test naming conventions.
- Table-driven tests.
- Testing errors.
- Testing HTTP handlers.
- HTTP test servers.
- Test fixtures.
- Test coverage.
- Benchmarks.
- Example tests.
- Testing interfaces with mocks or fakes.
- Hands-on: Create a test suite for the sample application.
21. Performance Optimization
- Understanding Go application performance.
- Identifying bottlenecks.
- CPU versus memory performance.
- Efficient data structures.
- Reducing unnecessary allocations.
- Strings, bytes, and buffers.
- Goroutine management.
- Avoiding excessive concurrency.
- Caching strategies.
- Database and network considerations.
- Profiling applications.
- Benchmarks and performance testing.
- Using Go's profiling tools.
- Exercise: Profile and optimize a deliberately inefficient application.
22. Security and Robust Web Application Practices
- Validating user input.
- Safe handling of HTTP requests.
- Preventing common web vulnerabilities.
- Secure error handling.
- Authentication and authorization concepts.
- Managing secrets and configuration.
- Secure HTTP communication.
- Avoiding sensitive information in logs.
- Dependency management and updates.
- Resource limits and request timeouts.
- Exercise: Review and harden the sample API.
23. Application Logging and Observability
- Logging fundamentals.
- Structured logging.
- Log levels.
- Request logging.
- Error logging.
- Correlation and request IDs.
- Monitoring application behavior.
- Basic metrics.
- Health-check endpoints.
- Diagnosing production problems.
- Hands-on: Add structured logging and health checks.
24. Containerizing the Go Application
- Why use containers?
- Go applications and containerization.
- Writing a Dockerfile.
- Multi-stage builds.
- Building a minimal runtime image.
- Managing configuration through environment variables.
- Container networking.
- Exposing application ports.
- Running the application in a container.
- Testing the containerized application.
- Hands-on: Package the sample Go application as a production-ready container.
25. Deployment
- Preparing an application for production.
- Building production binaries.
- Environment configuration.
- Container-based deployment.
- Deployment architecture.
- Reverse proxies.
- HTTPS/TLS considerations.
- Application health checks.
- Graceful shutdown.
- Handling operating-system signals.
- Scaling Go web applications.
- Horizontal versus vertical scaling.
- Basic deployment troubleshooting.
- Hands-on: Deploy the sample web application.
26. Capstone: Complete Go Web Application
Participants integrate the concepts learned by developing a complete application.
The project may include:
- Project initialization with Go Modules.
- Package organization.
- HTTP routing.
- REST API endpoints.
- JSON request and response handling.
- Input validation.
- Error handling.
- Interfaces.
- Concurrent processing.
- External API communication.
- File or database persistence.
- Automated tests.
- Logging.
- Performance considerations.
- Containerization.
- Production configuration.
- Deployment.
27. Review and Best Practices
- Review of core Go syntax.
- Go coding conventions.
- Writing idiomatic Go.
- Keeping code simple.
- Effective package design.
- Error-handling best practices.
- Interface design principles.
- Concurrency best practices.
- Testing strategies.
- Performance considerations.
- Maintainability and readability.
- Common mistakes made by new Go developers.
- Recommended approaches for continuing Go development.
28. Conclusion
- Review of key concepts.
- Review of the completed web application.
- Questions and discussion.
- Troubleshooting common real-world scenarios.
- Recommended next steps for Go development.
- Additional Go libraries and ecosystem resources.
- Further opportunities for building production-grade Go services.
Requirements
- Familiarity with general programming principles.
Audience
- Software Developers.
Testimonials (5)
The trainer proved himself to be an expert of the topic, which I never give for granted. He provided very useful insight on industry standards.
Giuseppe
Course - Learning Go Programming
I enjoyed the amount of hands on exercises we did. I personally learn by doing things so it was good that Francesco had lots of hands-on exercises to do. I struggled to pick up a few of the concepts from the slides but when I actually got hands on and was able to implement some of the key features of the language it helped me understand it better.
Adam Fitzhugh - OpticoreIT
Course - Learning Go Programming
tha pace, trainers ability to help and sustain slightly more difficult questions.
Andrei Mihai - Viasat
Course - Learning Go Programming
Radu's in-depth knowledge, and tailoring the pace for me.
Adeel Ahmad - Coefficient Data Ltd
Course - Learning Go Programming
Flexibility of the trainer. Really catered the course to our specific needs.