{"id":9553,"date":"2022-05-01T23:10:02","date_gmt":"2022-05-01T15:10:02","guid":{"rendered":"https:\/\/jpuyy.com\/?p=9553"},"modified":"2022-05-04T16:00:17","modified_gmt":"2022-05-04T08:00:17","slug":"golang-interface","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=9553","title":{"rendered":"golang interface"},"content":{"rendered":"<p>learn by doing<\/p>\n<p>Interface is a protocol &#8211; a contract &#8211; an abstract type<\/p>\n<p>It only describe the expected behavior<\/p>\n<p>naming convention: abstract description<\/p>\n<p>don&#8217;t use empty interface unless it&#8217;s necessary.<\/p>\n<p>type foo interface{}<\/p>\n<p>learn type switch:<\/p>\n<p>func format(v interface{}) string {<br \/>\nswitch v := v.(type) {<br \/>\n    case int:<br \/>\n    case string:<br \/>\n    default:<br \/>\n}<br \/>\n}<\/p>\n<p>When a type anonymously embeds a type, it can use the methods of the embedded type as its own<\/p>\n<p>Interfaces: group types by behavior<\/p>\n<p>Satisfy existing interfaces <- first thinking\n\nInterfaces are abstract bridges between types\n\n\nwatch videos:\nhttps:\/\/www.udemy.com\/course\/learn-go-the-complete-bootcamp-course-golang\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>learn by doing Interface is a protocol &#8211; a contract &#8211; an abstract type It only describe the expected behavior naming convention: abstract description don&#8217;t use empty interface unless it&#8217;s necessary. type foo interface{} learn type switch: func format(v interface{}) string { switch v := v.(type) { case int: case string: default: } } When [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":["post-9553","post","type-post","status-publish","format-standard","hentry","category-golang"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9553"}],"version-history":[{"count":10,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9553\/revisions"}],"predecessor-version":[{"id":9586,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9553\/revisions\/9586"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}