{"id":1534,"date":"2020-09-21T06:07:28","date_gmt":"2020-09-20T22:07:28","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=1534"},"modified":"2022-02-16T21:58:33","modified_gmt":"2022-02-16T13:58:33","slug":"go-logic-2021ironman","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2020\/09\/21\/go-logic-2021ironman\/","title":{"rendered":"Iris \u9019\u500b\u5728 go \u8a9e\u8a00\u4e0a\u5730\u8868\u6700\u5feb\u7684\u7db2\u9801\u6846\u67b6-\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5"},"content":{"rendered":"<h1>go \u7684\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5<\/h1>\n<p>\u5728\u4ecb\u7d39\u5b8c go \u7684\u8b8a\u6578\u4ee5\u53ca\u5bb9\u5668\uff0c\u63a5\u4e0b\u4f86\u8981\u958b\u59cb\u9032\u5165\u7a0b\u5f0f\u908f\u8f2f\u5224\u65b7\u7684\u90e8\u5206\uff0c\u9019\u90e8\u5206\u5167\u5bb9\u8207\u5927\u90e8\u5206\u8a9e\u8a00\u76f8\u540c\uff0c\u4e0d\u5916\u4e4e\u5c31\u662f<code>if<\/code>\u3001<code>else<\/code>\u3001<code>switch<\/code>\u76f8\u95dc\u7684\u8a9e\u6cd5\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u91dd\u5c0d\u9019\u7d30\u7bc0\u90e8\u5206\u52a0\u4ee5\u8aaa\u660e\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5\u7684\u8aaa\u660e<\/h2>\n<p>\u524d\u9762\u6709\u91dd\u5c0d\u908f\u8f2f\u5224\u65b7\u7684\u8a9e\u6cd5\u505a\u4e00\u500b\u521d\u6b65\u7684\u4ecb\u7d39\uff0c\u6240\u8b02\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5\u4e0d\u5916\u4e4e\u5c31\u662f<code>if<\/code>\u3001<code>else<\/code>\u3001<code>switch<\/code>\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u5206\u5225\u91dd\u5c0d\u671f\u5167\u5bb9\u4f5c\u7d30\u90e8\u7684\u8aaa\u660e\u3002<\/p>\n<h3>if<\/h3>\n<p>\u9019\u90e8\u5206\u5c31\u662f\u7c21\u55ae\u7684\u5982\u679c\u5224\u65b7\u662f\uff0c\u5982\u679c\u6210\u7acb\u5c31\u6703\u57f7\u884c\u5340\u584a\u5167\u7684\u7a0b\u5f0f\uff0c\u8acb\u898b\u4ee5\u4e0b\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n)\n\nfunc main() {\n    odd := 11\n    mod := odd % 2\n    if mod != 0{\n        fmt.Println(odd, &quot;is odd&quot;)\n    }\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u5c31\u662f\u4e00\u500b\u7c21\u55ae\u7684<code>if<\/code>\u5224\u65b7\u5f0f\u7684\u4f8b\u5b50\uff0c\u5176\u4e2d\u7576<code>if<\/code>\u5f8c\u9762\u689d\u4ef6\u6210\u7acb\u6642\u5c31\u6703\u57f7\u884c<code class=\"kb-btn\"><\/code>\u5167\u7684\u7a0b\u5f0f\uff0c\u7136\u800c\u9084\u53ef\u4ee5\u5beb\u6210\u4e0b\u9762\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n)\n\nfunc main() {\n    odd := 11\n    if mod := odd % 2; mod != 0{\n        fmt.Println(odd, &quot;is odd&quot;)\n    }\n}<\/code><\/pre>\n<p>\u7c21\u55ae\u8b1b\u5c31\u662f\u5c07\u8ce6\u503c\uff0c\u8207\u5224\u65b7\u5beb\u5728\u540c\u4e00\u500b\u5340\u584a\uff0c\u518d\u4ee5<code>;<\/code>\u5206\u9694\u958b\u4f86\uff0c\u7576<code>;<\/code>\u5f8c\u9762\u7684\u5224\u65b7\u6210\u7acb\u6642\u5c31\u6703\u57f7\u884c<code class=\"kb-btn\"><\/code>\u7684\u7a0b\u5f0f\u3002<\/p>\n<h3>else<\/h3>\n<p>\u5728\u4ecb\u7d39\u5b8c<code>if<\/code>\u63a5\u4e0b\u4f86\u8ddf\u5927\u5bb6\u4ecb\u7d39<code>else<\/code>\uff0c\u7c21\u55ae\u8aaa\u660e<code>else<\/code>\u5c31\u662f\u7576<code>if<\/code>\u4e0d\u6210\u7acb\u6642\u6703\u5224\u65b7\u7684\u5176\u4ed6\u689d\u4ef6\uff0c\u7576\u689d\u4ef6\u6210\u7acb\u6642\u6703\u57f7\u884c\u5340\u584a\u5167\u7684\u7a0b\u5f0f\u3002\u8a73\u7d30\u8acb\u770b\u4ee5\u4e0b\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    v := 4\n    if v == 1 {\n        fmt.Printf(&quot;%d is 1&quot;, v)\n    } else if v == 2 {\n        fmt.Printf(&quot;%d is 2&quot;, v)\n    } else if v ==3 {\n        fmt.Printf(&quot;%d is 3&quot;, v)\n    } else {\n        fmt.Printf(&quot;%d is else&quot;, v)\n    }\n}<\/code><\/pre>\n<p>\u9019\u88e1\u8981\u6ce8\u610f\u683c\u5f0f\uff0c\u82e5\u662f\u8207\u4e0a\u9762\u4f8b\u5b50\u4e0d\u76f8\u7b26\u6703\u5c0e\u81f4\u65bc\u7de8\u8b6f\u932f\u8aa4\u7684\u554f\u984c\uff0c\u540c\u6642\u9019\u90e8\u5206\u4e5f\u53ef\u4ee5\u518d<code>if<\/code>\u52a0\u5165\u8ce6\u503c\u7684\u9700\u6c42\u7136\u5f8c\u518d<code>;<\/code>\u5f8c\u9762\u52a0\u5165\u5224\u65b7\u5f0f\uff0c\u8a73\u7d30\u8acb\u770b\u4ee5\u4e0b\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    o := 10\n\n    if v := o%3;v == 1 {\n        fmt.Printf(&quot;%d is 1&quot;, v)\n    } else if v == 2 {\n        fmt.Printf(&quot;%d is 2&quot;, v)\n    } else if v ==3 {\n        fmt.Printf(&quot;%d is 3&quot;, v)\n    } else {\n        fmt.Printf(&quot;%d is else&quot;, v)\n    }\n}<\/code><\/pre>\n<p>\u518d\u4f8b\u5b50\u5167<code>v<\/code>\u9019\u8b8a\u6578\u53ea\u5b58\u5728<code>if<\/code>\u3001<code>else<\/code>\u7684\u5224\u65b7\u5f0f\u4e4b\u5167\uff0c\u6240\u4ee5\u62ff\u5230\u5e95\u4e0b\u4f7f\u7528\u6703\u9020\u6210\u7de8\u8b6f\u5931\u6557\u7684\u72c0\u6cc1\u3002\u5230\u76ee\u524d\u70ba\u6b62<code>if<\/code>\u3001<code>else<\/code>\u7684\u4ecb\u7d39\u5c07\u544a\u4e00\u6bb5\u843d\uff0c\u63a5\u4e0b\u4f86\u8981\u4ecb\u7d39<code>switch<\/code>\u7684\u5224\u65b7\u5f0f\u3002<\/p>\n<h3>switch<\/h3>\n<p>\u5c31\u5982\u540c<code>if<\/code>\u3001<code>else<\/code>\u4e00\u6a23\uff0c<code>switch<\/code>\u7684\u5224\u65b7\u5f0f\u662f\u6aa2\u67e5\u8b8a\u6578\u662f\u5426\u8207<code>case<\/code>\u5f8c\u7684\u503c\u76f8\u540c\uff0c\u7576\u76f8\u540c\u5c31\u6703\u57f7\u884c\u5340\u584a\u5167\u7684\u7a0b\u5f0f\uff0c\u8a73\u7d30\u8acb\u770b\u4e0b\u5217\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    switch os := &quot;Other&quot;; os {\n    case &quot;First&quot;:\n        fmt.Println(&quot;First.&quot;)\n    case &quot;Second&quot;:\n        fmt.Println(&quot;Second.&quot;)\n    default:\n        \/\/ freebsd, openbsd,\n        \/\/ plan9, windows...\n        fmt.Printf(&quot;%s.\\n&quot;, os)\n    }\n}<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4f8b\u5b50\u4e3b\u8981\u662f\u5728<code>switch<\/code>\u5f8c\u9762\u6709\u4e00\u500b\u8ce6\u503c\u7684\u5f0f\u5b50\u63a5\u4e0b\u4f86\u4ee5<code>;<\/code>\u4f86\u5340\u9694\uff0c\u5728<code>;<\/code>\u5f8c\u662f\u63a5\u8457\u8981\u5224\u65b7\u7684\u8b8a\u6578<code>go<\/code>\uff0c\u800c<code>case<\/code>\u5f8c\u662f\u653e\u8457\u6bd4\u5c0d\u7684\u5167\u5bb9\uff0c\u5982\u679c<code>go<\/code>\u7684\u5167\u5bb9\u8207<code>case<\/code>\u5f8c\u7684\u503c\u76f8\u540c\u5247\u6703\u57f7\u884c<code>case<\/code>\u8207<code>case<\/code>\u4e4b\u9593\u7684\u7a0b\u5f0f\uff0c\u5982\u679c\u6700\u5f8c\u90fd\u6c92\u6210\u7acb\u6703\u57f7\u884c<code>default<\/code>\u7684\u7a0b\u5f0f\uff0c\u9084\u6709\u6bd4\u8f03\u7279\u5225\u7684\u5730\u65b9\u662f\u5c0d\u65bc<code>go<\/code>\u800c\u8a00<code>case<\/code>\u8207<code>case<\/code>\u4e4b\u9593\u4e0d\u9700\u8981<code>break<\/code>\u9694\u958b\u3002\u4f46\u662f\u4ee5\u4e0b\u4f8b\u5b50\u5c31\u6703\u9020\u6210\u908f\u8f2f\u5224\u65b7\u932f\u8aa4<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    switch os := &quot;Second&quot;; os {\n    case &quot;First&quot;:\n    case &quot;Second&quot;:\n        fmt.Println(&quot;First and Second.&quot;)\n    default:\n        \/\/ freebsd, openbsd,\n        \/\/ plan9, windows...\n        fmt.Printf(&quot;%s.\\n&quot;, os)\n    }\n}<\/code><\/pre>\n<p>\u90a3\u8981\u5982\u4f55\u4fee\u6539\u4e0a\u8ff0\u4f8b\u5b50\u5462\uff0c\u5c31\u628a\u4ed6\u7576<code>if<\/code>\u3001<code>else<\/code>\u4f86\u4f7f\u7528\u5373\u53ef\uff0c\u5c31\u662f\u4e0d\u8981\u5728<code>switch<\/code>\u7d66\u689d\u4ef6\u5f0f\uff0c\u800c\u5728<code>case<\/code>\u5167\u5beb\u5224\u65b7\u5f0f\uff0c\u5982\u4e0b\u5217\u4f8b\u5b50\u6240\u793a<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    os := &quot;Fourth&quot;\n    switch  {\n    case os == &quot;First&quot; || os == &quot;Second&quot;:\n        fmt.Println(&quot;First and Second.&quot;)\n    case os == &quot;Third&quot; || os == &quot;Fourth&quot;:\n        fmt.Println(&quot;Third and Fourth.&quot;)\n    default:\n        \/\/ freebsd, openbsd,\n        \/\/ plan9, windows...\n        fmt.Printf(&quot;%s.\\n&quot;, os)\n    }\n}<\/code><\/pre>\n<p>\u9664\u4e86\u4e0a\u8ff0\u7684\u4f8b\u5b50\u4e4b\u5916<code>switch<\/code>\u9084\u6709\u4e00\u500b\u8981\u6ce8\u610f\u7684\u9ede\u662f\uff0c\u5224\u65b7\u5f0f\u7684\u9806\u5e8f\u662f\u7531\u4e0a\u800c\u4e0b\uff0c\u5982\u679c\u5176\u4e2d\u4e00\u500bcase\u6210\u7acb\u5f8c\u5c31\u6703\u57f7\u884c\u5176\u4e2d\u7684\u7a0b\u5f0f\u4e26\u4e14\u96e2\u958b<code>switch<\/code>\u5224\u65b7\u5f0f\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u9019\u7bc7\u7684\u5167\u5bb9\u4e3b\u8981\u662f\u4ecb\u7d39 go \u7684\u908f\u8f2f\u5224\u65b7\u5f0f\uff0c\u4e26\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b go \u7684\u908f\u8f2f\u5224\u65b7\u5f0f\u8207\u5176\u4ed6\u8a9e\u8a00\u7684\u5dee\u7570\u3002\u63a5\u4e0b\u4f86\u4e0b\u4e00\u7bc7\u8981\u958b\u59cb\u8ddf\u5927\u5bb6\u5206\u4eab go \u7684\u8ff4\u5708\u5224\u65b7\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>go \u7684\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5 \u5728\u4ecb\u7d39\u5b8c go \u7684\u8b8a\u6578\u4ee5\u53ca\u5bb9\u5668\uff0c\u63a5\u4e0b\u4f86\u8981\u958b\u59cb\u9032\u5165\u7a0b\u5f0f\u908f\u8f2f\u5224\u65b7\u7684\u90e8\u5206\uff0c\u9019\u90e8\u5206\u5167\u5bb9\u8207\u5927\u90e8\u5206\u8a9e &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2020\/09\/21\/go-logic-2021ironman\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Iris \u9019\u500b\u5728 go \u8a9e\u8a00\u4e0a\u5730\u8868\u6700\u5feb\u7684\u7db2\u9801\u6846\u67b6-\u908f\u8f2f\u5224\u65b7\u8a9e\u6cd5\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[158,81],"class_list":["post-1534","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2020ironman","tag-go"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=1534"}],"version-history":[{"count":3,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1534\/revisions"}],"predecessor-version":[{"id":2685,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1534\/revisions\/2685"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=1534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=1534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=1534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}