{"id":57842,"date":"2024-10-10T21:36:22","date_gmt":"2024-10-10T13:36:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57842\/"},"modified":"2024-10-10T21:36:22","modified_gmt":"2024-10-10T13:36:22","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80-bool-%e9%a1%9e%e5%9e%8b%ef%bc%88%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57842\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00 bool \u985e\u578b\uff08\u5e03\u723e\u985e\u578b\uff09"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80-bool-%e9%a1%9e%e5%9e%8b%ef%bc%88%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%ef%bc%89-bzPMpEpzny\">GO\u6559\u7a0b: Go \u8a9e\u8a00 bool \u985e\u578b\uff08\u5e03\u723e\u985e\u578b\uff09<\/h1>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u5e03\u723e\u985e\u578b\uff08bool\uff09\u662f\u4e00\u500b\u57fa\u672c\u6578\u64da\u985e\u578b\uff0c\u7528\u65bc\u8868\u793a\u771f\uff08true\uff09\u6216\u5047\uff08false\uff09\u7684\u908f\u8f2f\u503c\u3002\u9019\u500b\u985e\u578b\u5728\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u3001\u689d\u4ef6\u5224\u65b7\u548c\u908f\u8f2f\u904b\u7b97\u4e2d\u626e\u6f14\u8457\u91cd\u8981\u7684\u89d2\u8272\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Go \u8a9e\u8a00\u4e2d\u7684\u5e03\u723e\u985e\u578b\uff0c\u5305\u62ec\u5176\u5b9a\u7fa9\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u76f8\u95dc\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e5%ae%9a%e7%be%a9-bzPMpEpzny\">\u5e03\u723e\u985e\u578b\u7684\u5b9a\u7fa9<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u5e03\u723e\u985e\u578b\u7684\u5b9a\u7fa9\u975e\u5e38\u7c21\u55ae\u3002\u5b83\u53ea\u6709\u5169\u500b\u53ef\u80fd\u7684\u503c\uff1atrue \u548c false\u3002\u9019\u4f7f\u5f97\u5e03\u723e\u985e\u578b\u5728\u908f\u8f2f\u904b\u7b97\u4e2d\u975e\u5e38\u76f4\u89c0\u4e14\u6613\u65bc\u4f7f\u7528\u3002<\/p>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e8%81%b2%e6%98%8e%e8%88%87%e5%88%9d%e5%a7%8b%e5%8c%96-bzPMpEpzny\">\u5e03\u723e\u985e\u578b\u7684\u8072\u660e\u8207\u521d\u59cb\u5316<\/h2>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u5e03\u723e\u985e\u578b\u7684\u8b8a\u91cf\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u65b9\u5f0f\u8072\u660e\u548c\u521d\u59cb\u5316\uff1a<\/p>\n<pre><code>var isActive bool = true\nvar isAvailable bool \/\/ \u9ed8\u8a8d\u503c\u70ba false\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u78bc\u4e2d\uff0c\u7b2c\u4e00\u884c\u8072\u660e\u4e86\u4e00\u500b\u540d\u70ba isActive \u7684\u5e03\u723e\u8b8a\u91cf\u4e26\u521d\u59cb\u5316\u70ba true\uff0c\u800c\u7b2c\u4e8c\u884c\u8072\u660e\u4e86\u4e00\u500b\u540d\u70ba isAvailable \u7684\u5e03\u723e\u8b8a\u91cf\uff0c\u56e0\u70ba\u6c92\u6709\u521d\u59cb\u5316\uff0c\u6240\u4ee5\u5176\u9ed8\u8a8d\u503c\u70ba false\u3002<\/p>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e4%bd%bf%e7%94%a8-bzPMpEpzny\">\u5e03\u723e\u985e\u578b\u7684\u4f7f\u7528<\/h2>\n<p>\u5e03\u723e\u985e\u578b\u5728\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u7279\u5225\u662f\u5728\u689d\u4ef6\u8a9e\u53e5\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u4f7f\u7528\u5834\u666f\uff1a<\/p>\n<h3 id=\"%e6%a2%9d%e4%bb%b6%e8%aa%9e%e5%8f%a5-bzPMpEpzny\">\u689d\u4ef6\u8a9e\u53e5<\/h3>\n<p>\u5e03\u723e\u985e\u578b\u5e38\u7528\u65bc if \u8a9e\u53e5\u4e2d\uff0c\u4ee5\u6c7a\u5b9a\u662f\u5426\u57f7\u884c\u67d0\u6bb5\u4ee3\u78bc\uff1a<\/p>\n<pre><code>if isActive {\n    fmt.Println(\"\u7cfb\u7d71\u5df2\u555f\u7528\")\n} else {\n    fmt.Println(\"\u7cfb\u7d71\u672a\u555f\u7528\")\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c isActive \u7684\u503c\u70ba true\uff0c\u5247\u6703\u8f38\u51fa\u201c\u7cfb\u7d71\u5df2\u555f\u7528\u201d\uff1b\u5426\u5247\uff0c\u8f38\u51fa\u201c\u7cfb\u7d71\u672a\u555f\u7528\u201d\u3002<\/p>\n<h3 id=\"%e9%82%8f%e8%bc%af%e9%81%8b%e7%ae%97-bzPMpEpzny\">\u908f\u8f2f\u904b\u7b97<\/h3>\n<p>Go \u8a9e\u8a00\u652f\u6301\u591a\u7a2e\u908f\u8f2f\u904b\u7b97\u7b26\uff0c\u5305\u62ec AND\uff08&amp;&amp;\uff09\u3001OR\uff08||\uff09\u548c NOT\uff08!\uff09\u3002\u9019\u4e9b\u904b\u7b97\u7b26\u53ef\u4ee5\u7528\u4f86\u7d44\u5408\u5e03\u723e\u8868\u9054\u5f0f\uff1a<\/p>\n<pre><code>isActive := true\nisAvailable := false\n\nif isActive &amp;&amp; isAvailable {\n    fmt.Println(\"\u7cfb\u7d71\u53ef\u7528\")\n} else {\n    fmt.Println(\"\u7cfb\u7d71\u4e0d\u53ef\u7528\")\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u53ea\u6709\u7576 isActive \u548c isAvailable \u90fd\u70ba true \u6642\uff0c\u624d\u6703\u8f38\u51fa\u201c\u7cfb\u7d71\u53ef\u7528\u201d\u3002\u5982\u679c\u5176\u4e2d\u4e00\u500b\u70ba false\uff0c\u5247\u6703\u8f38\u51fa\u201c\u7cfb\u7d71\u4e0d\u53ef\u7528\u201d\u3002<\/p>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-bzPMpEpzny\">\u5e03\u723e\u985e\u578b\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528\u5e03\u723e\u985e\u578b\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u5e03\u723e\u985e\u578b\u4e0d\u80fd\u8207\u6574\u6578\u6216\u5176\u4ed6\u6578\u64da\u985e\u578b\u76f4\u63a5\u9032\u884c\u6bd4\u8f03\u6216\u904b\u7b97\u3002<\/li>\n<li>\u5728\u689d\u4ef6\u8a9e\u53e5\u4e2d\uff0c\u5e03\u723e\u8868\u9054\u5f0f\u5fc5\u9808\u8fd4\u56de true \u6216 false\u3002<\/li>\n<li>\u5e03\u723e\u985e\u578b\u7684\u9ed8\u8a8d\u503c\u70ba false\uff0c\u9019\u5728\u521d\u59cb\u5316\u8b8a\u91cf\u6642\u9700\u8981\u7279\u5225\u6ce8\u610f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-bzPMpEpzny\">\u7e3d\u7d50<\/h2>\n<p>Go \u8a9e\u8a00\u4e2d\u7684\u5e03\u723e\u985e\u578b\u662f\u4e00\u500b\u7c21\u55ae\u800c\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u5728\u7a0b\u5e8f\u4e2d\u9032\u884c\u908f\u8f2f\u5224\u65b7\u548c\u63a7\u5236\u6d41\u7a0b\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528\u5e03\u723e\u985e\u578b\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u7de8\u5beb\u51fa\u66f4\u6e05\u6670\u3001\u66f4\u9ad8\u6548\u7684\u4ee3\u78bc\u3002\u5982\u679c\u60a8\u5c0d\u65bc\u4f3a\u670d\u5668\u7684\u9700\u6c42\u6709\u8208\u8da3\uff0c\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u53ef\u4ee5\u5728\u6211\u5011\u7684\u7db2\u7ad9\u4e0a\u627e\u5230\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 Go \u8a9e\u8a00\u4e2d\u7684 bool \u985e\u578b\uff0c\u5b78\u7fd2\u5176\u5b9a\u7fa9\u3001\u7528\u6cd5\u53ca\u5728\u7a0b\u5f0f\u8a2d\u8a08\u4e2d\u7684\u61c9\u7528\uff0c\u63d0\u5347\u4f60\u7684\u7de8\u7a0b\u6280\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-57842","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57842","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=57842"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57842\/revisions"}],"predecessor-version":[{"id":57843,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57842\/revisions\/57843"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}