{"id":71219,"date":"2024-02-23T18:12:12","date_gmt":"2024-02-23T10:12:12","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=71219"},"modified":"2024-02-23T18:12:12","modified_gmt":"2024-02-23T10:12:12","slug":"go-modifier-programming","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/go-modifier-programming.html","title":{"rendered":"Golang \u4fee\u9970\u5668\u7f16\u7a0b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e4b\u524d\u5199\u8fc7\u4e00\u7bc7\u300aPython\u4fee\u9970\u5668\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b<\/a>\u300b\uff0c\u8fd9\u79cd\u6a21\u5f0f\u5f88\u5bb9\u6613\u7684\u53ef\u4ee5\u628a\u4e00\u4e9b\u51fd\u6570\u88c5\u914d\u5230\u53e6\u5916\u4e00\u4e9b\u51fd\u6570\u4e0a\uff0c\u53ef\u4ee5\u8ba9\u4f60\u7684\u4ee3\u7801\u66f4\u4e3a\u7684\u7b80\u5355\uff0c\u4e5f\u53ef\u4ee5\u8ba9\u4e00\u4e9b\u201c\u5c0f\u529f\u80fd\u578b\u201d\u7684\u4ee3\u7801\u590d\u7528\u6027\u66f4\u9ad8\uff0c\u8ba9\u4ee3\u7801\u4e2d\u7684\u51fd\u6570\u53ef\u4ee5\u50cf\u4e50\u9ad8\u73a9\u5177\u90a3\u6837\u81ea\u7531\u5730\u62fc\u88c5\u3002\u6240\u4ee5\uff0c\u4e00\u76f4\u4ee5\u6765\uff0c\u6211\u5bf9\u4fee\u9970\u5668decoration\u8fd9\u79cd\u7f16\u7a0b\u6a21\u5f0f\u60c5\u6709\u72ec\u949f\uff0c\u8fd9\u91cc\u5199\u4e00\u7bc7Go\u8bed\u8a00\u76f8\u5173\u7684\u6587\u7ae0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u770b\u8fc7Python\u4fee\u9970\u5668\u90a3\u7bc7\u6587\u7ae0\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u77e5\u9053\u8fd9\u662f\u4e00\u79cd\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u73a9\u6cd5\u2014\u2014\u7528\u4e00\u4e2a\u9ad8\u9636\u51fd\u6570\u6765\u5305\u88c5\u4e00\u4e0b\u3002\u591a\u5520\u53e8\u4e00\u53e5\uff0c\u5173\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u53ef\u4ee5\u53c2\u770b\u6211\u4e4b\u524d\u5199\u8fc7\u4e00\u7bc7\u6587\u7ae0\u300a\u51fd\u6570\u5f0f\u7f16\u7a0b<\/a>\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\uff0c\u60f3\u901a\u8fc7\u4ece\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\u7684\u601d\u7ef4\u65b9\u5f0f\u8fc7\u6e21\u5230\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u601d\u7ef4\u65b9\u5f0f\uff0c\u4ece\u800c\u5e26\u52a8\u66f4\u591a\u7684\u4eba\u73a9\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u4e00\u4e0b\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u90a3\u4e48\u53ef\u4ee5\u79fb\u6b65\u5148\u9605\u8bfb\u4e00\u4e0b\u3002\u6240\u4ee5\uff0cGo\u8bed\u8a00\u7684\u4fee\u9970\u5668\u7f16\u7a0b\u6a21\u5f0f\uff0c\u5176\u5b9e\u4e5f\u5c31\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u6a21\u5f0f\u3002<\/p>\n

\u4e0d\u8fc7\uff0c\u8981\u63d0\u9192\u6ce8\u610f\u7684\u662f\uff0cGo \u8bed\u8a00\u7684\u201c\u7cd6\u201d\u4e0d\u591a\uff0c\u800c\u4e14\u53c8\u662f\u5f3a\u7c7b\u578b\u7684\u9759\u6001\u65e0\u865a\u62df\u673a\u7684\u8bed\u8a00\uff0c\u6240\u4ee5\uff0c\u65e0\u6cd5\u505a\u5230\u50cf Java \u548c Python \u90a3\u6837\u7684\u4f18\u96c5\u7684\u4fee\u9970\u5668\u7684\u4ee3\u7801\u3002\u5f53\u7136\uff0c\u4e5f\u8bb8\u662f\u6211\u624d\u624d\u758f\u5b66\u6d45\uff0c\u5982\u679c\u4f60\u77e5\u9053\u6709\u66f4\u591a\u7684\u5199\u6cd5\uff0c\u8bf7\u4f60\u4e00\u5b9a\u544a\u8bc9\u6211\u3002\u5148\u8c22\u8fc7\u4e86\u3002<\/p>\n

\u7b80\u5355\u793a\u4f8b<\/strong><\/div>\n

\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n

package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc decorator(f func(s string)) func(s string) {\r\n\r\n        return func(s string) {\r\n                fmt.Println(\"Started\")\r\n                f(s)\r\n                fmt.Println(\"Done\")\r\n        }\r\n}\r\n\r\nfunc Hello(s string) {\r\n        fmt.Println(s)\r\n}\r\n\r\nfunc main() {\r\n        decorator(Hello)(\"Hello, World!\")\r\n}<\/pre>\n

\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u52a8\u7528\u4e86\u4e00\u4e2a\u9ad8\u9636\u51fd\u6570\u00a0decorator()<\/span>\uff0c\u5728\u8c03\u7528\u7684\u65f6\u5019\uff0c\u5148\u628a\u00a0Hello()<\/span>\u51fd\u6570\u4f20\u8fdb\u53bb\uff0c\u7136\u540e\u5176\u8fd4\u56de\u4e00\u4e2a\u533f\u540d\u51fd\u6570\uff0c\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u4e2d\u9664\u4e86\u8fd0\u884c\u4e86\u81ea\u5df1\u7684\u4ee3\u7801\uff0c\u4e5f\u8c03\u7528\u4e86\u88ab\u4f20\u5165\u7684\u00a0Hello()<\/span>\u00a0\u51fd\u6570\u3002<\/p>\n

\u8fd9\u4e2a\u73a9\u6cd5\u548c Python \u7684\u5f02\u66f2\u540c\u5de5\uff0c\u53ea\u4e0d\u8fc7\uff0c\u6709\u4e9b\u9057\u61be\u7684\u662f\uff0cGo \u5e76\u4e0d\u652f\u6301\u50cf Python \u90a3\u6837\u7684\u00a0@decorator<\/span>\u00a0\u8bed\u6cd5\u7cd6\u3002\u6240\u4ee5\uff0c\u5728\u8c03\u7528\u4e0a\u6709\u4e9b\u96be\u770b\u3002\u5f53\u7136\uff0c\u5982\u679c\u4f60\u8981\u60f3\u8ba9\u4ee3\u7801\u5bb9\u6613\u8bfb\u4e00\u4e9b\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n

hello := decorator(Hello)\r\nhello(\"Hello\")<\/pre>\n

\u6211\u4eec\u518d\u6765\u770b\u4e00\u4e2a\u548c\u8ba1\u7b97\u8fd0\u884c\u65f6\u95f4\u7684\u4f8b\u5b50\uff1a<\/p>\n

package main\r\n\r\nimport (\r\n  \"fmt\"\r\n  \"reflect\"\r\n  \"runtime\"\r\n  \"time\"\r\n)\r\n\r\ntype SumFunc func(int64, int64) int64\r\n\r\nfunc getFunctionName(i interface{}) string {\r\n  return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()\r\n}\r\n\r\nfunc timedSumFunc(f SumFunc) SumFunc {\r\n  return func(start, end int64) int64 {\r\n\r\n    defer func(t time.Time) {\r\n      fmt.Printf(\"--- Time Elapsed (%s): %v ---\/n\", \r\n          getFunctionName(f), time.Since(t))\r\n    }(time.Now())\r\n\r\n    return f(start, end)\r\n  }\r\n}\r\n\r\nfunc Sum1(start, end int64) int64 {\r\n  var sum int64\r\n  sum = 0\r\n  if start > end {\r\n    start, end = end, start\r\n  }\r\n  for i := start; i <= end; i++ {\r\n    sum += i\r\n  }\r\n  return sum\r\n}\r\n\r\nfunc Sum2(start, end int64) int64 {\r\n  if start > end {\r\n    start, end = end, start\r\n  }\r\n  return (end - start + 1) * (end + start) \/ 2\r\n}\r\n\r\nfunc main() {\r\n\r\n  sum1 := timedSumFunc(Sum1)\r\n  sum2 := timedSumFunc(Sum2)\r\n\r\n  fmt.Printf(\"%d, %d\/n\", sum1(-10000, 10000000), sum2(-10000, 10000000))\r\n}<\/pre>\n

\u5173\u4e8e\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6709\u51e0\u4e2a\u4e8b\u8bf4\u660e\u4e00\u4e0b\uff1a<\/p>\n

1\uff09\u6709\u4e24\u4e2a Sum \u51fd\u6570\uff0cSum1()<\/span>\u00a0\u51fd\u6570\u5c31\u662f\u7b80\u5355\u7684\u505a\u4e2a\u5faa\u73af\uff0cSum2()<\/span>\u00a0\u51fd\u6570\u52a8\u7528\u4e86\u6570\u636e\u516c\u5f0f\u3002\uff08\u6ce8\u610f\uff1astart \u548c end \u6709\u53ef\u80fd\u6709\u8d1f\u6570\u7684\u60c5\u51b5\uff09<\/p>\n

2\uff09\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86 Go \u8bed\u8a00\u7684\u53cd\u5c04\u673a\u5668\u6765\u83b7\u53d6\u51fd\u6570\u540d\u3002<\/p>\n

3\uff09\u4fee\u9970\u5668\u51fd\u6570\u662f\u00a0timedSumFunc()<\/span><\/p>\n

\u8fd0\u884c\u540e\u8f93\u51fa\uff1a<\/p>\n

$ go run time.sum.go\r\n--- Time Elapsed (main.Sum1): 3.557469ms ---\r\n--- Time Elapsed (main.Sum2): 291ns ---\r\n49999954995000, 49999954995000<\/pre>\n
HTTP \u76f8\u5173\u7684\u4e00\u4e2a\u793a\u4f8b<\/strong><\/div>\n

\u6211\u4eec\u518d\u6765\u770b\u4e00\u4e2a\u5904\u7406 HTTP \u8bf7\u6c42\u7684\u76f8\u5173\u7684\u4f8b\u5b50\u3002<\/p>\n

\u5148\u770b\u4e00\u4e2a\u7b80\u5355\u7684 HTTP Server \u7684\u4ee3\u7801\u3002<\/p>\n

package main\r\n\r\nimport (\r\n        \"fmt\"\r\n        \"log\"\r\n        \"net\/http\"\r\n        \"strings\"\r\n)\r\n\r\nfunc WithServerHeader(h http.HandlerFunc) http.HandlerFunc {\r\n        return func(w http.ResponseWriter, r *http.Request) {\r\n                log.Println(\"--->WithServerHeader()\")\r\n                w.Header().Set(\"Server\", \"HelloServer v0.0.1\")\r\n                h(w, r)\r\n        }\r\n}\r\n\r\nfunc hello(w http.ResponseWriter, r *http.Request) {\r\n        log.Printf(\"Recieved Request %s from %s\/n\", r.URL.Path, r.RemoteAddr)\r\n        fmt.Fprintf(w, \"Hello, World! \"+r.URL.Path)\r\n}\r\n\r\nfunc main() {\r\n        http.HandleFunc(\"\/v1\/hello\", WithServerHeader(hello))\r\n        err := http.ListenAndServe(\":8080\", nil)\r\n        if err != nil {\r\n                log.Fatal(\"ListenAndServe: \", err)\r\n        }\r\n}<\/pre>\n
\n

\u4e0a\u9762\u4ee3\u7801\u4e2d\u4f7f\u7528\u5230\u4e86\u4fee\u9970\u6a21\u5f0f\uff0cWithServerHeader()<\/span>\u00a0\u51fd\u6570\u5c31\u662f\u4e00\u4e2a Decorator\uff0c\u5176\u4f20\u5165\u4e00\u4e2a\u00a0http.HandlerFunc<\/span>\uff0c\u7136\u540e\u8fd4\u56de\u4e00\u4e2a\u6539\u5199\u7684\u7248\u672c\u3002\u4e0a\u9762\u7684\u4f8b\u5b50\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\uff0c\u7528\u00a0WithServerHeader()<\/span>\u00a0\u5c31\u53ef\u4ee5\u52a0\u5165\u4e00\u4e2a Response \u7684 Header\u3002<\/p>\n

\u4e8e\u662f\uff0c\u8fd9\u6837\u7684\u51fd\u6570\u6211\u4eec\u53ef\u4ee5\u5199\u51fa\u597d\u4e9b\u4e2a\u3002\u5982\u4e0b\u6240\u793a\uff0c\u6709\u5199 HTTP \u54cd\u5e94\u5934\u7684\uff0c\u6709\u5199\u8ba4\u8bc1 Cookie \u7684\uff0c\u6709\u68c0\u67e5\u8ba4\u8bc1Cookie\u7684\uff0c\u6709\u6253\u65e5\u5fd7\u7684\u2026\u2026<\/p>\n

package main\r\n\r\nimport (\r\n        \"fmt\"\r\n        \"log\"\r\n        \"net\/http\"\r\n        \"strings\"\r\n)\r\n\r\nfunc WithServerHeader(h http.HandlerFunc) http.HandlerFunc {\r\n        return func(w http.ResponseWriter, r *http.Request) {\r\n                log.Println(\"--->WithServerHeader()\")\r\n                w.Header().Set(\"Server\", \"HelloServer v0.0.1\")\r\n                h(w, r)\r\n        }\r\n}\r\n\r\nfunc WithAuthCookie(h http.HandlerFunc) http.HandlerFunc {\r\n        return func(w http.ResponseWriter, r *http.Request) {\r\n                log.Println(\"--->WithAuthCookie()\")\r\n                cookie := &http.Cookie{Name: \"Auth\", Value: \"Pass\", Path: \"\/\"}\r\n                http.SetCookie(w, cookie)\r\n                h(w, r)\r\n        }\r\n}\r\n\r\nfunc WithBasicAuth(h http.HandlerFunc) http.HandlerFunc {\r\n        return func(w http.ResponseWriter, r *http.Request) {\r\n                log.Println(\"--->WithBasicAuth()\")\r\n                cookie, err := r.Cookie(\"Auth\")\r\n                if err != nil || cookie.Value != \"Pass\" {\r\n                        w.WriteHeader(http.StatusForbidden)\r\n                        return\r\n                }\r\n                h(w, r)\r\n        }\r\n}\r\n\r\nfunc WithDebugLog(h http.HandlerFunc) http.HandlerFunc {\r\n        return func(w http.ResponseWriter, r *http.Request) {\r\n                log.Println(\"--->WithDebugLog\")\r\n                r.ParseForm()\r\n                log.Println(r.Form)\r\n                log.Println(\"path\", r.URL.Path)\r\n                log.Println(\"scheme\", r.URL.Scheme)\r\n                log.Println(r.Form[\"url_long\"])\r\n                for k, v := range r.Form {\r\n                        log.Println(\"key:\", k)\r\n                        log.Println(\"val:\", strings.Join(v, \"\"))\r\n                }\r\n                h(w, r)\r\n        }\r\n}\r\nfunc hello(w http.ResponseWriter, r *http.Request) {\r\n        log.Printf(\"Recieved Request %s from %s\/n\", r.URL.Path, r.RemoteAddr)\r\n        fmt.Fprintf(w, \"Hello, World! \"+r.URL.Path)\r\n}\r\n\r\nfunc main() {\r\n        http.HandleFunc(\"\/v1\/hello\", WithServerHeader(WithAuthCookie(hello)))\r\n        http.HandleFunc(\"\/v2\/hello\", WithServerHeader(WithBasicAuth(hello)))\r\n        http.HandleFunc(\"\/v3\/hello\", WithServerHeader(WithBasicAuth(WithDebugLog(hello))))\r\n        err := http.ListenAndServe(\":8080\", nil)\r\n        if err != nil {\r\n                log.Fatal(\"ListenAndServe: \", err)\r\n        }\r\n}<\/pre>\n<\/div>\n
\n
\u591a\u4e2a\u4fee\u9970\u5668\u7684 Pipeline<\/strong><\/div>\n

\u5728\u4f7f\u7528\u4e0a\uff0c\u9700\u8981\u5bf9\u51fd\u6570\u4e00\u5c42\u5c42\u7684\u5957\u8d77\u6765\uff0c\u770b\u4e0a\u53bb\u597d\u50cf\u4e0d\u662f\u5f88\u597d\u770b\uff0c\u5982\u679c\u9700\u8981 decorator \u6bd4\u8f83\u591a\u7684\u8bdd\uff0c\u4ee3\u7801\u4f1a\u6bd4\u8f83\u96be\u770b\u4e86\u3002\u55ef\uff0c\u6211\u4eec\u53ef\u4ee5\u91cd\u6784\u4e00\u4e0b\u3002<\/p>\n

\u91cd\u6784\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5148\u5199\u4e00\u4e2a\u5de5\u5177\u51fd\u6570\u2014\u2014\u7528\u6765\u904d\u5386\u5e76\u8c03\u7528\u5404\u4e2a decorator\uff1a<\/p>\n

type HttpHandlerDecorator func(http.HandlerFunc) http.HandlerFunc\r\n\r\nfunc Handler(h http.HandlerFunc, decors ...HttpHandlerDecorator) http.HandlerFunc {\r\n        for i := range decors {\r\n                d := decors[len(decors)-1-i] \/\/ iterate in reverse\r\n                h = d(h)\r\n        }\r\n        return h\r\n}<\/pre>\n<\/div>\n

\u7136\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u4f7f\u7528\u4e86\u3002<\/p>\n

http.HandleFunc(\"\/v4\/hello\", Handler(hello,\r\n                WithServerHeader, WithBasicAuth, WithDebugLog))<\/pre>\n

\u8fd9\u6837\u7684\u4ee3\u7801\u662f\u4e0d\u662f\u66f4\u6613\u8bfb\u4e86\u4e00\u4e9b\uff1fpipeline \u7684\u529f\u80fd\u4e5f\u5c31\u51fa\u6765\u4e86\u3002<\/p>\n

\u6cdb\u578b\u7684\u4fee\u9970\u5668<\/strong><\/div>\n

\u4e0d\u8fc7\uff0c\u5bf9\u4e8e Go \u7684\u4fee\u9970\u5668\u6a21\u5f0f\uff0c\u8fd8\u6709\u4e00\u4e2a\u5c0f\u95ee\u9898 \u2014\u2014 \u597d\u50cf\u65e0\u6cd5\u505a\u5230\u6cdb\u578b\uff0c\u5c31\u50cf\u4e0a\u9762\u90a3\u4e2a\u8ba1\u7b97\u65f6\u95f4\u7684\u51fd\u6570\u4e00\u6837\uff0c\u5176\u4ee3\u7801\u8026\u5408\u4e86\u9700\u8981\u88ab\u4fee\u9970\u7684\u51fd\u6570\u7684\u63a5\u53e3\u7c7b\u578b\uff0c\u65e0\u6cd5\u505a\u5230\u975e\u5e38\u901a\u7528\uff0c\u5982\u679c\u8fd9\u4e2a\u4e8b\u89e3\u51b3\u4e0d\u4e86\uff0c\u90a3\u4e48\uff0c\u8fd9\u4e2a\u4fee\u9970\u5668\u6a21\u5f0f\u8fd8\u662f\u6709\u70b9\u4e0d\u597d\u7528\u7684\u3002<\/p>\n

\u56e0\u4e3a Go \u8bed\u8a00\u4e0d\u50cf Python \u548c Java\uff0cPython\u662f\u52a8\u6001\u8bed\u8a00\uff0c\u800c Java \u6709\u8bed\u8a00\u865a\u62df\u673a\uff0c\u6240\u4ee5\u4ed6\u4eec\u53ef\u4ee5\u5e72\u597d\u4e9b\u6bd4\u8f83\u53d8\u6001\u7684\u4e8b\uff0c\u7136\u800c Go \u8bed\u8a00\u662f\u4e00\u4e2a\u9759\u6001\u7684\u8bed\u8a00\uff0c\u8fd9\u610f\u5473\u7740\u5176\u7c7b\u578b\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u5c31\u8981\u641e\u5b9a\uff0c\u5426\u5219\u65e0\u6cd5\u7f16\u8bd1\u3002\u4e0d\u8fc7\uff0cGo \u8bed\u8a00\u652f\u6301\u7684\u6700\u5927\u7684\u6cdb\u578b\u662f\u00a0interface{}<\/span>\u00a0\u8fd8\u6709\u6bd4\u8f83\u7b80\u5355\u7684 reflection \u673a\u5236\uff0c\u5728\u4e0a\u9762\u505a\u505a\u6587\u7ae0\uff0c\u5e94\u8be5\u8fd8\u662f\u53ef\u4ee5\u641e\u5b9a\u7684\u3002<\/p>\n

\u5e9f\u8bdd\u4e0d\u8bf4\uff0c\u4e0b\u9762\u662f\u6211\u7528 reflection \u673a\u5236\u5199\u7684\u4e00\u4e2a\u6bd4\u8f83\u901a\u7528\u7684\u4fee\u9970\u5668\uff08\u4e3a\u4e86\u4fbf\u4e8e\u9605\u8bfb\uff0c\u6211\u5220\u9664\u4e86\u51fa\u9519\u5224\u65ad\u4ee3\u7801\uff09<\/p>\n

func Decorator(decoPtr, fn interface{}) (err error) {\r\n        var decoratedFunc, targetFunc reflect.Value\r\n\r\n        decoratedFunc = reflect.ValueOf(decoPtr).Elem()\r\n        targetFunc = reflect.ValueOf(fn)\r\n\r\n        v := reflect.MakeFunc(targetFunc.Type(),\r\n                func(in []reflect.Value) (out []reflect.Value) {\r\n                        fmt.Println(\"before\")\r\n                        out = targetFunc.Call(in)\r\n                        fmt.Println(\"after\")\r\n                        return\r\n                })\r\n\r\n        decoratedFunc.Set(v)\r\n        return\r\n}<\/pre>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u52a8\u7528\u4e86\u00a0reflect.MakeFunc()<\/span>\u00a0\u51fd\u6570\u5236\u51fa\u4e86\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\u5176\u4e2d\u7684\u00a0targetFunc.Call(in)<\/span>\u00a0\u8c03\u7528\u4e86\u88ab\u4fee\u9970\u7684\u51fd\u6570\u3002\u5173\u4e8e Go \u8bed\u8a00\u7684\u53cd\u5c04\u673a\u5236\uff0c\u63a8\u8350\u5b98\u65b9\u6587\u7ae0 \u2014\u2014 \u300aThe Laws of Reflection<\/a>\u300b\uff0c\u5728\u8fd9\u91cc\u6211\u4e0d\u591a\u8bf4\u4e86\u3002<\/p>\n

\u4e0a\u9762\u8fd9\u4e2a\u00a0Decorator()<\/span>\u00a0\u9700\u8981\u4e24\u4e2a\u53c2\u6570\uff0c<\/p>\n