Читать книгу Practical Go - Amit Saha - Страница 53

An Architecture for Sub-command-Driven Applications

Оглавление

As you develop your command-line application, it is a good idea to keep your main package lean and to create a separate package or packages for the sub-command implementations. Your main package will parse the command-line arguments and call the relevant sub-command handler function. If the arguments provided are not recognizable, a help message is displayed containing the usage message for all of the recognized sub-commands (see Figure 2.2).

Next, you lay down the foundation of a generic command-line network client, which you will build upon in later chapters. We will call this program mync (short for my network client). For now, you will ignore the implementation of the sub-commands and come back to it in later chapters when you fill in the implementation.


Figure 2.2: The main package implements the root command. A sub-command is implemented in its own package.

Let's look at the implementation of the main package first. Here, we will only have a single file, main.go, to start (see Listing 2.2).

Practical Go

Подняться наверх