Powerful Command-Line Applications in Go: Build Fast and Maintainable Tools
Whether you want to automate tasks, analyze data, parse logs, talk to network services, or address other systems requirements, writing your own command-line tool may be the fastest – and perhaps the most fun – way to do it. The Go programming language is a great choice for developing tools that are fast, reliable, and cross-platform. Create command-line tools that work with files, connect to services, and even manage external processes, all while using tests and benchmarks to ensure your programs are fast and correct.
When you want to develop cross platform command-line tools that are fast and reliable, use Go, a modern programming language that combines the reliability of compiled languages with the ease of use and flexibility of dynamic typed languages. Work through practical examples to develop elegant and efficient tools by applying Go’s rich standard library, its built in support for concurrency, and its expressive syntax. Use Go’s integrated testing capabilities to automatically test your tools, ensuring they work reliably even across code refactoring.
Develop CLI tools that interact with your users by using common input/output patterns, including environment variables and flags. Handle files to read or persist data, and manipulate paths consistently in cross-platform scenarios. Control processes and handle signals, and use a benchmark driven approach and Go’s concurrency primitives to create tools that perform well. Use powerful external libraries such as Cobra to create modern and flexible tools that handle subcommands, and develop tools that interact with databases, APIs, and network services. Finally, leverage what you learned by tackling additional challenges at the end of each chapter.
What You Need:
Go 1.8 or higher, an internet connection to download the example files and additional libraries, and a text editor to write your programs.
Powerful Command-Line Application s in Go About the Pragmatic Bookshelf Table of Contents Early Praise for Powerful Command-Line Applications in Go Foreword Acknowledgments Preface What’s in This Book How to Use This Book About the Example Code Go Modules Online Resources Chapter 1: Your First Command-Line Program in Go Building the Basic Word Counter Testing the Basic Word Counter Adding Command-Line Flags Compiling Your Tool for Dif ferent Platforms Exercises Wrapping Up Chapter 2: Interacting with Your Users Organizing Your Code Defining the To-Do API Creating the Initial To-Do Command-L ine Tool Testing the Initial CLI Implementati on Handling Multiple Command-Line Options Display Command-Line Tool Usage Improving the List Output Forma t Increasing Flexibility with Environment Variables Capturing Input from STDIN Exercises Wrapping Up Chapter 3: Working with Files in Go Creating a Basic Markdown Prev iew Tool Writing Tests for the Markdo wn Preview Tool Adding Temporary Files to the Markdown Preview Tool Using Interfaces t o Automate Tests Adding an Auto-Preview F eature Cleaning Up Temporary Files Improving the Markdown Pre view Tool with Templates Exercises Wrapping Up Chapter 4: Navigating the File System Developing a File System Crawler Testing with Table-Driven T esting Deleting Matched Files Testing with the Help of T est Helpers Logging Deleted Files Archiving Files Exercises Wrapping Up Chapter 5: Improving the Performance of Your CLI Tools Developing the Initial Version of colStats Writing Tests for colStats Benchmarking Your Tool Profiling Your Tool Reducing Memory Allocation Tracing Your Tool Improving the colStats Tool to Process Files Concurrently Reduce Scheduling Contention Exercises Wrapping Up Chapter 6: Controlling Processes Executing External Programs Handling Errors Writing Tests for Goci Defining a Pipeline Adding Another Step to the Pipe line Handling Output from External Pr ograms Running Commands with Contexts Integration Tests with a Local G it Server Testing Commands with Mock Reso urces Handling Signals Exercises Wrapping Up Chapter 7: Using the Cobra CLI Framework Starting Your Cobra Application Navigating Your New Cobra Applicati on Adding the First Subcommand to Your Application Starting the Scan Package Creating the Subcommands to Mana ge Hosts Testing the Manage Hosts Subcomman ds Adding the Port Scanning Function ality Using Viper for Configuration Manag ement Generating Command Completion an d Documentation Exercises Wrapping Up Chapter 8: Talking to REST APIs Developing a REST API Server Testing the REST API Server Completing the REST API Server Developing the Initial Client for th e REST API Testing the Client Without Co nnecting to the API Viewing a Single Item Adding an Item Testing HTTP Requests Locally Completing and Deleting Ite ms Executing Integration Te sts Exercises Wrapping Up Chapter 9: Developing Interactive Terminal Tools Initializing the Pomodoro Application Storing Data with the Repository Pat tern Testing the Pomodoro Functionality Building the Interface Widgets Organizing the Interface’s Layout Building the Interactive Interface Initializing the CLI with Cobra Exercises Wrapping Up Chapter 10: Persisting Data in a SQL Database Getting Started with SQLite Go, SQL, and SQLite Persisting Data in the Database Testing the Repository with SQLite Updating the Application to Use the SQ Lite Repository Displaying a Summary to the Users Exercises Wrapping Up Chapter 11: Distributing Your Tool Starting the Notify Package Including OS-Specific Data Including OS-Specific Files in the Buil d Testing the Notify Package Conditionally Building Your Applic ation Cross-Compiling Your Application Compiling Your Go Application for Co ntainers Distributing Your Application as Sou rce Code Exercises Wrapping Up You May Be Interested In…
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.