{"id":15464,"date":"2024-11-18T18:12:05","date_gmt":"2024-11-18T10:12:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15464"},"modified":"2024-11-18T18:12:05","modified_gmt":"2024-11-18T10:12:05","slug":"go%e4%b8%ad%e6%96%ad%e8%a8%80interface%e7%b1%bb%e5%9e%8b%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15464\/","title":{"rendered":"GO\u4e2d\u65ad\u8a00interface\u7c7b\u578b\u7684\u65b9\u6cd5"},"content":{"rendered":"<p><strong>\u65b9\u6cd5\u4e00\uff1a<\/strong><\/p>\n<pre>if sw, ok := w.(stringWriter); ok {\r\n   return sw.WriteString(s)\r\n}<\/pre>\n<p>\u6839\u636eok\u7684\u503c\u5224\u65ad\u65ad\u8a00\u662f\u5426\u6210\u529f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a<\/strong><\/p>\n<pre>switch a.(type) {\r\n      case int64:\r\n          if i, ok := a.(int64); ok {\r\n              return int(i),nil\r\n          }\r\n      case float64:\r\n          if i, ok := a.(float64); ok {\r\n              return int(i),nil\r\n          }\r\n      default:\r\n          return 0,errors.New(\"Don't change to Int\")\r\n  }<\/pre>\n<p>\u65b9\u6cd5\u4e8c\u4e00\u822c\u7528\u5728\u9700\u8981\u65ad\u8a00\u7c7b\u578b\u6bd4\u8f83\u591a\u7684\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u4e00\uff1a if sw, ok := w.(stringWriter); ok { return sw.WriteString(s) } \u6839\u636eok\u7684\u503c\u5224\u65ad\u65ad\u8a00\u662f\u5426\u6210\u529f\u3002 &nbsp; \u65b9\u6cd5\u4e8c\uff1a switch a.(type) { case int64: if i, ok := a.(int64); ok { return int(i),nil } case float64: if i, ok := a.(float64); ok { return int(i),nil } default: return 0,errors.New(&#8220;Don&#8217;t change to Int&#8221;) } \u65b9\u6cd5\u4e8c\u4e00\u822c\u7528\u5728\u9700\u8981\u65ad\u8a00\u7c7b\u578b\u6bd4\u8f83\u591a\u7684\u60c5\u51b5\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15464","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15464"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15464\/revisions"}],"predecessor-version":[{"id":15465,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15464\/revisions\/15465"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}