{"id":777,"date":"2019-12-01T07:02:54","date_gmt":"2019-12-01T07:02:54","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=777"},"modified":"2019-12-01T07:08:58","modified_gmt":"2019-12-01T07:08:58","slug":"difference-between-method-function-go","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/","title":{"rendered":"Difference between method and function in GO"},"content":{"rendered":"\n

There are some important differences between method and function. Let’s see the signature of both<\/p>\n\n\n\n

Function:<\/strong><\/p>\n\n\n\n

func some_func_name(arguments) return_values<\/code><\/pre>\n\n\n\n

Method:<\/strong><\/p>\n\n\n\n

func (receiver receiver_type) some_func_name(arguments) return_values<\/code><\/pre>\n\n\n\n


From the above signature, it is clear that method has a receiver argument. A receiver can be a struct or any other type. The method will have access to the properties of the receiver and can call the receiver’s other methods.
This is the only difference between function and method, but due to it they differ in terms of functionality they offer
<\/p>\n\n\n\n

  • A function can be used as first-order objects and can be passed around while methods cannot.<\/li>
  • Methods can be used for chaining on the receiver while function cannot be used for the same.<\/li>
  • There can exist different methods with the same name with a different receiver, but there cannot exist two different functions with the same name in the same package.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"

    There are some important differences between method and function. Let’s see the signature of both Function: Method: From the above signature, it is clear that method has a receiver argument. A receiver…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[97,3,4,93],"class_list":["post-777","post","type-post","status-publish","format-standard","hentry","category-tech","tag-function","tag-go","tag-golang","tag-method"],"yoast_head":"\nDifference between method and function in GO - Welcome To Golang By Example<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference between method and function in GO - Welcome To Golang By Example\" \/>\n<meta property=\"og:description\" content=\"There are some important differences between method and function. Let’s see the signature of both Function: Method: From the above signature, it is clear that method has a receiver argument. A receiver...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/\" \/>\n<meta property=\"og:site_name\" content=\"Welcome To Golang By Example\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-01T07:02:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-01T07:08:58+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\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:\/\/golangbyexamples.com\/difference-between-method-function-go\/\",\"url\":\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/\",\"name\":\"Difference between method and function in GO - Welcome To Golang By Example\",\"isPartOf\":{\"@id\":\"https:\/\/golangbyexamples.com\/#website\"},\"datePublished\":\"2019-12-01T07:02:54+00:00\",\"dateModified\":\"2019-12-01T07:08:58+00:00\",\"author\":{\"@id\":\"https:\/\/golangbyexamples.com\/#\/schema\/person\/8833ea7638dafd763cb1db6c0ca4576f\"},\"breadcrumb\":{\"@id\":\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/golangbyexamples.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Difference between method and function in GO\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/golangbyexamples.com\/#website\",\"url\":\"https:\/\/golangbyexamples.com\/\",\"name\":\"Welcome To Golang By Example\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/golangbyexamples.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/golangbyexamples.com\/#\/schema\/person\/8833ea7638dafd763cb1db6c0ca4576f\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/golangbyexamples.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/golangbyexamples.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference between method and function in GO - Welcome To Golang By Example","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:\/\/golangbyexamples.com\/difference-between-method-function-go\/","og_locale":"en_US","og_type":"article","og_title":"Difference between method and function in GO - Welcome To Golang By Example","og_description":"There are some important differences between method and function. Let’s see the signature of both Function: Method: From the above signature, it is clear that method has a receiver argument. A receiver...","og_url":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/","og_site_name":"Welcome To Golang By Example","article_published_time":"2019-12-01T07:02:54+00:00","article_modified_time":"2019-12-01T07:08:58+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/","url":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/","name":"Difference between method and function in GO - Welcome To Golang By Example","isPartOf":{"@id":"https:\/\/golangbyexamples.com\/#website"},"datePublished":"2019-12-01T07:02:54+00:00","dateModified":"2019-12-01T07:08:58+00:00","author":{"@id":"https:\/\/golangbyexamples.com\/#\/schema\/person\/8833ea7638dafd763cb1db6c0ca4576f"},"breadcrumb":{"@id":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/golangbyexamples.com\/difference-between-method-function-go\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/golangbyexamples.com\/difference-between-method-function-go\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/golangbyexamples.com\/"},{"@type":"ListItem","position":2,"name":"Difference between method and function in GO"}]},{"@type":"WebSite","@id":"https:\/\/golangbyexamples.com\/#website","url":"https:\/\/golangbyexamples.com\/","name":"Welcome To Golang By Example","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/golangbyexamples.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/golangbyexamples.com\/#\/schema\/person\/8833ea7638dafd763cb1db6c0ca4576f","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/golangbyexamples.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/golangbyexamples.com\/author\/admin\/"}]}},"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paOs1b-cx","amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/posts\/777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/comments?post=777"}],"version-history":[{"count":2,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/posts\/777\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/posts\/777\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/media?parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/categories?post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/golangbyexamples.com\/wp-json\/wp\/v2\/tags?post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}