CLI Applications
Go เหมาะมากสำหรับสร้าง CLI tools เพราะ compile เป็น single binary ไม่ต้องมี runtime แถม startup เร็วมาก
รับ Command Line Arguments
Section titled “รับ Command Line Arguments”package main
import ( "fmt" "os")
func main() { // os.Args[0] = ชื่อโปรแกรม // os.Args[1:] = arguments ที่ส่งมา
fmt.Println("Program:", os.Args[0]) fmt.Println("Arguments:", os.Args[1:])
if len(os.Args) < 2 { fmt.Println("Usage: program <name>") os.Exit(1) }
name := os.Args[1] fmt.Println("Hello,", name)}เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google