- เรียก API https://jsonplaceholder.typicode.com/posts ได้ array ของ JSON ประมาณนี้
[
{
"userId": 1,| เขียนโปรแกรม 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 |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>Camera</title> | |
| </head> | |
| <body> | |
| <video id="camera" autoplay playsinline></video> | |
| <script> | |
| const videoElement = document.getElementById("camera"); |