{"id":206763,"date":"2025-06-12T10:36:26","date_gmt":"2025-06-12T02:36:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206763\/"},"modified":"2025-06-12T10:36:26","modified_gmt":"2025-06-12T02:36:26","slug":"go-%e4%b8%ad%e4%bd%bf%e7%94%a8-fastwalk-%e6%97%b6%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-undefined-walkfn-%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206763\/","title":{"rendered":"Go \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732247499673fffcbb2823.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u5982\u4f55\u5728 go \u4e2d\u4f7f\u7528 fastwalk<\/strong>,fastwalk \u662f\u4e00\u4e2a go \u5e93\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u904d\u5386\u6587\u4ef6\u5939\u53ca\u5176\u5b50\u76ee\u5f55\u3002\u5b83\u6709\u4e00\u4e2a walk \u51fd\u6570\uff0c\u9700\u8981\u4e00\u4e2a\u914d\u7f6e\u548c\u4e00\u4e2a\u56de\u8c03\u51fd\u6570 walkfn \u6765\u6267\u884c\u3002,<br \/>\n<strong>\u95ee\u9898\uff1a<\/strong>,\u5728\u4f7f\u7528 fastwalk \u65f6\uff0c\u51fa\u73b0 &#8220;undefined: walkfn&#8221; \u7684\u9519\u8bef\u3002\u5982\u4f55\u5b9a\u4e49\u6b63\u786e\u7684 walkfn \u51fd\u6570\uff1f,<br \/>\n<strong>\u7b54\u6848\uff1a<\/strong>,walkfn \u51fd\u6570\u5fc5\u987b\u5728 := \u8bed\u53e5\u7ed3\u675f\u540e\u5b9a\u4e49\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u6539\u540e\u7684\u4ee3\u7801\u6765\u4fee\u590d\u9519\u8bef\uff1a,\u8fd9\u6837\uff0cfastwalk.walk() \u51fd\u6570\u5c06\u4f7f\u7528\u6b63\u786e\u5b9a\u4e49\u7684 walkfn \u56de\u8c03\u51fd\u6570\u3002,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002,\u5982\u4f55\u5728 go \u4e2d\u4f7f\u7528 fastwalk,\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>Go \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f<\/span><\/p>\n<h1>Go \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f<\/h1>\n<p><span>2024-11-22 11:51:55<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u4e2d\u4f7f\u7528 fastwalk \u65f6\u5982\u4f55\u89e3\u51b3 \u201cundefined: walkFn\u201d \u9519\u8bef\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732247499673fffcbb2823.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5728 go \u4e2d\u4f7f\u7528 fastwalk<\/strong><\/p>\n<p>fastwalk \u662f\u4e00\u4e2a go \u5e93\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u904d\u5386\u6587\u4ef6\u5939\u53ca\u5176\u5b50\u76ee\u5f55\u3002\u5b83\u6709\u4e00\u4e2a walk \u51fd\u6570\uff0c\u9700\u8981\u4e00\u4e2a\u914d\u7f6e\u548c\u4e00\u4e2a\u56de\u8c03\u51fd\u6570 walkfn \u6765\u6267\u884c\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 fastwalk \u65f6\uff0c\u51fa\u73b0 &#8220;undefined: walkfn&#8221; \u7684\u9519\u8bef\u3002\u5982\u4f55\u5b9a\u4e49\u6b63\u786e\u7684 walkfn \u51fd\u6570\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>walkfn \u51fd\u6570\u5fc5\u987b\u5728 := \u8bed\u53e5\u7ed3\u675f\u540e\u5b9a\u4e49\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u6539\u540e\u7684\u4ee3\u7801\u6765\u4fee\u590d\u9519\u8bef\uff1a<\/p>\n<pre>func main() {\n    conf := fastwalk.Config{\n        Follow: false,\n    }\n    var data_temp []string\n\n    var walkFn func(path string, d fs.DirEntry, err error) error \/\/ \u5b9a\u4e49 walkFn\n\n    walkFn = func(path string, d fs.DirEntry, err error) error {\n        if err != nil {\n            return nil\n        }\n\n        if d.IsDir() {\n            data_temp = append(data_temp, path+\"\\\\\")\n            return fastwalk.Walk(&amp;conf, path, walkFn)\n        }\n        data_temp = append(data_temp, path)\n        return nil\n    }\n\n    _ := fastwalk.Walk(&amp;conf, \"\u6587\u4ef6\u5939\u8def\u5f84\", walkFn)\n\n    fmt.Println(data_temp)\n}<\/pre>\n<p>\u8fd9\u6837\uff0cfastwalk.walk() \u51fd\u6570\u5c06\u4f7f\u7528\u6b63\u786e\u5b9a\u4e49\u7684 walkfn \u56de\u8c03\u51fd\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u600e\u4e48\u7981\u6b62Win10\u66f4\u65b0Win11 Win10\u8bbe\u7f6e\u4e0d\u66f4\u65b0Win11\u7684\u65b9\u6cd5\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4e3a\u4ec0\u4e48&#8220;\u6807\u7b7e\u7684`display: inline-block`\u4f1a\u8ba9\u7236\u5143\u7d20\u6709\u9ad8\u5ea6\uff0c\u800c`display: inline`\u5374\u8ba9\u7236\u5143\u7d20\u9ad8\u5ea6\u4e3a0\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0 &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-206763","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=206763"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206763\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}