{"id":10699,"date":"2022-11-22T16:01:30","date_gmt":"2022-11-22T08:01:30","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=10699"},"modified":"2024-12-13T16:56:35","modified_gmt":"2024-12-13T08:56:35","slug":"golang","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/11\/22\/golang\/","title":{"rendered":"golang\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u4e00\u3001\u8bfb\u53d6yml\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e00\u3001\u901a\u8fc7yaml.v2\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u6570\u636e\uff0c\u9700\u8981\u5bfc\u5165yaml.v2\u7684\u5305<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go get gopkg.in\/yaml.v2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u5728config\u6587\u4ef6\u5939\u4e0b\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6config.yml\uff0c\u5185\u5bb9\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"160\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/1-1.png\" alt=\"\" class=\"wp-image-13553\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/1-1.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/1-1-300x74.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/1-1-600x147.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>app\u6a21\u5757\uff0c\u4e0b\u9762\u5305\u542b\u4e24\u4e2a\u5b57\u6bb5host\uff0cport<\/li>\n\n\n\n<li>log\u6a21\u5757\uff1a\u4e0b\u9762\u5305\u542b\u4e00\u4e2a\u5b57\u6bb5maxSize<\/li>\n\n\n\n<li>server\u6a21\u5757\uff1a\u53ea\u6709\u4e00\u4e2a\u503cmysql<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5728config\u6587\u4ef6\u5939\u4e2d\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u5bf9\u5e94\u7684\u7ed3\u6784\u4f53\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"436\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/2-1.png\" alt=\"\" class=\"wp-image-13554\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/2-1.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/2-1-300x201.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/06\/2-1-600x401.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>App\u5b57\u6bb5\uff1a\u7c7b\u578b\u4e3aconfigapp\uff0c\u4e5f\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u5185\u5d4c\u8fdb\u6765<\/li>\n\n\n\n<li>Log\u5b57\u6bb5\uff1a\u7c7b\u578b\u4e3aconfiglog\uff0c\u4e5f\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u5185\u5d4c\u8fdb\u6765<\/li>\n\n\n\n<li>Server\u5b57\u6bb5\uff1a\u7c7b\u578b\u4e3astring\uff0c\u5bf9\u5e94\u7684\u662f\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684server<\/li>\n<\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1a\u4e3a\u4ec0\u4e48\u8981\u901a\u8fc7configapp\u548cconfiglog\u5185\u5d4c\u8fdb\u6765\uff0c\u56e0\u4e3a\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684app\u548clog\u4e3a\u591a\u5c42\u7ea7\u7684\uff0c\u4e0d\u50cfserver\u5c31\u662f\u5355\u7eaf\u7684\u952e\u503c\uff0c\u56e0\u6b64\u9700\u8981\u901a\u8fc7\u7ed3\u6784\u4f53\u7684\u65b9\u5f0f\u5c06app\u548clog\u6620\u5c04\u4e3a\u5bf9\u5e94\u7ed3\u6784\u4f53\u7136\u540e\u5185\u5d4c\u5165Config\u7ed3\u6784\u4f53\u4e2d\uff0cConfig\u7ed3\u6784\u4f53\u6807\u7b7e\u4e2d\u7684app\u3001log\u3001server\u521a\u597d\u5bf9\u5e94\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4e09\u4e2a\u5c42\u7ea7\uff0c\u5fc5\u987b\u8981\u5199\uff0c\u5426\u5219\u53cd\u5e8f\u5217\u5316\u6ca1\u6570\u636e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728config\u5916\u5c42\u521b\u5efa\u6587\u4ef6peizhi.go\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"742\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/9-5.png\" alt=\"\" class=\"wp-image-10708\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/9-5.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/9-5-287x300.png 287w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/9-5-573x600.png 573w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"144\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/10-6.png\" alt=\"\" class=\"wp-image-10709\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/10-6.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/10-6-300x61.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/10-6-600x122.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e8c\u3001<strong>\u4f7f\u7528Viper\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Viper\u53ef\u4ee5\u5904\u7406\u591a\u79cd\u683c\u5f0f\u7684\u914d\u7f6e\uff0c\u76ee\u524d\u5df2\u652f\u6301\u4eceJSON\u3001TOML\u3001YAML\u3001HCL\u3001INI\u548cJava properties\u6587\u4ef6\u4e2d\u8bfb\u53d6\u914d\u7f6e\u6570\u636e\uff0cViper\u8fd8\u80fd\u76d1\u89c6\u914d\u7f6e\u6587\u4ef6\u7684\u53d8\u52a8\u3001\u91cd\u65b0\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u3002\u5728\u9879\u76ee\u4e2d\u53ef\u4ee5\u7528\u4f5c\u70ed\u52a0\u8f7d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go get github.com\/spf13\/viper<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u5728\u4e0a\u9762\u4f8b\u5b50\u57fa\u7840\u4e0a\uff0c\u5176\u4f59\u4e0d\u7528\u52a8\uff0c\u4fee\u6539peizhi.go\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"651\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/12-4.png\" alt=\"\" class=\"wp-image-10715\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/12-4.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/12-4-300x275.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/12-4-600x551.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"137\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/13-3.png\" alt=\"\" class=\"wp-image-10717\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/13-3.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/13-3-300x58.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/13-3-600x116.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>\u9644\u52a0\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4f8b\u5b50\u8bfb\u53d6\u7684\u90fd\u662f\u5355\u4e2a\u914d\u7f6e\uff0c\u5982\u679c\u8981\u8bfb\u53d6\u6570\u636e\u4e3a\u4e00\u4e2a\u5207\u7247\uff0c\u6b64\u65f6\u5e94\u8be5\u600e\u4e48\u529e\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u8bfb\u53d6yaml\u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u5230\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u9996\u5148\u67e5\u770b\u914d\u7f6e\u6587\u4ef6\u5199\u6cd5\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"127\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/12-4.png\" alt=\"\" class=\"wp-image-14240\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/12-4.png 705w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/12-4-300x54.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/12-4-600x108.png 600w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u7684config.go\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"568\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/14-4.png\" alt=\"\" class=\"wp-image-14243\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/14-4.png 704w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/14-4-300x242.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/14-4-600x484.png 600w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\uff1a\u7ed3\u6784\u4f53\u5b57\u6bb5\u540d\u9996\u5b57\u6bcd\u8981\u5927\u5199\uff0c\u5426\u5219\u53cd\u5e8f\u5217\u5316\u4e0d\u6210\u529f\uff0c\u7ed3\u6784\u4f53\u540d\u5b57\u5982\u679c\u4e0d\u9700\u8981\u5bfc\u51fa\u90a3\u5c31\u4e0d\u7528\u5927\u5199<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5b9a\u4e49\u4e3b\u6587\u4ef6\u6765\u8c03\u7528\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"343\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/15-2.png\" alt=\"\" class=\"wp-image-14245\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/15-2.png 706w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/15-2-300x146.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/15-2-600x292.png 600w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"69\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/16.png\" alt=\"\" class=\"wp-image-14247\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/16.png 705w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/16-300x29.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/07\/16-600x59.png 600w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u8bfb\u53d6yml\u914d\u7f6e\u6587\u4ef6 \u65b9\u6cd5\u4e00\u3001\u901a\u8fc7yaml.v2\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u6570\u636e\uff0c\u9700\u8981\u5bfc\u5165yaml.v2\u7684\u5305 1\u3001\u9996\u5148\u5728co [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":10710,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-10699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=10699"}],"version-history":[{"count":19,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10699\/revisions"}],"predecessor-version":[{"id":17795,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10699\/revisions\/17795"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/10710"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=10699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=10699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=10699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}