Course Outline
1. Introduction to Go
- What is Go (Golang)?
- The history and design philosophy behind Go.
- Go as a language for web and systems programming.
- Key characteristics:
- Static typing.
- Emphasis on simplicity and readability.
- Rapid compilation.
- Native support for concurrency.
- Automated garbage collection.
- Cross-platform compilation capabilities.
- Typical use cases for Go.
- Advantages and constraints of the Go ecosystem.
- Comparison of Go with C/C++, JavaScript, Ruby, Python, and Java.
- An overview of the Go ecosystem.
- The standard library in Go.
- Go modules and dependency management strategies.
- The anatomy of a Go application.
- Hands-on: Inspecting and executing a simple Go program.
2. Configuring the Go Development Environment
- Installing Go.
- Understanding the Go toolchain.
- Setting environment variables.
- Selecting an IDE or code editor.
- Interacting with Go via the command line.
- Establishing a Go workspace.
- Understanding the project structure in Go.
- Initializing projects using Go Modules.
- Utilizing
go mod init. - Managing dependencies with
go get. - Updating and inspecting dependencies.
- Formatting source code using
gofmt. - Executing programs with
go run. - Compiling applications with
go build. - Installing Go applications.
- Cross-compiling applications.
- Hands-on: Creating and configuring a Go project within a container.
3. Variables, Constants, and Data Types in Go
- Declaring variables.
- Explicit versus inferred types.
- Short variable declarations.
- Defining constants.
- Understanding zero values.
- Variable scope and lifetime.
- Primitive data types:
- Integers.
- Floating-point numbers.
- Complex numbers.
- Booleans.
- Strings.
- Type conversion techniques.
- Handling Unicode and UTF-8.
- Runes and bytes.
- Assigning multiple variables.
- Understanding type safety.
- Exercise: Building a small command-line data-processing program.
4. Operators and Expressions
- Arithmetic operators.
- Comparison operators.
- Logical operators.
- Assignment operators.
- Increment and decrement operations.
- Operator precedence rules.
- Performing integer and floating-point calculations.
- Avoiding common type-conversion errors.
- Exercise: Implementing calculation and validation logic.
5. Dates, Times, and Formatting
- Using the
timepackage. - Creating and manipulating dates.
- Retrieving the current time.
- Managing time zones and locations.
- Parsing date and time strings.
- Formatting dates and times.
- Calculating time durations.
- Working with Unix timestamps.
- Handling timeouts.
- Exercise: Incorporating timestamps and duration calculations into an application.
6. Arrays, Slices, Maps, and Structs
Arrays
- Declaring arrays.
- Initializing arrays.
- Iterating through arrays.
- Handling multidimensional arrays.
Slices
- Distinguishing between slices and arrays.
- Creating slices.
- Appending elements to slices.
- Copying slices.
- Understanding slice length and capacity.
- Slicing existing slices.
- Common pitfalls when working with slices.
Maps
- Creating maps.
- Adding and removing map entries.
- Checking for key existence.
- Iterating over maps.
- Maps containing complex data types.
Structs
-
Defining structures.
-
Working with struct fields.
-
Initializing structs.
-
Handling nested structs.
-
Using anonymous structs.
-
Implementing struct methods.
-
Utilizing JSON struct tags.
-
Hands-on: Modeling users, products, and application data using structs, slices, and maps.
7. Conditional Logic and Loops
ifstatements.elseandelse ifclauses.- Declaring variables within conditions.
forloops.- Creating infinite loops.
- Defining loop conditions.
- Using
breakandcontinue. - Iterating using
range. - Nested loops.
switchstatements.- Expression-based switches.
- Handling multiple cases.
- Default cases.
- Type switches.
- Exercise: Implementing application validation and processing logic.
8. Functions
- Defining functions.
- Managing function parameters.
- Returning values.
- Multiple return values.
- Named return values.
- Variadic functions.
- Anonymous functions.
- Function values.
- Closures.
- Recursion.
- Passing functions as arguments.
- Functions that return errors.
- Designing small, reusable functions.
- Exercise: Refactoring existing code into reusable functions.
9. Pointers and Memory Concepts
- Understanding pointers.
- Address-of and dereference operators.
- Pointers and function parameters.
- Pointer receivers.
- Pointers to structs.
- Nil pointers.
- Scenarios where pointers are beneficial.
- Value versus reference semantics.
- Go's memory management and garbage collection.
- Common pointer-related errors.
- Hands-on: Modifying application data using pointers.
10. Developing a Web Application in Go
- Overview of Go's web capabilities.
- Introduction to the
net/httppackage. - Creating an HTTP server.
- Handling HTTP requests and responses.
- HTTP methods.
- Request URLs and query parameters.
- HTTP headers.
- HTTP status codes.
- Routing fundamentals.
- Creating handlers.
- Processing form data.
- Serving static files.
- Working with HTML templates.
- Template variables and control structures.
- Structuring a web application.
- Hands-on: Building 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 and path parameters.
- API response structures.
- Separating handlers from business logic.
- Hands-on: Building a CRUD REST API.
12. Go Runtime, Compilation, and Project Builds
- Understanding the Go compiler.
- The Go 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: Compiling the application for multiple platforms.
13. Working with Files and the Web
- Opening and closing files.
- Reading file contents.
- Writing to files.
- Creating directories.
- File metadata.
- Buffered I/O operations.
- 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: Retrieving data from an external API and persisting it locally.
14. Error Handling and Debugging
- Go's approach to errors.
- Returning errors from functions.
- Checking for errors.
- Creating custom errors.
- Wrapping errors.
- Adding context to errors.
errors.Isanderrors.As.- Panic and recovery.
- When to use
panic. - Debugging common Go issues.
- Logging application activity.
- Using Go debugging tools.
- Exercise: Diagnosing and fixing deliberately introduced application errors.
15. Interfaces and Abstraction
- What is an interface?
- Implicit interface implementation.
- Defining interfaces.
- Interface values.
- Empty interfaces and
any. - Type assertions.
- Type switches.
- Pointer versus value implementations.
- Designing small interfaces.
- Dependency inversion.
- Using interfaces for testing.
- Reducing application coupling.
- Hands-on: Introducing 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: Refactoring 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: Converting 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: Building 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: Adding request cancellation and timeouts to the web application.
20. Testing Go Applications
- The importance of automated testing.
- Writing unit tests.
- The
testingpackage. - Test functions.
- Test naming conventions.
- Table-driven tests.
- Testing error handling.
- Testing HTTP handlers.
- HTTP test servers.
- Test fixtures.
- Test coverage.
- Benchmarks.
- Example tests.
- Testing interfaces with mocks or fakes.
- Hands-on: Creating 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: Profiling and optimizing 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: Reviewing and hardening 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: Adding structured logging and health checks.
24. Containerizing the Go Application
- The benefits of using 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: Packaging 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: Deploying the sample web application.
26. Capstone: Complete Go Web Application
Participants will consolidate their knowledge 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
- A solid grasp of general programming principles.
Target 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.