[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-go-structs-methods-design-flexible-data-all--*":3,"academy-blog-translations-67kqkz2g6x6yu12":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 with Structs - Designing Flexible Data!","sclblg987654321","school_blog_translations","\u003Cp>\u003Cspan style=\"font-size:20px;\">\u003Cstrong>Go with Structs - Designing Flexible Data!\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Systematic data management is the heart of a good program, and in Go, we can easily achieve this with Structs that group related variables together, along with Methods that help us manage data efficiently.\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>What is a Struct?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>A Struct (Structure) in Go is a grouping of related variables, such as name, age, and address, which helps us manage data easily and systematically.\u003Cbr>Example of a 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>Using Methods with Structs\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Methods are functions associated with a Struct that allow us to flexibly manage the data within the Struct.\u003Cbr>Example of a 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>Pointers with Structs\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Using Pointers with Structs allows us to update the values of variables within the Struct.\u003Cbr>Example:\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>Nested Structs\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>One Struct can contain another Struct as a member, enabling more complex data structures.\u003Cbr>Example of a 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_1_r9qfp01rhw.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002F95vfmb1qvz4mue5\u002Fusing_structs_and_methods_in_go_to_design_flexible_data_1_r9qfp01rhw.webp","2026-03-04 08:34:20.077Z","",{"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:15.916Z","ud78nn6j2oqlld1","Data Design","2026-04-10 16:08:10.809Z",{"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},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"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","67kqkz2g6x6yu12",208,"95vfmb1qvz4mue5",[20,25,30,35,40],"2025-01-22 05:01:58.115Z","Learn how to create Structs in Go, add Methods, and use Pointers to manage data efficiently.","go-structs-methods-design-flexible-data","2026-04-25 02:47:31.110Z",{"en":77}]