Advanced Go — ภาพรวม
“ขั้นสูง” ใน Go หมายถึงอะไร
หัวข้อที่มีชื่อว่า ““ขั้นสูง” ใน Go หมายถึงอะไร”ถ้าคุณมาจาก TypeScript คุณคิดเป็น type, จัดการ async flow และ compose พฤติกรรมผ่าน interface เป็นอยู่แล้ว โมดูล Go-101 ปูพื้นฐานไปแล้ว ส่วนโมดูลนี้ครอบคลุมสิ่งที่ยกระดับโค้ดให้พร้อมขึ้น production: อัลกอริทึม generic ที่ type-safe, reflection ที่ runtime สำหรับโค้ดระดับ framework, การเขียน test และ benchmark แบบมีวินัย, การจัดการ module เชิงลึก และ performance profiling
ไม่มีหัวข้อไหนต้องใช้ library พิเศษเลย ทุกอย่างอยู่ใน standard library ของ Go หรือใน toolchain go เอง
แผนที่บทเรียน
หัวข้อที่มีชื่อว่า “แผนที่บทเรียน”| บทเรียน | สิ่งที่จะได้เรียน | เทียบกับ TS |
|---|---|---|
| Generics | Type parameters, constraint interfaces, comparable, เมื่อใดใช้ generics แทน interface | TS generics (เปรียบเทียบเชิงลึก) |
| Reflection | reflect package, struct tags ที่ runtime, รูปแบบที่ปลอดภัย | reflect-metadata / decorators |
| Table-driven tests | testing.T, subtests ด้วย t.Run, ตาราง fixture ร่วมกัน | jest it.each / describe.each |
| Benchmarks | testing.B, go test -bench, intuition การ profiling | benchmark.js, console.time |
| Modules เชิงลึก | Semantic versioning, go.mod/go.sum, replace, vendoring, workspaces | npm + package-lock.json + npm workspaces |
| pprof profiling | CPU/heap profiles, net/http/pprof, อ่าน flame graphs | node --prof, clinic.js |
แนวคิดหลัก
หัวข้อที่มีชื่อว่า “แนวคิดหลัก”toolchain ของ Go ตั้งใจออกแบบมาให้มีทุกอย่างพร้อมในตัว คุณไม่ต้องไปหา benchmark runner ภายนอก, profiler plugin หรือ test framework จากเจ้าอื่น คำสั่ง go test ตัวเดียวรันได้ทั้ง unit test, integration test, benchmark และ fuzz test นี่คือการตัดสินใจออกแบบที่ตั้งใจ: workflow เดียว คำสั่งเดียว ไม่ผูกติดกับ framework ไหน
// TypeScript ต้องใช้เครื่องมือแยกกัน:import { describe, it, expect } from 'vitest';import Benchmark from 'benchmark';import { Profile } from 'clinic';// Go: คำสั่งเดียวจัดการทุกอย่าง// go test ./... — รัน tests// go test -bench=. — รัน benchmarks// go test -fuzz=Fuzz — รัน fuzz tests// go tool pprof cpu.out — เปิด profiler