Powerful Command-Line Applications in Go: Build Fast and Maintainable Tools
暫譯: 使用 Go 建立強大的命令列應用程式:快速且可維護的工具

Gerardi, Ricardo

  • 出版商: Pragmatic Bookshelf
  • 出版日期: 2022-01-11
  • 定價: $1,600
  • 售價: 8.8$1,408
  • 語言: 英文
  • 頁數: 250
  • 裝訂: Paperback
  • ISBN: 168050696X
  • ISBN-13: 9781680506969
  • 相關分類: Command LineGo 程式語言
  • 立即出貨 (庫存 < 3)

買這商品的人也買了...

相關主題

商品描述

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.

商品描述(中文翻譯)

無論您想自動化任務、分析數據、解析日誌、與網絡服務交互,或滿足其他系統需求,編寫自己的命令行工具可能是最快的方式——也許還是最有趣的方式。Go 程式語言是開發快速、可靠且跨平台工具的絕佳選擇。創建與文件交互、連接服務,甚至管理外部進程的命令行工具,同時使用測試和基準來確保您的程式快速且正確。

當您想開發快速且可靠的跨平台命令行工具時,使用 Go,這是一種現代程式語言,結合了編譯語言的可靠性與動態類型語言的易用性和靈活性。通過實際範例,應用 Go 的豐富標準庫、內建的並發支持和表達性語法,開發優雅且高效的工具。利用 Go 的集成測試功能自動測試您的工具,確保它們在代碼重構後仍能可靠運行。

開發與用戶互動的 CLI 工具,使用常見的輸入/輸出模式,包括環境變數和標誌。處理文件以讀取或持久化數據,並在跨平台場景中一致地操作路徑。控制進程和處理信號,並使用基準驅動的方法和 Go 的並發原語來創建性能良好的工具。使用強大的外部庫,如 Cobra,來創建現代且靈活的工具,處理子命令,並開發與數據庫、API 和網絡服務交互的工具。最後,利用您所學的知識,通過在每章結尾解決額外挑戰來加強學習。

您需要的條件:

Go 1.8 或更高版本,連接互聯網以下載範例文件和其他庫,以及一個文本編輯器來編寫您的程式。

作者簡介

Ricardo Gerardi is an IT professional with over 20 years experience in large and small companies. He's currently working as Automation Consultant at Red Hat. Ricardo has been developing command line tools for a long time, for different purposes including automation, monitoring, and data analysis tools, and he has now adopted Go for all his projects.

作者簡介(中文翻譯)

Ricardo Gerardi 是一位擁有超過 20 年經驗的 IT 專業人士,曾在大型和小型公司工作。他目前在 Red Hat 擔任自動化顧問。Ricardo 長期以來一直在開發命令列工具,這些工具用於自動化、監控和數據分析等不同目的,現在他已經在所有項目中採用了 Go。

目錄大綱

What’s in This Book
How to Use This Book
About Example Code
Go Modules
Online Resources
Your First Command Line Program in Go excerpt
Building the Basic Word Counter
Testing the Basic Word Counter
Adding Command Line Flags
Compiling your Tool for Different Platforms
Exercises

Interacting with Your Users
Organizing your Code
Defining the To-Do API
Creating the Initial To-Do Command Line Tool
Testing the Initial CLI Implementation
Handling Multiple Command Line Options
Display Command Line Tool Usage
Improving the List Output Format
Increasing Flexibility with Environment Variables
Capturing Input from STDIN
Exercises

Working with Files in Go
Creating a Basic Markdown Preview Tool
Writing Tests for the Markdown Preview Tool
Adding Temporary Files to the Markdown Preview Tool
Using Interfaces to Automate Tests
Adding an Auto-Preview Feature
Cleaning Up Temporary Files
Improving the Markdown Preview Tool with Templates
Exercises

Navigating the File System
Developing a File System Crawler
Testing with Table Driven Testing
Deleting Matched Files
Testing with the Help of Test Helpers
Logging Deleted Files
Archiving Files
Exercises

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

Controlling Processes
Executing External Programs
Writing tests for Goci
Defining a Pipeline
Adding Another Step to the Pipeline
Handling Output from External Programs
Running Commands with Contexts
Integration Tests with a Local Git Server
Testing Commands with Mock Resources
Handling Signals
Exercises

Talking to REST APIs
Using the Cobra CLI Framework
Developing Interactive Terminal Tools
Working with Regular Expressions in Go
Distributing Your Tool

目錄大綱(中文翻譯)

What’s in This Book

How to Use This Book

About Example Code

Go Modules

Online Resources

Your First Command Line Program in Go excerpt

Building the Basic Word Counter

Testing the Basic Word Counter

Adding Command Line Flags

Compiling your Tool for Different Platforms

Exercises

Interacting with Your Users

Organizing your Code

Defining the To-Do API

Creating the Initial To-Do Command Line Tool

Testing the Initial CLI Implementation

Handling Multiple Command Line Options

Display Command Line Tool Usage

Improving the List Output Format

Increasing Flexibility with Environment Variables

Capturing Input from STDIN

Exercises

Working with Files in Go

Creating a Basic Markdown Preview Tool

Writing Tests for the Markdown Preview Tool

Adding Temporary Files to the Markdown Preview Tool

Using Interfaces to Automate Tests

Adding an Auto-Preview Feature

Cleaning Up Temporary Files

Improving the Markdown Preview Tool with Templates

Exercises

Navigating the File System

Developing a File System Crawler

Testing with Table Driven Testing

Deleting Matched Files

Testing with the Help of Test Helpers

Logging Deleted Files

Archiving Files

Exercises

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

Controlling Processes

Executing External Programs

Writing tests for Goci

Defining a Pipeline

Adding Another Step to the Pipeline

Handling Output from External Programs

Running Commands with Contexts

Integration Tests with a Local Git Server

Testing Commands with Mock Resources

Handling Signals

Exercises

Talking to REST APIs

Using the Cobra CLI Framework

Developing Interactive Terminal Tools

Working with Regular Expressions in Go

Distributing Your Tool