Chapter 2. A solid foundation

This chapter covers

  • Working with command-line flags, options, and arguments
  • Passing configuration into an application
  • Starting and gracefully stopping a web server
  • Path routing for web and API servers

The foundation an application is built upon can be as important as any feature. Handling the way an application shuts down so you don’t lose data or create a bad user experience is an example of a step you take when building a strong foundation.

This chapter covers four foundational areas. You’ll start with console applications, also known as CLI applications. You’ll learn about handling command-line options, sometimes called flags or getopts, in a way that’s consistent with modern applications on Linux and other POSIX systems. As part of this, you’ll explore a setup that enables you to focus on application code rather than structure while developing console applications.

You’ll follow that up by looking at several ways to pass configuration into an application. This includes various popular file and content formats used to store configuration.

From there, you’ll move onto servers and practical measures for starting and stopping them. This may seem fairly straightforward, but addressing certain situations early (for example, stopping a server before data has finished being saved) can cut down on future problems.

2.1. Working with CLI applications, the Go way

2.2. Handling configuration

2.3. Working with real-world web servers

2.4. Summary

sitemap