Powerful Command-Line Applications in Go: Build Fast and Maintainable Tools
Gerardi, Ricardo
- 出版商: Pragmatic Bookshelf
- 出版日期: 2022-01-11
- 定價: $1,600
- 售價: 9.5 折 $1,520
- 語言: 英文
- 頁數: 250
- 裝訂: Paperback
- ISBN: 168050696X
- ISBN-13: 9781680506969
-
相關分類:
Command Line、Go 程式語言
立即出貨 (庫存 < 3)
買這商品的人也買了...
-
$2,100$1,995 -
$954$906 -
$780$663 -
$1,400Network Programming with Go: Learn to Code Secure and Reliable Network Services from Scratch
-
$620$465 -
$450$338 -
$580$458 -
$2,050$1,948 -
$2,200$2,090 -
$2,240Dive Into Systems: A Gentle Introduction to Computer Systems (Paperback)
-
$560$420 -
$780$616 -
$800$632 -
$720$360 -
$650$455 -
$600$468 -
$1,758The Rust Programming Language, 2/e (Paperback)
-
$620$310 -
$680$537 -
$580$458 -
$780$585 -
$790$616 -
$980$774 -
$680$476 -
$620$465
相關主題
商品描述
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的集成測試功能自動測試您的工具,確保它們即使在代碼重構時也能可靠運行。
通過使用常見的輸入/輸出模式(包括環境變量和標誌)來開發與用戶交互的命令行工具。處理文件以讀取或保存數據,在跨平台場景中一致地操作路徑。控制進程並處理信號,使用基於基準的方法和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
目錄大綱(中文翻譯)
本書內容包括:
- 本書內容介紹
- 如何使用本書
- 關於範例程式碼
- Go 模組
- 線上資源
- 在 Go 中建立第一個命令列程式
- 建立基本的字數統計程式
- 測試基本的字數統計程式
- 添加命令列旗標
- 編譯工具以適應不同平台
- 練習題
與使用者互動:
- 組織程式碼
- 定義待辦事項 API
- 建立初始的待辦事項命令列工具
- 測試初始的命令列工具實作
- 處理多個命令列選項
- 顯示命令列工具使用方式
- 改進清單輸出格式
- 使用環境變數增加彈性
- 從 STDIN 捕獲輸入
- 練習題
處理檔案:
- 在 Go 中建立基本的 Markdown 預覽工具
- 為 Markdown 預覽工具撰寫測試
- 將臨時檔案加入 Markdown 預覽工具
- 使用介面自動化測試
- 添加自動預覽功能
- 清理臨時檔案
- 使用模板改進 Markdown 預覽工具
- 練習題
導覽檔案系統:
- 開發檔案系統爬蟲
- 使用表驅動測試進行測試
- 刪除符合條件的檔案
- 使用測試輔助工具進行測試
- 記錄已刪除的檔案
- 封存檔案
- 練習題
提升 CLI 工具效能:
- 開發 colStats 的初始版本
- 為 colStats 撰寫測試
- 執行效能測試
- 執行效能分析
- 減少記憶體配置
- 追蹤工具
- 改進 colStats 工具以並行處理檔案
- 減少排程競爭
- 練習題
控制進程:
- 執行外部程式
- 為 Goci 撰寫測試
- 定義流程
- 添加流程的另一個步驟
- 處理外部程式的輸出
- 使用上下文執行命令
- 使用本地 Git 伺服器進行整合測試
- 使用模擬資源測試命令
- 處理信號
- 練習題
與 REST API 通訊:
- 使用 Cobra CLI 框架
- 開發互動式終端工具
- 在 Go 中使用正則表達式
- 分發你的工具