{"id":9755,"date":"2022-07-28T07:57:37","date_gmt":"2022-07-28T07:57:37","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9755"},"modified":"2023-07-20T04:35:47","modified_gmt":"2023-07-20T04:35:47","slug":"structure-in-golang","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/","title":{"rendered":"Structure in Golang"},"content":{"rendered":"<p style=\"background: white; vertical-align: baseline; margin: 0in 0in 7.5pt 0in;\"><span lang=\"EN-IN\" style=\"font-size: 11.0pt; letter-spacing: .1pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 A structure <\/span><span lang=\"EN-IN\" style=\"font-size: 11.0pt; color: black; background: white;\">is a collection of data fields with declared data types. Golang can declare and create its data types by combining one or more types, including both built-in and user-defined types.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\ntype student struct {\r\n    Name    string\r\n    class   string\r\n    Roll_No int\r\n    Marks   int\r\n}\r\n\r\nfunc main() {\r\n    var s1 = student{\"Sandeep\", \"X\", 2001, 98}\r\n    var s2 student\r\n    s2.Name = \"Sonu\"\r\n    s2.class = \"IX\"\r\n    s2.Roll_No = 2039\r\n    s2.Marks = 56\r\n    fmt.Println(s1)\r\n    fmt.Println(s2)\r\n}\r\n<\/pre>\n<ul>\n<li><strong>Accessing Structure members<\/strong>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\ntype Books struct {\r\n    title   string\r\n    author string\r\n    subject string\r\n    book-id int\r\n}\r\nfunc main() {\r\n    var Book1 Books\r\n    var Book2 Books\r\n    Book1.title = \"Go Programing\"\r\n    Book1.author = \"Kreston\"\r\n    Book1.subject = \"Go programing tutorial\"\r\n    Book1.book-id = 398312389\r\n\r\n    Book2.title = \"Python Programing\"\r\n    Book2.author = \"Hazera Ali\"\r\n    Book2.subject = \"Python programing tutorial\"\r\n    Book2.book-id = 392342334\r\n\r\n    fmt.Printf(\"Book 1 Title :%s\\n\", Book1.title)\r\n    fmt.Printf(\"Book 1 author :%s\\n\", Book1.author)\r\n    fmt.Printf(\"Book 1 subject :%s\\n\", Book1.subject)\r\n    fmt.Printf(\"Book 1 book id :%s\\n\", Book1.book-id)\r\n\r\n    fmt.Printf(\"Book 2 Title :%s\\n\", Book2.title)\r\n    fmt.Printf(\"Book 2 author :%s\\n\", Book2.author)\r\n    fmt.Printf(\"Book 2 subject :%s\\n\", Book2.subject)\r\n    fmt.Printf(\"Book 2 book id :\", Book2.book-id)\r\n}\r\n<\/pre>\n<p>&nbsp;<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 A structure is a collection of data fields with declared data types. Golang can declare and create its data types by combining one or more types, including both built-in and user-defined types. package main import &#8220;fmt&#8221; type student struct { Name string class string Roll_No [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[666,1707],"tags":[668,808],"class_list":["post-9755","post","type-post","status-publish","format-standard","hentry","category-go-lang","category-golang-modules","tag-go","tag-go-language"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Structure in Golang - Prwatech<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Structure in Golang - Prwatech\" \/>\n<meta property=\"og:description\" content=\"\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 A structure is a collection of data fields with declared data types. Golang can declare and create its data types by combining one or more types, including both built-in and user-defined types. package main import &quot;fmt&quot; type student struct { Name string class string Roll_No [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-28T07:57:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-20T04:35:47+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/\",\"url\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/\",\"name\":\"Structure in Golang - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2022-07-28T07:57:37+00:00\",\"dateModified\":\"2023-07-20T04:35:47+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Structure in Golang\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Structure in Golang - Prwatech","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Structure in Golang - Prwatech","og_description":"\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 A structure is a collection of data fields with declared data types. Golang can declare and create its data types by combining one or more types, including both built-in and user-defined types. package main import \"fmt\" type student struct { Name string class string Roll_No [&hellip;]","og_url":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2022-07-28T07:57:37+00:00","article_modified_time":"2023-07-20T04:35:47+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/","url":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/","name":"Structure in Golang - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2022-07-28T07:57:37+00:00","dateModified":"2023-07-20T04:35:47+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Structure in Golang"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=9755"}],"version-history":[{"count":4,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9755\/revisions"}],"predecessor-version":[{"id":9759,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9755\/revisions\/9759"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}