เขียน struct ชื่อ RateLimiter ที่รองรับ method นี้:
Allow(userID string, now time.Time) boolเงื่อนไข:
ผู้ใช้แต่ละคนสามารถเรียก API ได้ไม่เกิน 3 ครั้ง ภายใน 1 นาที
ถ้ายังไม่เกิน limit ให้ return true
เขียน struct ชื่อ RateLimiter ที่รองรับ method นี้:
Allow(userID string, now time.Time) boolเงื่อนไข:
ผู้ใช้แต่ละคนสามารถเรียก API ได้ไม่เกิน 3 ครั้ง ภายใน 1 นาที
ถ้ายังไม่เกิน limit ให้ return true
| เขียนโปรแกรม 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 | |
| } |
[
{
"userId": 1,| package main | |
| import ( | |
| "encoding/json" | |
| "net/http" | |
| "slices" | |
| "sync" | |
| ) | |
| type TODO struct { |
เป็นเทคนิค ในการ optimize binary ที่ได้จาก compiler แบบใหม่ที่ทำให้ประสิทธิภาพเพิ่มขึ้น 2-7% โดยใช้ข้อมูลพฤติกรรมการใช้งาน ผ่านการทำ profiling แล้วเอาข้อมูลจาก profiling มาประกอบการ compile ในรอบถัดไป
จะใช้ GODEBUG กับ settings เพื่อ turn on / turn off ความสามารถของภาษาที่มีการ breaking change หรือมีพฤติกรรมที่เปลี่ยนไป ทำให้ยังสามารถ compile code ด้วยพฤติกรรมเดิมได้ถ้าต้องการ
| using System; | |
| using System.Text; | |
| using RabbitMQ.Client; | |
| using RabbitMQ.Client.Events; | |
| using System.Threading.Channels; | |
| using System.Threading.Tasks; | |
| namespace Receive | |
| { | |
| class Program |