{"id":207035,"date":"2025-07-08T08:12:07","date_gmt":"2025-07-08T00:12:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207035\/"},"modified":"2025-07-08T08:12:07","modified_gmt":"2025-07-08T00:12:07","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e5%9c%a8-golang-%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%8c%89%e4%bd%8d-and-%e8%bf%9b%e8%a1%8c%e6%af%94%e8%be%83%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207035\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u5728 golang \u4e2d\u4f7f\u7528\u6309\u4f4d AND \u8fdb\u884c\u6bd4\u8f83\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u4e3a\u4ec0\u4e48\u5728 golang \u4e2d\u4f7f\u7528\u6309\u4f4d AND \u8fdb\u884c\u6bd4\u8f83\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 16:42:28<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4e3a\u4ec0\u4e48\u5728 golang \u4e2d\u4f7f\u7528\u6309\u4f4d AND \u8fdb\u884c\u6bd4\u8f83\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u9605\u8bfb\u8fd9\u6837\u7684\u4e00\u6bb5\u4ee3\u7801\uff08\u53d6\u81ea fsnotify\uff09\uff1a<\/p>\n<pre>type Op uint32\n\n    const (\n        Create Op = 1 &lt;&lt; iota\n        Write\n        Remove\n        Rename\n        Chmod\n    )\n\n    ...\n\n    func (op Op) String() string {\n\n    var buffer bytes.Buffer\n\n    if op&amp;Create == Create {\n        buffer.WriteString(\"|CREATE\")\n    }\n    if op&amp;Remove == Remove {\n        buffer.WriteString(\"|REMOVE\")\n    }\n    if op&amp;Write == Write {\n        buffer.WriteString(\"|WRITE\")\n    }\n    if op&amp;Rename == Rename {\n        buffer.WriteString(\"|RENAME\")\n    }\n    if op&amp;Chmod == Chmod {\n        buffer.WriteString(\"|CHMOD\")\n    }\n    if buffer.Len() == 0 {\n        return \"\"\n    }\n    return buffer.String()[1:] \n}<\/pre>\n<p>\u6211\u7684\u65b0\u624b\u95ee\u9898\u662f\u4e3a\u4ec0\u4e48\u6709\u4eba\u4f1a\u4f7f\u7528\u50cf <code>op&amp;remove == remove<\/code> \u8fd9\u6837\u7684\u6309\u4f4d and \u8fd0\u7b97\u6765\u5b9e\u9645\u8fdb\u884c\u6bd4\u8f83\u3002 \u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u6bd4\u8f83\u64cd\u4f5c\u548c\uff08\u521b\u5efa|\u5220\u9664|&#8230;\uff09\u503c\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u8fd9\u662f \u7684\u793a\u4f8b\u3002\u4ed6\u4eec\u6b63\u5728\u505a\u7684\u662f\u5b9a\u4e49\u4e00\u7cfb\u5217\u63a9\u7801\uff08\u521b\u5efa\u3001\u5220\u9664\u3001\u5199\u5165\uff09\uff0c\u8fd9\u4e9b\u63a9\u7801\u662f\u6574\u6570 1\u30012\u30014\u30018\u300116\u300132 \u7b49\u3002\u60a8\u4f20\u5165\u4e00\u4e2a\u64cd\u4f5c\u503c\uff0c\u8be5\u64cd\u4f5c\u503c\u53ef\u4ee5\u6709\u591a\u4e2a\u64cd\u4f5c\uff0c\u5b83\u4f1a\u6839\u636e\u7ffb\u8f6c\u7684\u4f4d\u6765\u786e\u5b9a\u8981\u6267\u884c\u54ea\u4e2a\u64cd\u4f5c\u3002\u5982\u679c\u60a8\u4ee5\u6309\u4f4d\u6a21\u5f0f\u601d\u8003\u8fd9\u4e9b\u6570\u5b57\uff0c\u8fd9\u5c31\u66f4\u6709\u610f\u4e49\u4e86\u3002 4 == 00000100\uff0c\u5220\u9664\u7684\u503c\u3002\u5982\u679c\u60a8\u4f20\u5165\u64cd\u4f5c\u7801 6\uff0c\u5219\u5f53\u60a8\u6bd4\u8f83 00000110 &amp;&amp; 00000100 == 00000100 \u65f6\uff0c\u60a8\u4f1a\u5f97\u5230 true\uff0c\u56e0\u4e3a\u7279\u5b9a\u4e8e\u201cRemove\u201d\u7684\u4f4d\uff08\u7b2c\u4e09\u4e2a\u6700\u4f4e\u6709\u6548\u4f4d\uff09\u662f 1\u3002<\/p>\n<p>\u7528\u4e00\u79cd\u4e0d\u592a\u884c\u8bdd\u548c\u5177\u4f53\u7684\u65b9\u5f0f\u6765\u8bf4\uff0c\u8fd9\u57fa\u672c\u4e0a\u662f\u4e00\u79cd\u7528\u4e00\u4e2a\u5b57\u8282\u4f20\u9012\u591a\u4e2a\u64cd\u4f5c\u7801\u7684\u65b9\u6cd5\u3002\u4ed6\u4eec\u8fdb\u884c\u6309\u4f4d\u4e0e\u7136\u540e\u6bd4\u8f83\u7684\u539f\u56e0\u662f\u56e0\u4e3a\u5b83\u5141\u8bb8\u4ed6\u4eec\u68c0\u67e5\u7279\u5b9a\u4f4d\u662f\u5426\u88ab\u7ffb\u8f6c\uff0c\u800c\u5ffd\u7565\u5176\u4f59\u4f4d\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u4e3a\u4ec0\u4e48\u5728 golang \u4e2d\u4f7f\u7528\u6309\u4f4d AND \u8fdb\u884c\u6bd4\u8f83\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#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-207035","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207035","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=207035"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207035\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}