{"id":93740,"date":"2020-04-14T16:21:21","date_gmt":"2020-04-14T08:21:21","guid":{"rendered":"http:\/\/4563.org\/?p=93740"},"modified":"2020-04-14T16:21:21","modified_gmt":"2020-04-14T08:21:21","slug":"golang-%e4%b8%ad-interface-%e5%86%85%e9%83%a8%e6%9e%84%e9%80%a0%e4%b8%8e%e9%9d%a2%e8%af%95%e7%9c%9f%e9%a2%98%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=93740","title":{"rendered":"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sanbenweiyang <\/span>  <span><i><\/i> 39<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h4>(1) interface \u7684\u8d4b\u503c\u95ee\u9898<\/h4>\n<blockquote>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u80fd\u7f16\u8bd1\u8fc7\u53bb\u5417\uff1f\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<\/blockquote>\n<pre><code>package main  import (  \"fmt\" )  type People interface {  Speak(string) string }  type Stduent struct{}  func (stu *Stduent) Speak(think string) (talk string) {  if think == \"love\" {   talk = \"You are a good boy\"  } else {   talk = \"hi\"  }  return }  func main() {  var peo People = Stduent{}  think := \"love\"  fmt.Println(peo.Speak(think)) } <\/code><\/pre>\n<p>\u7ee7\u627f\u4e0e\u591a\u6001\u7684\u7279\u70b9<\/p>\n<p>\u5728 golang \u4e2d\u5bf9\u591a\u6001\u7684\u7279\u70b9\u4f53\u73b0\u4ece\u8bed\u6cd5\u4e0a\u5e76\u4e0d\u662f\u5f88\u660e\u663e\u3002<\/p>\n<p>\u6211\u4eec\u77e5\u9053\u53d1\u751f\u591a\u6001\u7684\u51e0\u4e2a\u8981\u7d20\uff1a<\/p>\n<p>1 \u3001\u6709 interface \u63a5\u53e3\uff0c\u5e76\u4e14\u6709\u63a5\u53e3\u5b9a\u4e49\u7684\u65b9\u6cd5\u3002<\/p>\n<p>2 \u3001\u6709\u5b50\u7c7b\u53bb\u91cd\u5199 interface \u7684\u63a5\u53e3\u3002<\/p>\n<p>3 \u3001\u6709\u7236\u7c7b\u6307\u9488\u6307\u5411\u5b50\u7c7b\u7684\u5177\u4f53\u5bf9\u8c61<\/p>\n<p>\u90a3\u4e48\uff0c\u6ee1\u8db3\u4e0a\u8ff0 3 \u4e2a\u6761\u4ef6\uff0c\u5c31\u53ef\u4ee5\u4ea7\u751f\u591a\u6001\u6548\u679c\uff0c\u5c31\u662f\uff0c\u7236\u7c7b\u6307\u9488\u53ef\u4ee5\u8c03\u7528\u5b50\u7c7b\u7684\u5177\u4f53\u65b9\u6cd5\u3002<\/p>\n<p>\u6240\u4ee5\u4e0a\u8ff0\u4ee3\u7801\u62a5\u9519\u7684\u5730\u65b9\u5728<code>var peo People = Stduent{}<\/code>\u8fd9\u6761\u8bed\u53e5\uff0c <code>Student{}<\/code>\u5df2\u7ecf\u91cd\u5199\u4e86\u7236\u7c7b<code>People{}<\/code>\u4e2d\u7684<code>Speak(string) string<\/code>\u65b9\u6cd5\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u7528\u7236\u7c7b\u6307\u9488\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61\u5373\u53ef\u3002<\/p>\n<p>\u6240\u4ee5\u5e94\u8be5\u6539\u6210<code>var peo People = &amp;Student{}<\/code> \u5373\u53ef\u7f16\u8bd1\u901a\u8fc7\u3002\uff08 People \u4e3a interface \u7c7b\u578b\uff0c\u5c31\u662f\u6307\u9488\u7c7b\u578b\uff09<\/p>\n<h4>(2) interface \u7684\u5185\u90e8\u6784\u9020(\u975e\u7a7a\u63a5\u53e3 iface \u60c5\u51b5)<\/h4>\n<blockquote>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6253\u5370\u51fa\u6765\u4ec0\u4e48\u5185\u5bb9\uff0c\u8bf4\u51fa\u4e3a\u4ec0\u4e48\u3002<\/p>\n<\/blockquote>\n<pre><code>package main  import (  \"fmt\" )  type People interface {  Show() }  type Student struct{}  func (stu *Student) Show() {  }  func live() People {  var stu *Student  return stu }  func main() {  if live() == nil {   fmt.Println(\"AAAAAAA\")  } else {   fmt.Println(\"BBBBBBB\")  } } <\/code><\/pre>\n<p><strong>\u7ed3\u679c<\/strong><\/p>\n<pre><code>BBBBBBB <\/code><\/pre>\n<p><strong>\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u9700\u8981\u4e86\u89e3<code>interface<\/code>\u7684\u5185\u90e8\u7ed3\u6784\uff0c\u624d\u80fd\u7406\u89e3\u8fd9\u4e2a\u9898\u76ee\u7684\u542b\u4e49\u3002<\/p>\n<p>interface \u5728\u4f7f\u7528\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5171\u6709\u4e24\u79cd\u8868\u73b0\u5f62\u5f0f<\/p>\n<p>\u4e00\u79cd\u4e3a<strong>\u7a7a\u63a5\u53e3(empty interface)<\/strong>\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code>var MyInterface interface{} <\/code><\/pre>\n<p>\u53e6\u4e00\u79cd\u4e3a<strong>\u975e\u7a7a\u63a5\u53e3(non-empty interface)<\/strong>, \u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code>type MyInterface interface {   function() } <\/code><\/pre>\n<p>\u8fd9\u4e24\u79cd interface \u7c7b\u578b\u5206\u522b\u7528\u4e24\u79cd<code>struct<\/code>\u8868\u793a\uff0c\u7a7a\u63a5\u53e3\u4e3a<code>eface<\/code>, \u975e\u7a7a\u63a5\u53e3\u4e3a<code>iface<\/code>. !]( https:\/\/upload-images.jianshu.io\/upload_images\/11093205-390416d69864055e.jpeg?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1240)<\/p>\n<h5><strong>\u7a7a\u63a5\u53e3 eface<\/strong><\/h5>\n<p>\u7a7a\u63a5\u53e3 eface \u7ed3\u6784\uff0c\u7531\u4e24\u4e2a\u5c5e\u6027\u6784\u6210\uff0c\u4e00\u4e2a\u662f\u7c7b\u578b\u4fe1\u606f_type\uff0c\u4e00\u4e2a\u662f\u6570\u636e\u4fe1\u606f\u3002\u5176\u6570\u636e\u7ed3\u6784\u58f0\u660e\u5982\u4e0b\uff1a<\/p>\n<pre><code>type eface struct {      \/\/\u7a7a\u63a5\u53e3     _type *_type         \/\/\u7c7b\u578b\u4fe1\u606f     data  unsafe.Pointer \/\/\u6307\u5411\u6570\u636e\u7684\u6307\u9488(go \u8bed\u8a00\u4e2d\u7279\u6b8a\u7684\u6307\u9488\u7c7b\u578b unsafe.Pointer \u7c7b\u4f3c\u4e8e c \u8bed\u8a00\u4e2d\u7684 void*) } <\/code><\/pre>\n<p><strong>_type \u5c5e\u6027<\/strong>\uff1a\u662f GO \u8bed\u8a00\u4e2d\u6240\u6709\u7c7b\u578b\u7684\u516c\u5171\u63cf\u8ff0\uff0cGo \u8bed\u8a00\u51e0\u4e4e\u6240\u6709\u7684\u6570\u636e\u7ed3\u6784\u90fd\u53ef\u4ee5\u62bd\u8c61\u6210 _type\uff0c\u662f\u6240\u6709\u7c7b\u578b\u7684\u516c\u5171\u63cf\u8ff0\uff0c**type \u8d1f\u8d23\u51b3\u5b9a data \u5e94\u8be5\u5982\u4f55\u89e3\u91ca\u548c\u64cd\u4f5c\uff0c**type \u7684\u7ed3\u6784\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code>type _type struct {     size       uintptr  \/\/\u7c7b\u578b\u5927\u5c0f     ptrdata    uintptr  \/\/\u524d\u7f00\u6301\u6709\u6240\u6709\u6307\u9488\u7684\u5185\u5b58\u5927\u5c0f     hash       uint32   \/\/\u6570\u636e hash \u503c     tflag      tflag     align      uint8    \/\/\u5bf9\u9f50     fieldalign uint8    \/\/\u5d4c\u5165\u7ed3\u6784\u4f53\u65f6\u7684\u5bf9\u9f50     kind       uint8    \/\/kind \u6709\u4e9b\u679a\u4e3e\u503c kind \u7b49\u4e8e 0 \u662f\u65e0\u6548\u7684     alg        *typeAlg \/\/\u51fd\u6570\u6307\u9488\u6570\u7ec4\uff0c\u7c7b\u578b\u5b9e\u73b0\u7684\u6240\u6709\u65b9\u6cd5     gcdata    *byte     str       nameOff     ptrToThis typeOff } <\/code><\/pre>\n<p><strong>data \u5c5e\u6027:<\/strong> \u8868\u793a\u6307\u5411\u5177\u4f53\u7684\u5b9e\u4f8b\u6570\u636e\u7684\u6307\u9488\uff0c\u4ed6\u662f\u4e00\u4e2a<code>unsafe.Pointer<\/code>\u7c7b\u578b\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2a C \u7684\u4e07\u80fd\u6307\u9488<code>void*<\/code>\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d5b8aa56.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<h5>\u975e\u7a7a\u63a5\u53e3 iface<\/h5>\n<p>iface \u8868\u793a non-empty interface \u7684\u6570\u636e\u7ed3\u6784\uff0c\u975e\u7a7a\u63a5\u53e3\u521d\u59cb\u5316\u7684\u8fc7\u7a0b\u5c31\u662f\u521d\u59cb\u5316\u4e00\u4e2a iface \u7c7b\u578b\u7684\u7ed3\u6784\uff0c\u5176\u4e2d<code>data<\/code>\u7684\u4f5c\u7528\u540c<code>eface<\/code>\u7684\u76f8\u540c\uff0c\u8fd9\u91cc\u4e0d\u518d\u591a\u52a0\u63cf\u8ff0\u3002<\/p>\n<pre><code>type iface struct {   tab  *itab   data unsafe.Pointer } <\/code><\/pre>\n<p>iface \u7ed3\u6784\u4e2d\u6700\u91cd\u8981\u7684\u662f itab \u7ed3\u6784\uff08\u7ed3\u6784\u5982\u4e0b\uff09\uff0c\u6bcf\u4e00\u4e2a <code>itab<\/code> \u90fd\u5360 32 \u5b57\u8282\u7684\u7a7a\u95f4\u3002itab \u53ef\u4ee5\u7406\u89e3\u4e3a<code>pair&lt;interface type, concrete type&gt;<\/code> \u3002itab \u91cc\u9762\u5305\u542b\u4e86 interface \u7684\u4e00\u4e9b\u5173\u952e\u4fe1\u606f\uff0c\u6bd4\u5982 method \u7684\u5177\u4f53\u5b9e\u73b0\u3002<\/p>\n<pre><code>type itab struct {   inter  *interfacetype   \/\/ \u63a5\u53e3\u81ea\u8eab\u7684\u5143\u4fe1\u606f   _type  *_type           \/\/ \u5177\u4f53\u7c7b\u578b\u7684\u5143\u4fe1\u606f   link   *itab   bad    int32   hash   int32            \/\/ _type \u91cc\u4e5f\u6709\u4e00\u4e2a\u540c\u6837\u7684 hash\uff0c\u6b64\u5904\u591a\u653e\u4e00\u4e2a\u662f\u4e3a\u4e86\u65b9\u4fbf\u8fd0\u884c\u63a5\u53e3\u65ad\u8a00   fun    [1]uintptr       \/\/ \u51fd\u6570\u6307\u9488\uff0c\u6307\u5411\u5177\u4f53\u7c7b\u578b\u6240\u5b9e\u73b0\u7684\u65b9\u6cd5 } <\/code><\/pre>\n<p>\u5176\u4e2d\u503c\u5f97\u6ce8\u610f\u7684\u5b57\u6bb5\uff0c\u4e2a\u4eba\u7406\u89e3\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li><code>interface type<\/code>\u5305\u542b\u4e86\u4e00\u4e9b\u5173\u4e8e interface \u672c\u8eab\u7684\u4fe1\u606f\uff0c\u6bd4\u5982<code>package path<\/code>\uff0c\u5305\u542b\u7684<code>method<\/code>\u3002\u8fd9\u91cc\u7684 interfacetype \u662f\u5b9a\u4e49 interface \u7684\u4e00\u79cd\u62bd\u8c61\u8868\u793a\u3002<\/li>\n<li><code>type<\/code>\u8868\u793a\u5177\u4f53\u5316\u7684\u7c7b\u578b\uff0c\u4e0e eface \u7684 <em>type \u7c7b\u578b\u76f8\u540c\u3002<\/em><\/li>\n<li><code>hash<\/code>\u5b57\u6bb5\u5176\u5b9e\u662f\u5bf9<code>_type.hash<\/code>\u7684\u62f7\u8d1d\uff0c\u5b83\u4f1a\u5728 interface \u7684\u5b9e\u4f8b\u5316\u65f6\uff0c\u7528\u4e8e\u5feb\u901f\u5224\u65ad\u76ee\u6807\u7c7b\u578b\u548c\u63a5\u53e3\u4e2d\u7684\u7c7b\u578b\u662f\u5426\u4e00\u81f4\u3002\u53e6\uff0cGo \u7684 interface \u7684 Duck-typing \u673a\u5236\u4e5f\u662f\u4f9d\u8d56\u8fd9\u4e2a\u5b57\u6bb5\u6765\u5b9e\u73b0\u3002<\/li>\n<li><code>fun<\/code>\u5b57\u6bb5\u5176\u5b9e\u662f\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u6570\u7ec4\uff0c\u867d\u7136\u58f0\u660e\u65f6\u662f\u56fa\u5b9a\u5927\u5c0f\u4e3a 1\uff0c\u4f46\u5728\u4f7f\u7528\u65f6\u4f1a\u76f4\u63a5\u901a\u8fc7 fun \u6307\u9488\u83b7\u53d6\u5176\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u4e14\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u7684\u8fb9\u754c\uff0c\u6240\u4ee5\u8be5\u6570\u7ec4\u4e2d\u4fdd\u5b58\u7684\u5143\u7d20\u6570\u91cf\u662f\u4e0d\u786e\u5b9a\u7684\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d66a2619.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<p>\u6240\u4ee5\uff0cPeople \u62e5\u6709\u4e00\u4e2a Show \u65b9\u6cd5\u7684\uff0c\u5c5e\u4e8e\u975e\u7a7a\u63a5\u53e3\uff0cPeople \u7684\u5185\u90e8\u5b9a\u4e49\u5e94\u8be5\u662f\u4e00\u4e2a<code>iface<\/code>\u7ed3\u6784\u4f53<\/p>\n<pre><code>type People interface {     Show()   }   <\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d72e0b7e.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<pre><code>func live() People {     var stu *Student     return stu       }      <\/code><\/pre>\n<p>stu \u662f\u4e00\u4e2a\u6307\u5411 nil \u7684\u7a7a\u6307\u9488\uff0c\u4f46\u662f\u6700\u540e<code>return stu<\/code> \u4f1a\u89e6\u53d1<code>\u533f\u540d\u53d8\u91cf People = stu<\/code>\u503c\u62f7\u8d1d\u52a8\u4f5c\uff0c\u6240\u4ee5\u6700\u540e<code>live()<\/code>\u653e\u56de\u7ed9\u4e0a\u5c42\u7684\u662f\u4e00\u4e2a<code>People insterface{}<\/code>\u7c7b\u578b\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a<code>iface struct{}<\/code>\u7c7b\u578b\u3002stu \u4e3a nil\uff0c\u53ea\u662f<code>iface<\/code>\u4e2d\u7684 data \u4e3a nil \u800c\u5df2\u3002 \u4f46\u662f<code>iface struct{}<\/code>\u672c\u8eab\u5e76\u4e0d\u4e3a nil.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d7ef0c55.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<p>\u6240\u4ee5\u5982\u4e0b\u5224\u65ad\u7684\u7ed3\u679c\u4e3a<code>BBBBBBB<\/code>\uff1a<\/p>\n<pre><code>func main() {        if live() == nil {           fmt.Println(\"AAAAAAA\")           } else {         fmt.Println(\"BBBBBBB\")     } } <\/code><\/pre>\n<h4>(3) interface \u5185\u90e8\u6784\u9020(\u7a7a\u63a5\u53e3 eface \u60c5\u51b5)<\/h4>\n<blockquote>\n<p>\u4e0b\u9762\u4ee3\u7801\u7ed3\u679c\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<\/blockquote>\n<pre><code>func Foo(x interface{}) {  if x == nil {   fmt.Println(\"empty interface\")   return  }  fmt.Println(\"non-empty interface\") } func main() {  var p *int = nil  Foo(p) } <\/code><\/pre>\n<p><strong>\u7ed3\u679c<\/strong><\/p>\n<pre><code>non-empty interface <\/code><\/pre>\n<p><strong>\u5206\u6790<\/strong><\/p>\n<p>\u4e0d\u96be\u770b\u51fa\uff0c<code>Foo()<\/code>\u7684\u5f62\u53c2<code>x interface{}<\/code>\u662f\u4e00\u4e2a\u7a7a\u63a5\u53e3\u7c7b\u578b<code>eface struct{}<\/code>\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d8a11a05.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<p>\u5728\u6267\u884c<code>Foo(p)<\/code>\u7684\u65f6\u5019\uff0c\u89e6\u53d1<code>x interface{} = p<\/code>\u8bed\u53e5\uff0c\u6240\u4ee5\u6b64\u65f6 x \u7ed3\u6784\u5982\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45d95d0c05.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<p>\u6240\u4ee5 x \u7ed3\u6784\u4f53\u672c\u8eab\u4e0d\u4e3a nil\uff0c\u800c\u662f data \u6307\u9488\u6307\u5411\u7684 p \u4e3a nil \u3002<\/p>\n<h4>(4) inteface{}\u4e0e*interface{}<\/h4>\n<blockquote>\n<p>ABCD \u4e2d\u54ea\u4e00\u884c\u5b58\u5728\u9519\u8bef\uff1f<\/p>\n<\/blockquote>\n<pre><code>type S struct { }  func f(x interface{}) { }  func g(x *interface{}) { }  func main() {  s := S{}  p := &amp;s  f(s) \/\/A  g(s) \/\/B  f(p) \/\/C  g(p) \/\/D } <\/code><\/pre>\n<p><strong>\u7ed3\u679c<\/strong><\/p>\n<pre><code>B \u3001D \u4e24\u884c\u9519\u8bef B \u9519\u8bef\u4e3a\uff1acannot use s (type S) as type *interface {} in argument to g:  *interface {} is pointer to interface, not interface   D \u9519\u8bef\u4e3a\uff1acannot use p (type *S) as type *interface {} in argument to g:  *interface {} is pointer to interface, not interface  <\/code><\/pre>\n<p>\u770b\u5230\u8fd9\u9053\u9898\u9700\u8981\u7b2c\u4e00\u65f6\u95f4\u60f3\u5230\u7684\u662f Golang \u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0cinterface \u662f\u6240\u6709 golang \u7c7b\u578b\u7684\u7236\u7c7b \u51fd\u6570\u4e2d<code>func f(x interface{})<\/code>\u7684<code>interface{}<\/code>\u53ef\u4ee5\u652f\u6301\u4f20\u5165 golang \u7684\u4efb\u4f55\u7c7b\u578b\uff0c\u5305\u62ec\u6307\u9488\uff0c\u4f46\u662f\u51fd\u6570<code>func g(x *interface{})<\/code>\u53ea\u80fd\u63a5\u53d7<code>*interface{}<\/code><\/p>\n<p>\u5982\u679c\u638c\u63e1<code>interface<\/code>\u6784\u9020\uff0c\u5efa\u8bae\u770b\u4e0b\u4e00\u7bc7\u6587\u7ae0 \u4f7f\u7528 Golang \u7684 interface \u63a5\u53e3\u8bbe\u8ba1\u539f\u5219<\/p>\n<h3>\u5173\u4e8e\u4f5c\u8005\uff1a<\/h3>\n<p>mail:\u00a0<span data-cfemail=\"5f3b3e313d363138713e2b1f38323e3633713c3032\">[email&#160;protected]<\/span> github:\u00a0https:\/\/github.com\/aceld \u539f\u521b\u4e66\u7c4d gitbook:\u00a0http:\/\/legacy.gitbook.com\/@aceld<\/p>\n<h2>\u521b\u4f5c\u4e0d\u6613, \u5171\u540c\u5b66\u4e60\u8fdb\u6b65, \u6b22\u8fce\u5173\u6ce8\u4f5c\u8005, \u56de\u590d&#8221;zinx&#8221;\u6709\u597d\u793c<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec45da191243.jpg\" alt=\"Golang \u4e2d interface \u5185\u90e8\u6784\u9020\u4e0e\u9762\u8bd5\u771f\u9898\u5206\u6790\" \/><\/p>\n<h2>\u6587\u7ae0\u63a8\u8350<\/h2>\n<h4>\u5f00\u6e90\u8f6f\u4ef6\u4f5c\u54c1<\/h4>\n<p>(\u539f\u521b\u5f00\u6e90)Zinx-\u57fa\u4e8e Golang \u8f7b\u91cf\u7ea7\u670d\u52a1\u5668\u5e76\u53d1\u6846\u67b6-\u5b8c\u6574\u7248(\u9644\u6559\u7a0b\u89c6\u9891)<\/p>\n<p>(\u539f\u521b\u5f00\u6e90)Lars-\u57fa\u4e8e C++\u8d1f\u8f7d\u5747\u8861\u8fdc\u7a0b\u8c03\u5ea6\u7cfb\u7edf-\u5b8c\u6574\u7248<\/p>\n<h4>\u7cbe\u9009\u6587\u7ae0<\/h4>\n<p>\u5178\u85cf\u7248-Golang \u8c03\u5ea6\u5668 GMP \u539f\u7406\u4e0e\u8c03\u5ea6\u5168\u5206\u6790<\/p>\n<p>\u5178\u85cf\u7248-Golang \u4e09\u8272\u6807\u8bb0\u3001\u6df7\u5408\u5199\u5c4f\u969c GC \u6a21\u5f0f\u56fe\u6587\u5168\u5206\u6790<\/p>\n<p>\u6700\u5e38\u7528\u7684\u8c03\u8bd5 golang \u7684 bug \u4ee5\u53ca\u6027\u80fd\u95ee\u9898\u7684\u5b9e\u8df5\u65b9\u6cd5\uff1f<\/p>\n<p>Golang \u4e2d\u7684 Defer \u5fc5\u638c\u63e1\u7684 7 \u77e5\u8bc6\u70b9<\/p>\n<p>Golang \u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u201c\u4f55\u65f6\u6808?\u4f55\u65f6\u5806?\u201d<\/p>\n<p>\u4f7f\u7528 Golang \u7684 interface \u63a5\u53e3\u8bbe\u8ba1\u539f\u5219<\/p>\n<p>\u6d41\uff1f I\/O \u64cd\u4f5c\uff1f\u963b\u585e\uff1f epoll?<\/p>\n<p>\u6df1\u5165\u6d45\u51fa Golang \u7684\u534f\u7a0b\u6c60\u8bbe\u8ba1<\/p>\n<p>Go \u8bed\u8a00\u6784\u5efa\u5fae\u670d\u52a1\u4e00\u7ad9\u5f0f\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Golang \u4e2d interfac&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93740"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93740"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93740\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93740"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}