Course Outline
1. Introduction to Go
- Defining Go (Golang)
- The history and design philosophy behind Go
- Go’s role in web and systems programming
- Key characteristics:
- Static typing
- Simplicity and readability
- Rapid compilation
- Native concurrency support
- Garbage collection
- Cross-platform compilation capabilities
- Typical use cases for Go
- Strengths and potential limitations of the language
- Comparison of Go with C/C++, JavaScript, Ruby, Python, and Java
- Navigating the Go ecosystem
- Overview of the Go standard library
- Go modules and managing dependencies
- Anatomy of a Go application
- Hands-on: Inspect and execute a basic Go program
2. Setting Up the Go Development Environment
- Installing Go
- Understanding the Go toolchain
- Configuring environment variables
- Selecting an IDE or code editor
- Interacting with Go via the command line
- 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 using
gofmt - Executing 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 vs. inferred types
- Short variable declaration syntax
- 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 simple command-line data processing tool
4. Operators and Expressions
- Arithmetic operators
- Comparison operators
- Logical operators
- Assignment operators
- Increment and decrement
- Operator precedence
- Handling integer and floating-point calculations
- Avoiding common type conversion errors
- Exercise: Implement calculation and validation logic
5. Dates, Times, and Formatting
- Utilizing the
timepackage - Creating and manipulating date objects
- Retrieving the current time
- Time zones and geographic locations
- Parsing date and time strings
- Formatting dates and times for output
- Calculating durations
- Working with Unix timestamps
- Handling timeouts
- Exercise: Integrate timestamps and duration calculations into an application
6. Arrays, Slices, Maps, and Structs
Arrays
- Declaring arrays
- Initializing arrays
- Iterating over arrays
- Multidimensional arrays
Slices
- Distinguishing slices from arrays
- Creating slices
- Appending elements
- Copying slices
- Managing slice length and capacity
- Slicing within slices
- Common pitfalls with slices
Maps
- Creating maps
- Adding and removing key-value entries
- Verifying the existence of keys
- Iterating over maps
- Maps holding complex data structures
Structs
-
Defining structures
-
Working with 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
ifstatementselseandelse ifconditions- Declaring variables within conditions
forloops- Infinite loops
- Loop conditions
breakandcontinuestatements- Iterating using
range - Nested loops
switchstatements- Expression-based switches
- Handling 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
- Functions as values
- Closures
- Recursion
- Passing functions as arguments
- Functions that return errors
- Designing small, reusable functions
- Exercise: Refactor existing code into reusable functions
9. Pointers and Memory Concepts
- Understanding pointers
- Address-of and dereference operators
- Pointers in function parameters
- Pointer receivers
- Pointers to structs
- Nil pointers
- When to utilize pointers
- Value vs. reference semantics
- Go's memory management and garbage collection
- Common pointer-related 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
- Handling HTTP requests and responses
- HTTP methods
- Request URLs and query parameters
- HTTP headers
- HTTP status codes
- Fundamentals of routing
- Creating handlers
- Processing 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 data
- Encoding and decoding JSON
- Request validation
- HTTP status codes
- Handling error responses
- Query and path parameters
- Structuring API responses
- Separating handlers from business logic
- Hands-on: Build a CRUD REST API
12. Go Runtime, Compilation, and Project Builds
- Understanding the Go compiler
- The Go build process
go rungo buildgo installgo 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 file contents
- Writing to files
- Creating directories
- Accessing 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 store it locally
14. Error Handling and Debugging
- Go's approach to error handling
- Returning errors from functions
- Checking for errors
- Creating custom error types
- Wrapping errors
- Adding context to errors
errors.Isanderrors.As- Panic and recovery mechanisms
- When to use
panic - Debugging common Go issues
- Logging application activity
- Utilizing Go debugging tools
- Exercise: Diagnose and fix intentionally introduced application errors
15. Interfaces and Abstraction
- Understanding interfaces
- Implicit interface implementation
- Defining interfaces
- Interface values
- Empty interfaces and
any - Type assertions
- Type switches
- Pointer vs. value implementations
- Designing small, focused 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 vs. 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
- Understanding concurrency
- Goroutines
- Starting goroutines
- 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 vs. 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
- The importance of contexts in web applications
context.Context- Request-scoped contexts
- Cancellation
- Deadlines
- Timeouts
- Propagating context through application layers
- Cancelling database or HTTP operations
- Avoiding common context misuse
- Exercise: Add 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 scenarios
- Testing HTTP handlers
- HTTP test servers
- Test fixtures
- Test coverage
- Performance benchmarks
- Example tests
- Testing interfaces with mocks or fakes
- Hands-on: Create a comprehensive test suite for the sample application
21. Performance Optimization
- Understanding Go application performance
- Identifying bottlenecks
- CPU vs. memory performance
- Efficient data structures
- Reducing unnecessary memory allocations
- Handling strings, bytes, and buffers
- Goroutine management
- Avoiding excessive concurrency
- Caching strategies
- Database and network considerations
- Profiling applications
- Benchmarks and performance testing
- Utilizing Go's built-in 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 data 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 issues
- Hands-on: Implement 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 minimal runtime images
- Managing configuration via 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 vs. vertical scaling
- Basic deployment troubleshooting
- Hands-on: Deploy the sample web application
26. Capstone: Complete Go Web Application
Participants will consolidate their knowledge by developing a complete, functional application.
The project may include:
- Project initialization with Go Modules
- Logical 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
- Maintaining code simplicity
- 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 continued 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
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.