[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-th-1-1-all-functions-in-go-pro-code-all--*":3,"academy-blog-translations-8id2fc9dco1j72u":74},{"data":4,"page":62,"perPage":62,"totalItems":62,"totalPages":62},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":68,"keywords":69,"locale":44,"published_at":70,"scheduled_at":13,"school_blog":66,"short_description":71,"slug":72,"status":64,"title":6,"updated":73,"updated_by":13,"views":67},"EP.5 Functions in Go: เขียนโค้ดแบบมือโปรด้วยฟังก์ชัน","sclblg987654321","school_blog_translations","\u003Cp>\u003Cspan style=\"font-size:20px;\">\u003Cstrong>Functions in Go: เขียนโค้ดแบบมือโปรด้วยฟังก์ชัน\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>คุณรู้ไหม? ฟังก์ชันช่วยให้โค้ดของคุณสั้นลงและง่ายต่อการดูแล วันนี้เราจะมาดูกันว่า Go ทำให้การสร้างฟังก์ชันเป็นเรื่องง่ายแค่ไหน!\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>ฟังก์ชันคืออะไร?\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>ฟังก์ชัน (Function) คือชุดคำสั่งที่เราสามารถเรียกใช้งานซ้ำได้ ทำให้โค้ดของคุณสะอาด อ่านง่าย และดูแลรักษาได้ง่ายขึ้น\u003Cbr>ตัวอย่างฟังก์ชันง่ายๆ:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc greet(name string) {\r\n    fmt.Println(\"Hello,\", name)\r\n}\r\n\r\nfunc main() {\r\n    greet(\"Alice\")\r\n    greet(\"Bob\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>สร้างฟังก์ชันใน Go\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>ใน Go ฟังก์ชันประกอบด้วยชื่อฟังก์ชัน, พารามิเตอร์ (ถ้ามี), และผลลัพธ์ (ถ้ามี)\u003Cbr>ตัวอย่างฟังก์ชันที่มีการคืนค่า (Return Value):\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func add(a int, b int) int {\r\n    return a + b\r\n}\r\n\r\nfunc main() {\r\n    result := add(3, 4)\r\n    fmt.Println(\"Result:\", result)\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>พารามิเตอร์หลายตัวและผลลัพธ์หลายค่า\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>Go สามารถส่งค่ากลับได้หลายค่า:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func swap(x, y int) (int, int) {\r\n    return y, x\r\n}\r\n\r\nfunc main() {\r\n    a, b := swap(1, 2)\r\n    fmt.Println(a, b) \u002F\u002F Output: 2 1\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>ฟังก์ชันไร้พารามิเตอร์และผลลัพธ์\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>บางฟังก์ชันไม่จำเป็นต้องรับค่าใดๆ และไม่ต้องคืนค่า เช่น:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func sayHello() {\r\n    fmt.Println(\"Hello, World!\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>","9_11zon_oedolz94az.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fref3ytohopj23ro\u002F9_11zon_oedolz94az.webp","2026-03-04 08:34:24.233Z","",{"keywords":15,"locale":38,"school_blog":48},[16,23,28,33],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:33:59.518Z","7pqn3y8ffwzzde5","ภาษา Go","2026-04-10 16:08:04.777Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:34:22.524Z","qgrtnu2s485m6tv","ส่งค่ากลับหลายค่า","2026-04-10 16:08:13.239Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:34:00.113Z","8f9k1pkreklpbr4","การเขียนโค้ด Go","2026-04-10 16:08:05.021Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:34:23.794Z","oo2kb88aq6wzi90","ฟังก์ชันใน Go","2026-04-10 16:08:13.705Z",{"code":39,"collectionId":40,"collectionName":41,"created":42,"flag":43,"id":44,"is_default":45,"label":46,"updated":47},"th","pbc_1989393366","locales","2026-01-22 10:59:55.832Z","twemoji:flag-thailand","s8wri3bt4vgg2ji",true,"Thai","2026-04-10 15:42:46.614Z",{"category":49,"collectionId":50,"collectionName":51,"expand":52,"id":66,"views":67},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":53},{"blogIds":54,"collectionId":55,"collectionName":56,"created":57,"created_by":13,"id":49,"image":58,"image_alt":13,"image_path":59,"label":60,"name":61,"priority":62,"publish_at":63,"scheduled_at":13,"status":64,"updated":65,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":61,"th":61},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","8id2fc9dco1j72u",406,"ref3ytohopj23ro",[20,25,30,35],"2025-01-22 05:01:18.354Z","เรียนรู้การสร้างฟังก์ชันในภาษา Go การส่งค่ากลับหลายค่า และเคล็ดลับในการเขียนโค้ดที่มีประสิทธิภาพ","functions-in-go-pro-code","2026-04-25 02:47:32.052Z",{"th":72}]