{"id":41625,"date":"2024-12-01T11:20:12","date_gmt":"2024-12-01T03:20:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41625\/"},"modified":"2024-12-01T11:20:12","modified_gmt":"2024-12-01T03:20:12","slug":"go-%e8%bf%94%e5%9b%9e%e7%bb%93%e6%9e%84%e9%94%ae%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41625\/","title":{"rendered":"Go \u8fd4\u56de\u7ed3\u6784\u952e\u503c"},"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>Go \u8fd4\u56de\u7ed3\u6784\u952e\u503c<\/span><\/p>\n<h1>Go \u8fd4\u56de\u7ed3\u6784\u952e\u503c<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 20: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>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u8fd4\u56de\u7ed3\u6784\u952e\u503c\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u8bf7\u5e2e\u52a9\u7406\u89e3\uff0c\u6211\u5982\u4f55\u4ece\u51fd\u6570\u4e2d\u4e0d\u4ec5\u8fd4\u56de\u7ed3\u6784\u4e2d\u7684\u503c\uff0c\u8fd8\u8fd4\u56de\u5b83\u4eec\u7684\u540d\u79f0\uff1f<\/p>\n<p>\u793a\u4f8b\u6211\u7684 arg.go<\/p>\n<pre>package flags\n\nimport (\n    \"flag\"\n)\n\ntype flagsstruct struct {\n    argtest1  string\n    argtest2   string\n}\n\nfunc getinitflags() *flagsstruct {\n\n    flags := new(flagsstruct)\n\n    flag.stringvar(&amp;flags.argtest1, \"test1\", \"test1\", \"c\")\n    flag.stringvar(&amp;flags.argtest2, \"test2\", \"test2\", \"t\")\n\n    flag.parse()\n\n    return flags\n\n}<\/pre>\n<p>\u5b83\u4ec5\u9002\u7528\u4e8e\u6309\u952e\uff0c\u4f8b\u5982\u5728\u6211\u5c1d\u8bd5\u6253\u5370\u7684\u4e3b\u51fd\u6570\u4e2d\uff0c\u5b83\u6b63\u5728\u5de5\u4f5c\uff1a<\/p>\n<pre>fmt.print(*inputflags)<\/pre>\n<p> {\u6d4b\u8bd51\u6d4b\u8bd52} <\/p>\n<p>\u4f46\u662f\u6211\u600e\u6837\u624d\u80fd\u6253\u5370\u51fa\u8fd9\u6837\u7684\u4e1c\u897f\u5462\uff1f<\/p>\n<pre>fmt.Printf(inputFlags.argTest2)<\/pre>\n<p> .\/main.go:25:24: inputflags.argtest2 \u672a\u5b9a\u4e49\uff08\u65e0\u6cd5\u5f15\u7528 \u672a\u5bfc\u51fa\u7684\u5b57\u6bb5\u6216\u65b9\u6cd5 argtest2) <\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4f7f\u53c2\u6570\u540d\u79f0\u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934 (<code>ArgTest2<\/code>)\u3002\u8bf7\u53c2\u9605  \u4e86\u89e3\u66f4\u591a\u8be6\u60c5\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aGo \u8fd4\u56de\u7ed3\u6784\u952e\u503c\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; Go \u8fd4\u56de\u7ed3\u6784\u952e\u503c Go \u8fd4\u56de\u7ed3\u6784\u952e\u503c \u6765\u6e90\uff1astackoverflow 2024-04-20 20:51:55 0\u6d4f\u89c8 \u6536\u85cf \u4f60\u5728\u5b66\u4e60Golang\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587\u300aGo \u8fd4\u56de\u7ed3\u6784\u952e\u503c\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01 \u95ee\u9898\u5185\u5bb9 \u8bf7\u5e2e\u52a9\u7406\u89e3\uff0c\u6211\u5982\u4f55\u4ece\u51fd\u6570\u4e2d\u4e0d\u4ec5\u8fd4\u56de\u7ed3\u6784\u4e2d\u7684\u503c\uff0c\u8fd8\u8fd4\u56de\u5b83\u4eec\u7684\u540d\u79f0\uff1f \u793a\u4f8b\u6211\u7684 arg.go package flags import ( &#8220;flag&#8221; ) type flagsstruct struct { argtest1 string argtest2 string } func getinitflags() *flagsstruct { flags := new(flagsstruct) flag.stringvar(&amp;flags.argtest1, &#8220;test1&#8221;, &#8220;test1&#8221;, &#8220;c&#8221;) flag.stringvar(&amp;flags.argtest2, &#8220;test2&#8221;, &#8220;test2&#8221;, &#8220;t&#8221;) flag.parse() return flags } \u5b83\u4ec5\u9002\u7528\u4e8e\u6309\u952e\uff0c\u4f8b\u5982\u5728\u6211\u5c1d\u8bd5\u6253\u5370\u7684\u4e3b\u51fd\u6570\u4e2d\uff0c\u5b83\u6b63\u5728\u5de5\u4f5c\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41625","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=41625"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41625\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}