{"id":171,"date":"2026-07-07T20:29:54","date_gmt":"2026-07-07T20:29:54","guid":{"rendered":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/"},"modified":"2026-07-07T20:38:20","modified_gmt":"2026-07-07T20:38:20","slug":"08-go-structs-and-methods","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","title":{"rendered":"Go Structs and Methods \u2013 Organizing Data and Behavior"},"content":{"rendered":"<p><!-- ktg-updated-banner --><\/p>\n<div class=\"ktg-updated-banner\" style=\"margin:0 0 1.25em;padding:0.75em 1em;background:#fefce8;border-left:4px solid #ca8a04;border-radius:4px;\">\n<p><strong>Updated July 2, 2026.<\/strong> Refreshed for Go 1.22+ and current SEO best practices.<\/p>\n<\/div>\n<p>In this lesson we cover <strong>Go structs and methods<\/strong> \u2014 the primary way to model real-world entities in Go. If you completed <a href=\"https:\/\/www.kindsonthegenius.com\/go\/07-go-arrays-slices-maps\/\">Go Arrays, Slices, and Maps<\/a>, you know how to store collections. Now you will learn how to group related fields into a single type and attach functions to that type. This <strong>Go structs tutorial<\/strong> builds the foundation for interfaces, error handling, and the REST API you will build in Lesson 12.<\/p>\n<p><strong>Prerequisites:<\/strong> Lessons 1\u20137 completed, Go 1.22 or newer installed. <strong>Estimated time:<\/strong> 45\u201360 minutes.<\/p>\n<h4 id=\"struct-definition\">1. Defining a Struct<\/h4>\n<p>A <strong>struct<\/strong> is a composite type that groups named fields together. Each field has a name and a type. Structs are Go&#8217;s answer to objects in other languages \u2014 but without class inheritance. You define a struct with the <code>type<\/code> keyword:<\/p>\n<pre><code class=\"language-go\">package main\n\nimport \"fmt\"\n\n\/\/ Person is a struct with three fields\ntype Person struct {\n\tName string\n\tAge  int\n\tCity string\n}\n\nfunc main() {\n\tvar p Person\n\tfmt.Println(p) \/\/ { 0 } \u2014 zero value: empty string, 0 for int\n\n\tp.Name = \"Ada\"\n\tp.Age = 28\n\tp.City = \"Lagos\"\n\tfmt.Println(p.Name, p.Age, p.City)\n}\n<\/code><\/pre>\n<p>Field names that start with an uppercase letter are <strong>exported<\/strong> (visible outside the package). Lowercase field names are private to the package \u2014 the same export rule you learned for identifiers in the Basic Syntax lesson.<\/p>\n<h4 id=\"struct-literals\">2. Struct Literals<\/h4>\n<p>Create struct values with literals. You can list fields in order (positional) or by name (recommended for clarity):<\/p>\n<pre><code class=\"language-go\">package main\n\nimport \"fmt\"\n\ntype Book struct {\n\tTitle  string\n\tAuthor string\n\tPages  int\n}\n\nfunc main() {\n\t\/\/ Named field literal (preferred)\n\tb1 := Book{\n\t\tTitle:  \"The Go Programming Language\",\n\t\tAuthor: \"Donovan & Kernighan\",\n\t\tPages:  380,\n\t}\n\n\t\/\/ Positional literal \u2014 must supply all fields in order\n\tb2 := Book{\"Learning Go\", \"Jon Bodner\", 350}\n\n\t\/\/ Pointer to a struct with &\n\tb3 := &Book{Title: \"Concurrency in Go\", Author: \"Katherine Cox-Buday\", Pages: 300}\n\n\tfmt.Println(b1.Title)\n\tfmt.Println(b2.Author)\n\tfmt.Println(b3.Pages)\n}\n<\/code><\/pre>\n<p>Named field literals are safer \u2014 they survive field reordering and make code self-documenting. Use <code>&amp;Type{...}<\/code> when you need a pointer to a struct, which is common when passing structs to functions that should modify them.<\/p>\n<h4 id=\"methods\">3. Methods \u2014 Functions with a Receiver<\/h4>\n<p>A <strong>method<\/strong> is a function with a <em>receiver<\/em> \u2014 a special parameter that binds the function to a type. Methods let you write <code>p.Greet()<\/code> instead of <code>Greet(p)<\/code>, which reads more naturally for types that represent entities.<\/p>\n<pre><code class=\"language-go\">package main\n\nimport \"fmt\"\n\ntype Rectangle struct {\n\tWidth  float64\n\tHeight float64\n}\n\n\/\/ Area is a method with a value receiver\nfunc (r Rectangle) Area() float64 {\n\treturn r.Width * r.Height\n}\n\n\/\/ Scale is a method with a pointer receiver\nfunc (r *Rectangle) Scale(factor float64) {\n\tr.Width *= factor\n\tr.Height *= factor\n}\n\nfunc main() {\n\trect := Rectangle{Width: 10, Height: 5}\n\tfmt.Println(\"Area:\", rect.Area()) \/\/ 50\n\n\trect.Scale(2)\n\tfmt.Println(\"Scaled area:\", rect.Area()) \/\/ 200\n}\n<\/code><\/pre>\n<p>The receiver appears between <code>func<\/code> and the method name. It looks like an extra parameter, but it is not part of the call \u2014 <code>rect.Area()<\/code> passes <code>rect<\/code> implicitly as the receiver.<\/p>\n<h4 id=\"value-vs-pointer\">4. Value Receivers vs Pointer Receivers<\/h4>\n<p>Choosing between a value receiver <code>(r Rectangle)<\/code> and a pointer receiver <code>(r *Rectangle)<\/code> is one of the most important decisions in Go struct design:<\/p>\n<ul>\n<li><strong>Value receiver<\/strong> \u2014 receives a <em>copy<\/em> of the struct. Methods cannot modify the original. Good for small structs and read-only operations.<\/li>\n<li><strong>Pointer receiver<\/strong> \u2014 receives a pointer to the struct. Methods can modify the original. Good for large structs (avoids copying) and mutating operations.<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>Aspect<\/th>\n<th>Value Receiver<\/th>\n<th>Pointer Receiver<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Syntax<\/td>\n<td><code>func (r Rect) M()<\/code><\/td>\n<td><code>func (r *Rect) M()<\/code><\/td>\n<\/tr>\n<tr>\n<td>Can modify struct?<\/td>\n<td>No (works on a copy)<\/td>\n<td>Yes (modifies original)<\/td>\n<\/tr>\n<tr>\n<td>Memory<\/td>\n<td>Copies entire struct each call<\/td>\n<td>Copies only a pointer (8 bytes)<\/td>\n<\/tr>\n<tr>\n<td>Nil receiver<\/td>\n<td>Not applicable<\/td>\n<td>Can panic if receiver is nil<\/td>\n<\/tr>\n<tr>\n<td>Best for<\/td>\n<td>Small structs, getters, String()<\/td>\n<td>Mutators, large structs, consistency<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Consistency rule:<\/strong> If any method on a type uses a pointer receiver, use pointer receivers for <em>all<\/em> methods on that type. This avoids confusion about whether a method mutates the struct or not.<\/p>\n<pre><code class=\"language-go\">package main\n\nimport \"fmt\"\n\ntype Counter struct {\n\tCount int\n}\n\n\/\/ Pointer receiver \u2014 modifies the original\nfunc (c *Counter) Increment() {\n\tc.Count++\n}\n\n\/\/ Pointer receiver for consistency, even though it only reads\nfunc (c *Counter) String() string {\n\treturn fmt.Sprintf(\"Count: %d\", c.Count)\n}\n\nfunc main() {\n\tc := Counter{}\n\tc.Increment()\n\tc.Increment()\n\tfmt.Println(c) \/\/ Count: 2\n}\n<\/code><\/pre>\n<h4 id=\"embedding\">5. Struct Embedding \u2014 Composition Over Inheritance<\/h4>\n<p>Go does not have class inheritance. Instead, it uses <strong>embedding<\/strong> \u2014 placing one struct type inside another anonymously. The embedded struct&#8217;s fields and methods are <em>promoted<\/em> to the outer type, so you can access them directly.<\/p>\n<pre><code class=\"language-go\">package main\n\nimport \"fmt\"\n\ntype Address struct {\n\tStreet string\n\tCity   string\n}\n\nfunc (a Address) FullAddress() string {\n\treturn a.Street + \", \" + a.City\n}\n\ntype Employee struct {\n\tName    string\n\tAddress \/\/ embedded \u2014 fields promoted to Employee\n\tSalary  float64\n}\n\nfunc main() {\n\temp := Employee{\n\t\tName: \"Chidi\",\n\t\tAddress: Address{\n\t\t\tStreet: \"12 Broad Street\",\n\t\t\tCity:   \"Lagos\",\n\t\t},\n\t\tSalary: 75000,\n\t}\n\n\t\/\/ Promoted fields \u2014 no need for emp.Address.City\n\tfmt.Println(emp.City)\n\tfmt.Println(emp.FullAddress()) \/\/ promoted method\n}\n<\/code><\/pre>\n<p>Embedding is how Go achieves code reuse without inheritance hierarchies. A type can embed multiple structs. If two embedded types have a field with the same name, you must qualify the access: <code>emp.Address.City<\/code>.<\/p>\n<p>Embedding also works with interfaces \u2014 a struct that embeds an interface must satisfy that interface at runtime. You will explore this pattern in the Interfaces lesson.<\/p>\n<h4 id=\"practical-example\">6. Putting It Together \u2014 A Simple Bank Account<\/h4>\n<p>Here is a practical example that combines struct definition, literals, methods, and pointer receivers:<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n)\n\ntype Account struct {\n\tOwner   string\n\tBalance float64\n}\n\nfunc NewAccount(owner string) *Account {\n\treturn &Account{Owner: owner, Balance: 0}\n}\n\nfunc (a *Account) Deposit(amount float64) error {\n\tif amount <= 0 {\n\t\treturn fmt.Errorf(\"deposit amount must be positive\")\n\t}\n\ta.Balance += amount\n\treturn nil\n}\n\nfunc (a *Account) Withdraw(amount float64) error {\n\tif amount <= 0 {\n\t\treturn fmt.Errorf(\"withdrawal amount must be positive\")\n\t}\n\tif amount > a.Balance {\n\t\treturn fmt.Errorf(\"insufficient funds\")\n\t}\n\ta.Balance -= amount\n\treturn nil\n}\n\nfunc (a *Account) String() string {\n\treturn fmt.Sprintf(\"%s: $%.2f\", a.Owner, a.Balance)\n}\n\nfunc main() {\n\tacct := NewAccount(\"Ngozi\")\n\tif err := acct.Deposit(500); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tif err := acct.Withdraw(150); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(acct) \/\/ Ngozi: $350.00\n}\n<\/code><\/pre>\n<p>Notice the constructor pattern <code>NewAccount<\/code> \u2014 a common Go idiom that returns a pointer to a newly initialized struct. Error returns on <code>Deposit<\/code> and <code>Withdraw<\/code> preview the error-handling style you will master in Lesson 10.<\/p>\n<h4 id=\"next\">7. Next Steps<\/h4>\n<p>You now understand <strong>Go structs and methods<\/strong> \u2014 defining types, creating literals, writing methods with value and pointer receivers, and composing types through embedding. In the next lesson we dive deeper into <strong>pointers<\/strong> \u2014 when to use them, how they interact with structs, and common patterns you will see in production Go code.<\/p>\n<p>Continue the series: <a href=\"https:\/\/www.kindsonthegenius.com\/go\/07-go-arrays-slices-maps\/\">Lesson 7 \u2013 Arrays, Slices, and Maps<\/a> \u00b7 <a href=\"https:\/\/www.kindsonthegenius.com\/go\/09-go-pointers\/\">Lesson 9 \u2013 Pointers<\/a><\/p>\n<h4 id=\"faq\">Frequently Asked Questions<\/h4>\n<p><strong>What is a struct in Go?<\/strong><br \/>\nA struct groups related fields into a single type \u2014 Go&#8217;s primary way to model data. Structs do not have inheritance; use embedding for composition.<\/p>\n<p><strong>What is the difference between value and pointer receivers?<\/strong><br \/>\nPointer receivers can modify the struct and avoid copying large values. Value receivers copy the struct and cannot change the original. Use pointer receivers when methods mutate state or for consistency across all methods on a type.<\/p>\n<p><strong>What is struct embedding in Go?<\/strong><br \/>\nEmbedding one struct inside another anonymously promotes its fields and methods to the outer type \u2014 Go&#8217;s composition pattern instead of class inheritance.<\/p>\n<p><!-- ktg-lesson-nav --><\/p>\n<nav class=\"ktg-lesson-nav\" aria-label=\"Lesson navigation\">\n<p><strong>Previous:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/07-go-arrays-slices-maps\/\">Lesson 7: Go Arrays, Slices, and Maps \u2013 Working with Collections<\/a><\/p>\n<p><strong>Next:<\/strong> <a href=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/09-go-pointers\/\">Lesson 9: Go Pointers \u2013 Addresses, Dereferencing, and When to Use Them<\/a><\/p>\n<\/nav>\n<p><!-- ktg-alkademy-cta --><\/p>\n<div class=\"ktg-alkademy-cta\" style=\"margin:2em 0;padding:1.25em;border-left:4px solid #2563eb;background:#f8fafc;\">\n<p><strong>Want live Go or backend classes?<\/strong> Join <a href=\"https:\/\/www.alkademy.com\/courses\" target=\"_blank\" rel=\"noopener noreferrer\">Alkademy<\/a> for instructor-led programming courses with hands-on projects.<\/p>\n<\/div>\n<p><!-- ktg-faq-schema --><br \/>\n<script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What is a struct in Go?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"A struct groups related fields into a single type \\u2014 Go's primary way to model data.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between value and pointer receivers?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Pointer receivers can modify the struct and avoid copying large values. Value receivers copy the struct.\"}},{\"@type\":\"Question\",\"name\":\"What is struct embedding in Go?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Embedding one struct inside another promotes its fields and methods to the outer type.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[23],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-go-programming"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"kindsonthegenius\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Go Programming Tutorial - Beginner to Expert Go Programming Tutorial\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial\" \/>\n\t\t<meta property=\"og:description\" content=\"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-07T20:29:54+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-07T20:38:20+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#blogposting\",\"name\":\"Go Structs and Methods \\u2013 Organizing Data and Behavior - Go Programming Tutorial\",\"headline\":\"Go Structs and Methods \\u2013 Organizing Data and Behavior\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#organization\"},\"datePublished\":\"2026-07-07T20:29:54+00:00\",\"dateModified\":\"2026-07-07T20:38:20+00:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#webpage\"},\"articleSection\":\"Go Programming\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/category\\\/go-programming\\\/#listItem\",\"name\":\"Go Programming\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/category\\\/go-programming\\\/#listItem\",\"position\":2,\"name\":\"Go Programming\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/category\\\/go-programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#listItem\",\"name\":\"Go Structs and Methods \\u2013 Organizing Data and Behavior\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#listItem\",\"position\":3,\"name\":\"Go Structs and Methods \\u2013 Organizing Data and Behavior\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/category\\\/go-programming\\\/#listItem\",\"name\":\"Go Programming\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#organization\",\"name\":\"Go Programming Tutorial\",\"description\":\"Beginner to Expert Go Programming Tutorial\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/#author\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"kindsonthegenius\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#webpage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\",\"name\":\"Go Structs and Methods \\u2013 Organizing Data and Behavior - Go Programming Tutorial\",\"description\":\"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \\u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/#author\"},\"datePublished\":\"2026-07-07T20:29:54+00:00\",\"dateModified\":\"2026-07-07T20:38:20+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#website\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/\",\"name\":\"Go Programming Tutorial\",\"description\":\"Beginner to Expert Go Programming Tutorial\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial","description":"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields","canonical_url":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#blogposting","name":"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial","headline":"Go Structs and Methods \u2013 Organizing Data and Behavior","author":{"@id":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/#author"},"publisher":{"@id":"https:\/\/kindsonthegenius.com\/go\/#organization"},"datePublished":"2026-07-07T20:29:54+00:00","dateModified":"2026-07-07T20:38:20+00:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#webpage"},"isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#webpage"},"articleSection":"Go Programming"},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go#listItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/go","nextItem":{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/#listItem","name":"Go Programming"}},{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/#listItem","position":2,"name":"Go Programming","item":"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#listItem","name":"Go Structs and Methods \u2013 Organizing Data and Behavior"},"previousItem":{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#listItem","position":3,"name":"Go Structs and Methods \u2013 Organizing Data and Behavior","previousItem":{"@type":"ListItem","@id":"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/#listItem","name":"Go Programming"}}]},{"@type":"Organization","@id":"https:\/\/kindsonthegenius.com\/go\/#organization","name":"Go Programming Tutorial","description":"Beginner to Expert Go Programming Tutorial","url":"https:\/\/kindsonthegenius.com\/go\/"},{"@type":"Person","@id":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/#author","url":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/","name":"kindsonthegenius","image":{"@type":"ImageObject","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","width":96,"height":96,"caption":"kindsonthegenius"}},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#webpage","url":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","name":"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial","description":"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/go\/#website"},"breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#breadcrumblist"},"author":{"@id":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/#author"},"creator":{"@id":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/#author"},"datePublished":"2026-07-07T20:29:54+00:00","dateModified":"2026-07-07T20:38:20+00:00"},{"@type":"WebSite","@id":"https:\/\/kindsonthegenius.com\/go\/#website","url":"https:\/\/kindsonthegenius.com\/go\/","name":"Go Programming Tutorial","description":"Beginner to Expert Go Programming Tutorial","inLanguage":"en-US","publisher":{"@id":"https:\/\/kindsonthegenius.com\/go\/#organization"}}]},"og:locale":"en_US","og:site_name":"Go Programming Tutorial - Beginner to Expert Go Programming Tutorial","og:type":"article","og:title":"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial","og:description":"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields","og:url":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","article:published_time":"2026-07-07T20:29:54+00:00","article:modified_time":"2026-07-07T20:38:20+00:00","twitter:card":"summary_large_image","twitter:title":"Go Structs and Methods \u2013 Organizing Data and Behavior - Go Programming Tutorial","twitter:description":"Updated July 2, 2026. Refreshed for Go 1.22+ and current SEO best practices. In this lesson we cover Go structs and methods \u2014 the primary way to model real-world entities in Go. If you completed Go Arrays, Slices, and Maps, you know how to store collections. Now you will learn how to group related fields"},"aioseo_meta_data":[],"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/kindsonthegenius.com\/go\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/\" title=\"Go Programming\">Go Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGo Structs and Methods \u2013 Organizing Data and Behavior\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/kindsonthegenius.com\/go"},{"label":"Go Programming","link":"https:\/\/kindsonthegenius.com\/go\/category\/go-programming\/"},{"label":"Go Structs and Methods \u2013 Organizing Data and Behavior","link":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/"}],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial<\/title>\n<meta name=\"description\" content=\"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial\" \/>\n<meta property=\"og:description\" content=\"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"Go Programming Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-07T20:29:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-07T20:38:20+00:00\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#\\\/schema\\\/person\\\/1b5971e6d80495780d9857f155fd1b21\"},\"headline\":\"Go Structs and Methods \u2013 Organizing Data and Behavior\",\"datePublished\":\"2026-07-07T20:29:54+00:00\",\"dateModified\":\"2026-07-07T20:38:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\"},\"wordCount\":802,\"commentCount\":1,\"articleSection\":[\"Go Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\",\"name\":\"Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#website\"},\"datePublished\":\"2026-07-07T20:29:54+00:00\",\"dateModified\":\"2026-07-07T20:38:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#\\\/schema\\\/person\\\/1b5971e6d80495780d9857f155fd1b21\"},\"description\":\"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/2026\\\/07\\\/07\\\/08-go-structs-and-methods\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Structs and Methods \u2013 Organizing Data and Behavior\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#website\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/\",\"name\":\"Go Programming Tutorial\",\"description\":\"Beginner to Expert Go Programming Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/#\\\/schema\\\/person\\\/1b5971e6d80495780d9857f155fd1b21\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/go\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial","description":"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","og_locale":"en_US","og_type":"article","og_title":"Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial","og_description":"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.","og_url":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","og_site_name":"Go Programming Tutorial","article_published_time":"2026-07-07T20:29:54+00:00","article_modified_time":"2026-07-07T20:38:20+00:00","author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#article","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/kindsonthegenius.com\/go\/#\/schema\/person\/1b5971e6d80495780d9857f155fd1b21"},"headline":"Go Structs and Methods \u2013 Organizing Data and Behavior","datePublished":"2026-07-07T20:29:54+00:00","dateModified":"2026-07-07T20:38:20+00:00","mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/"},"wordCount":802,"commentCount":1,"articleSection":["Go Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","url":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/","name":"Go Structs and Methods \u2013 Organizing Data and Behavior | Go Programming Tutorial","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/go\/#website"},"datePublished":"2026-07-07T20:29:54+00:00","dateModified":"2026-07-07T20:38:20+00:00","author":{"@id":"https:\/\/kindsonthegenius.com\/go\/#\/schema\/person\/1b5971e6d80495780d9857f155fd1b21"},"description":"Learn Go structs, methods, and embedding for organizing data and behavior. Lesson 8 in the free Go programming tutorial with practical examples.","breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/go\/2026\/07\/07\/08-go-structs-and-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/go\/"},{"@type":"ListItem","position":2,"name":"Go Structs and Methods \u2013 Organizing Data and Behavior"}]},{"@type":"WebSite","@id":"https:\/\/kindsonthegenius.com\/go\/#website","url":"https:\/\/kindsonthegenius.com\/go\/","name":"Go Programming Tutorial","description":"Beginner to Expert Go Programming Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kindsonthegenius.com\/go\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kindsonthegenius.com\/go\/#\/schema\/person\/1b5971e6d80495780d9857f155fd1b21","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/kindsonthegenius.com\/go\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/171\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/go\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}