Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created October 7, 2025 06:30
Show Gist options
  • Save iporsut/545384962ec416028921f48d0d8a4bae to your computer and use it in GitHub Desktop.
Save iporsut/545384962ec416028921f48d0d8a4bae to your computer and use it in GitHub Desktop.
Interview Pair Programming
เขียนโปรแกรม Go ที่เริ่มต้น HTTP Server บนพอร์ต 8080
สร้าง Endpoint ที่ POST /sum
Request Body จะเป็น JSON object ที่มี Field ชื่อ numbers ซึ่งเป็น Array ของจำนวนเต็ม ดังตัวอย่าง:
{
"numbers": [1, 2, 3, 4, 5]
}
Server ควรจะ Parse JSON นี้, คำนวณผลรวมของตัวเลขทั้งหมดใน Array และตอบกลับด้วย JSON object ที่มีผลรวม ดังตัวอย่าง:
{
"sum": 15
}
จัดการกับข้อผิดพลาดพื้นฐานอย่างเหมาะสม (เช่น ถ้า JSON ผิดรูปแบบ หรือ Field numbers หายไป/ไม่ใช่ Array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment