
CLI Development
CLI design, flag package, cobra/viper, structuring CLI apps, exit codes, stdin/stdout/stderr, UX patterns, testing CLI apps
1What is the main role of the flag package in Go?
What is the main role of the flag package in Go?
คำตอบ
The flag package provides a simple API for parsing command-line arguments. It allows defining flags with predefined types (string, int, bool, etc.) and automatically handles parsing and validation. This package is part of the standard library and is suitable for simple CLIs.
2How to define a string flag with the flag package and retrieve its value?
How to define a string flag with the flag package and retrieve its value?
คำตอบ
The flag.String function returns a pointer to the flag value. After calling flag.Parse(), the value can be accessed by dereferencing the pointer. It's also possible to use flag.StringVar to bind directly to an existing variable.
3What is the difference between flag.String and flag.StringVar?
What is the difference between flag.String and flag.StringVar?
คำตอบ
flag.String allocates a new variable and returns a pointer to it, while flag.StringVar binds the flag to an existing variable passed by address. StringVar is useful when the variable needs to be defined at package level or when you want to avoid dereferencing.
What exit code should be used when a CLI application encounters an invalid arguments error?
What is the main advantage of Cobra over the standard flag package?
+17 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Go อื่นๆ
Go Basics
Go Data Structures
Go Interfaces
Error Handling
Goroutines Basics
Channels
Go Modules
HTTP Server
HTTP Client
JSON Encoding
database/sql
Context Package
Testing
Concurrency Patterns
Sync Primitives
Go Web Frameworks
REST API Design
gRPC
Reflection
Memory Management
Performance Optimization
Generics
Go Design Patterns
Microservices
Security & Authentication
Docker & Containerization
Kubernetes Basics
Advanced Go
เชี่ยวชาญ Go สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี