[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-th-1-1-all-go-structs-methods-design-flexible-data-all--*":3,"academy-blog-translations-ta8a2z13kjwnvbf":79},{"data":4,"page":67,"perPage":67,"totalItems":67,"totalPages":67},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":73,"keywords":74,"locale":49,"published_at":75,"scheduled_at":13,"school_blog":71,"short_description":76,"slug":77,"status":69,"title":6,"updated":78,"updated_by":13,"views":72},"EP.7 Go กับ Structs & Methods - ออกแบบข้อมูลให้ยืดหยุ่น!","sclblg987654321","school_blog_translations","\u003Cp>\u003Cspan style=\"font-size:20px;\">\u003Cstrong>Go กับ Structs &amp; Methods - ออกแบบข้อมูลให้ยืดหยุ่น!\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>การจัดการข้อมูลอย่างเป็นระบบคือหัวใจของโปรแกรมที่ดี และในภาษา Go เราทำได้ง่ายๆ ด้วย Structs ที่รวมกลุ่มตัวแปรต่างๆ ไว้ด้วยกัน พร้อมกับ Methods ที่ช่วยให้จัดการข้อมูลได้อย่างมีประสิทธิภาพ&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Struct คืออะไร?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Struct (Structure) ใน Go คือการรวมกลุ่มของตัวแปรที่เกี่ยวข้องเข้าด้วยกัน เช่น ชื่อ อายุ ที่อยู่ ช่วยให้จัดการข้อมูลได้ง่ายและเป็นระบบ\u003Cbr>ตัวอย่าง Struct:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\r\n\r\nimport \"fmt\"\r\n\r\ntype Person struct {\r\n    name string\r\n    age  int\r\n}\r\n\r\nfunc main() {\r\n    p := Person{name: \"Alice\", age: 25}\r\n    fmt.Println(p.name, \"is\", p.age, \"years old.\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>การใช้ Methods กับ Structs\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Methods เป็นฟังก์ชันที่เชื่อมกับ Struct ช่วยให้เราจัดการข้อมูลใน Struct ได้อย่างยืดหยุ่น\u003Cbr>ตัวอย่าง Method:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">type Person struct {\r\n    name string\r\n    age  int\r\n}\r\n\r\nfunc (p Person) greet() {\r\n    fmt.Printf(\"Hello, my name is %s.\\n\", p.name)\r\n}\r\n\r\nfunc main() {\r\n    p := Person{name: \"Bob\", age: 30}\r\n    p.greet() \u002F\u002F Output: Hello, my name is Bob.\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Pointer กับ Structs\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>ใช้ Pointer ร่วมกับ Struct เพื่ออัปเดตค่าของตัวแปรภายใน Struct\u003Cbr>ตัวอย่าง:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func (p *Person) setAge(newAge int) {\r\n    p.age = newAge\r\n}\r\n\r\nfunc main() {\r\n    p := Person{name: \"Alice\", age: 25}\r\n    p.setAge(26)\r\n    fmt.Println(p.name, \"is now\", p.age, \"years old.\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Struct ภายใน Struct (Nested Structs)\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>Struct หนึ่งสามารถมี Struct อื่นเป็นสมาชิกได้ ทำให้รองรับโครงสร้างข้อมูลที่ซับซ้อนมากขึ้น\u003Cbr>ตัวอย่าง Nested Struct:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">type Address struct {\r\n    city  string\r\n    state string\r\n}\r\n\r\ntype Person struct {\r\n    name    string\r\n    address Address\r\n}\r\n\r\nfunc main() {\r\n    p := Person{name: \"John\", address: Address{city: \"Bangkok\", state: \"Thailand\"}}\r\n    fmt.Println(p.name, \"lives in\", p.address.city)\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>","using_structs_and_methods_in_go_to_design_flexible_data_1f3qyd1s74.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002F2gi2u7ozilz3ea2\u002Fusing_structs_and_methods_in_go_to_design_flexible_data_1f3qyd1s74.webp","2026-03-04 08:34:19.534Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"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:34:16.794Z","q4turzw9zznten4","ออกแบบข้อมูล","2026-04-10 16:08:11.119Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:26:32.195Z","3lpkahsesypeohl","Pointers","2026-04-10 16:07:30.526Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:34:17.458Z","o0vm8zlzfdrjj78","Methods","2026-04-10 16:08:11.413Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:34:18.324Z","6xpqs57vsfjrf4z","Structs","2026-04-10 16:08:11.729Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"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":54,"collectionId":55,"collectionName":56,"expand":57,"id":71,"views":72},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"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":66,"th":66},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","ta8a2z13kjwnvbf",444,"2gi2u7ozilz3ea2",[20,25,30,35,40],"2025-01-22 05:01:54.534Z","เรียนรู้การสร้าง Structs ใน Go การเพิ่ม Methods และการใช้งาน Pointer เพื่อจัดการข้อมูลอย่างมีประสิทธิภาพ","go-structs-methods-design-flexible-data","2026-04-25 02:47:31.007Z",{"th":77}]