{"id":14685,"date":"2023-09-06T15:16:39","date_gmt":"2023-09-06T07:16:39","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=14685"},"modified":"2023-09-11T11:31:04","modified_gmt":"2023-09-11T03:31:04","slug":"go-9","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2023\/09\/06\/go-9\/","title":{"rendered":"Go\u8bed\u8a00\u4e4b\u5c01\u88c5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Golang\u662f\u4e00\u95e8\u975e\u5e38\u4f18\u79c0\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e9b\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u5c01\u88c5\u3002\u5c01\u88c5\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09\u7684\u6982\u5ff5\uff0c\u5b83\u6307\u7684\u662f\u9690\u85cf\u5bf9\u8c61\u7684\u5185\u90e8\u7ec6\u8282\uff0c\u4f7f\u5f97\u5bf9\u8c61\u53ea\u5bf9\u5916\u66b4\u9732\u5fc5\u9700\u7684\u884c\u4e3a\uff0c\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u5b89\u5168\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c01\u88c5\u7684\u5b9e\u73b0\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06\u7ed3\u6784\u4f53\u540d\u3001\u7ed3\u6784\u4f53\u5b57\u6bb5\u3001\u53d8\u91cf\u7b49\u7684\u9996\u5b57\u6bcd\u5c0f\u5199\uff0c\u4e0d\u80fd\u5bfc\u51fa\uff0c\u5176\u4ed6\u5305\u65e0\u6cd5\u4f7f\u7528\uff0c\u53d8\u4e3a\u79c1\u6709<\/li>\n\n\n\n<li>\u7ed9\u7ed3\u6784\u4f53\u6240\u5728\u5305\u63d0\u4f9b\u4e00\u4e2a\u5de5\u7a0b\u6a21\u5f0f\u7684\u51fd\u6570\uff0c\u9996\u5b57\u6bcd\u5927\u5199\u3002\u7c7b\u4f3c\u6784\u9020\u4e00\u4e2a\u51fd\u6570<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e00\u4e2a\u9996\u5b57\u6bcd\u5927\u5199\u7684Set\u65b9\u6cd5(\u7c7b\u4f3c\u5176\u4ed6\u8bed\u8a00\u7684public)\uff0c\u7528\u4e8e\u5bf9\u5c5e\u6027\u5224\u65ad\u5e76\u8d4b\u503c<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e00\u4e2a\u9996\u5b57\u6bcd\u5927\u5199\u7684Get\u65b9\u6cd5(\u7c7b\u4f3c\u5176\u4ed6\u8bed\u8a00\u7684public)\uff0c\u7528\u4e8e\u83b7\u53d6\u5c5e\u6027\u7684\u503c&nbsp; <strong>&nbsp; &nbsp;<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u65e5\u671f\u7ed3\u6784\u4f53\uff0c\u5305\u542b\u4e09\u4e2a\u5b57\u6bb5\u5e74\u6708\u65e5\uff0c\u7136\u540e\u5b9e\u4f8b\u5316\u8d4b\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"446\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-2.png\" alt=\"\" class=\"wp-image-14690\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-2.png 705w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-2-300x190.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-2-600x380.png 600w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"111\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-1.png\" alt=\"\" class=\"wp-image-14691\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-1.png 701w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-1-300x48.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-1-600x95.png 600w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u5e74\u6708\u65e5\u53ef\u4ee5\u968f\u610f\u8bbe\u7f6e\uff0c\u8fd9\u6839\u672c\u4e0d\u7b26\u5408\u5b89\u5168\u6027\u539f\u5219\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4efb\u4f55\u503c\uff0c\u5e74\u53ef\u80fd\u88ab\u8bbe\u7f6e\u4e3a0\u5230-999\uff0c\u6708\u53ef\u80fd\u88ab\u8bbe\u7f6e\u4e3a1-1000\uff0c\u65e5\u4e5f\u53ef\u80fd\u88ab\u8bbe\u7f6e\u4e3a1-888\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u8fdb\u884c\u5c01\u88c5\uff0c\u4ee5\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u548c\u51c6\u786e<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">setter\u65b9\u6cd5<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u9488\u5bf9date\u7ed3\u6784\u4f53\u5b57\u6bb5\u6765\u5b9a\u4e49\u5bf9\u5e94\u7684\u65b9\u6cd5\uff0c\u6bd4\u5982SetYear\u3001SetMonth\u3001SetDay\u65b9\u6cd5\u6765\u63a5\u53d7\u503c\uff0c\u5728\u65b9\u6cd5\u4e2d\u8fdb\u884c\u5224\u65ad\uff0c\u5982\u679c\u662f\u6709\u6548\u503c\uff0c\u5c31\u8d4b\u503c\u7ed9\u7ed3\u6784\u4f53\u5b57\u6bb5\uff0c\u5426\u5219\u62a5\u9519\uff0c\u8fd9\u7c7b\u65b9\u6cd5\u5e38\u88ab\u79f0\u4e3asetter\u65b9\u6cd5\uff0c\u4f9d\u7167\u60ef\u4f8b\uff0cGo\u7684setter\u65b9\u6cd5\u540d\u4e3aSetX\u7684\u5f62\u5f0f\uff0cX\u662f\u4f60\u60f3\u8981\u8bbe\u7f6e\u7684\u4e1c\u897f\u7684\u540d\u79f0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u5b9a\u4e49\u4e00\u4e2aSetYear\u65b9\u6cd5\uff0c\u7136\u540e\u63a5\u53d7\u53c2\u6570\u6765\u8bbe\u7f6eyear\u7684\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"448\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3.png\" alt=\"\" class=\"wp-image-14694\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3.png 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-300x192.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-600x385.png 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"99\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-1.png\" alt=\"\" class=\"wp-image-14695\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-1.png 701w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-1-300x42.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-1-600x85.png 600w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u770b\u51fa\uff0c\u901a\u8fc7SetYear\u8d4b\u503c\u540e\uff0c\u539f\u7ed3\u6784\u4f53\u7684\u5b57\u6bb5year\u7684\u503c\u8fd8\u662f\u521d\u59cb\u503c0\uff0c\u8fd9\u662f\u56e0\u4e3ago\u7684\u65b9\u6cd5\u9ed8\u8ba4\u662f\u503c\u4f20\u9012\uff0c\u6211\u4eec\u4fee\u6539\u7684\u662f\u62f7\u8d1d\u540e\u7684\u503c\u800c\u4e0d\u662f\u539f\u503c\uff0c\u56e0\u6b64\u5982\u679c\u8981\u4fee\u6539\u539f\u503c\u9700\u8981\u4f7f\u7528\u6307\u9488\u4f20\u9012\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"476\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-5.png\" alt=\"\" class=\"wp-image-14750\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-5.png 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-5-300x205.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/1-5-600x410.png 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6b21\u6253\u5370\uff0c\u53ef\u4ee5\u53d1\u73b0\u539f\u59cb\u503c\u4e5f\u4fee\u6539\u4e86\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"92\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-4.png\" alt=\"\" class=\"wp-image-14752\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-4.png 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-4-300x39.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/2-4-600x79.png 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u7684SetYeaer\u65b9\u6cd5\u91cc\u6211\u4eec\u53ea\u662f\u7b80\u5355\u7684\u8bbe\u7f6e\u4e86\u5b57\u6bb5\u503c\uff0c\u5e76\u6ca1\u6709\u505a\u6761\u4ef6\u5224\u65ad\uff0c\u53ef\u4ee5\u5728\u91cc\u9762\u505a\u4e00\u4e9b\u5224\u65ad\u5e74\u6708\u65e5\u7684\u64cd\u4f5c\uff0c\u6211\u4eec\u5148\u770b\u4e0bmain()\u51fd\u6570\u4e2d\uff0c\u53ca\u65f6\u6211\u4eec\u4f7f\u7528\u4e86SetYear\u5e76\u5728\u5176\u4e2d\u52a0\u5165\u4e86\u5224\u65ad\u65b9\u6cd5\uff0c\u4f46\u662f\u8fd8\u662f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528date.year\u6765\u8bbe\u7f6e\u503c\uff0c\u5e76\u4e14\u8fd9\u4e2a\u540e\u8bbe\u7f6e\u7684\u503c\u4f1a\u8986\u76d6SetYear\u4e2d\u7684\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"511\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-2.png\" alt=\"\" class=\"wp-image-14753\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-2.png 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-2-300x219.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/3-2-600x439.png 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"697\" height=\"112\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-4.png\" alt=\"\" class=\"wp-image-14756\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-4.png 697w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-4-300x48.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/4-4-600x96.png 600w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u770b\u51fa\uff0c\u8fd8\u662f\u4f1a\u88ab\u8bbe\u7f6e\u65e0\u6548\u503c\uff0c\u600e\u4e48\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528\u5c01\u88c5\u4e86<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u7684\u7ed3\u6784\u4f53\u548c\u65b9\u6cd5\u90fd\u5355\u72ec\u653e\u4e00\u4e2a\u5305gong\u4e2d\uff0c\u7136\u540e\u5c06\u7ed3\u6784\u4f53\u7684\u5b57\u6bb5\u5c0f\u5199\uff0c\u8fd9\u6837\u5c31\u4e0d\u53ef\u5bfc\u51fa\uff0c\u53ea\u5c06\u65b9\u6cd5\u5bfc\u51fa\uff0c\u5e76\u6dfb\u52a0\u4e00\u4e2a\u5de5\u7a0b\u51fd\u6570\uff0c\u5c01\u88c5\u540e\u66f4\u65b0\u503c\u53ea\u80fd\u901a\u8fc7Setter\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u88ab\u4fdd\u62a4\u4e86\uff0c\u907f\u514d\u8f93\u5165\u65e0\u6548\u6570\u636e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u5728gong\u5305\u4e2d\u5b9a\u4e49\u7ed3\u6784\u4f53\u4ee5\u53ca\u65b9\u6cd5\uff0c\u7ed3\u6784\u4f53\u548c\u5b57\u6bb5\u4e0d\u53ef\u5bfc\u51fa\uff0c\u901a\u8fc7\u65b9\u6cd5\u5b9a\u4e49\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"602\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/5-3.png\" alt=\"\" class=\"wp-image-14758\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/5-3.png 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/5-3-300x258.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/5-3-600x517.png 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c8\u884c\uff1a\u5b9a\u4e49\u5de5\u7a0b\u51fd\u6570\uff0c\u8fd4\u56de\u5b9e\u4f8b\u5316\u540e\u7684\u7ed3\u6784\u4f53\u6307\u9488\u7c7b\u578b<\/li>\n\n\n\n<li>\u7b2c13\u300114\u884c\uff1a\u7ed3\u6784\u4f53\u540d\u548c\u5b57\u6bb5\u90fd\u5c0f\u5199\uff0c\u56e0\u6b64\u4e0d\u53ef\u5bfc\u51fa<\/li>\n\n\n\n<li>\u7b2c18\u884c\uff1a\u5b9a\u4e49SetYear\u65b9\u6cd5\uff0c\u63a5\u6536\u503c\u5e76\u5224\u65ad<\/li>\n\n\n\n<li>\u7b2c25\u884c\uff1aYear\u65b9\u6cd5\u5b9e\u9645\u4e3agetter\u65b9\u6cd5\u7528\u4e8e\u83b7\u53d6\u503c<\/li>\n<\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u672a\u5bfc\u51fa\u7684\u53d8\u91cf\u3001struct\u5b57\u6bb5\u3001\u51fd\u6570\u3001\u65b9\u6cd5\u7b49\u4ecd\u7136\u80fd\u591f\u88ab\u76f8\u540c\u5305\u7684\u5bfc\u51fa\u7684\u51fd\u6570\u6216\u8005\u65b9\u6cd5\u8bbf\u95ee<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u4e3b\u51fd\u6570\uff0c\u7136\u540e\u8c03\u7528gong\u5305\u4e2d\u7684\u51fd\u6570\u5e76\u8bbe\u7f6e\u503c\u548c\u83b7\u53d6\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"698\" height=\"405\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/6-2.png\" alt=\"\" class=\"wp-image-14761\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/6-2.png 698w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/6-2-300x174.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/6-2-600x348.png 600w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c10\u884c\uff1a\u8c03\u7528gong\u5305\u4e2d\u7684\u51fd\u6570Date()\uff0c\u83b7\u53d6\u5b9e\u4f8b\u5316\u540e\u7684\u7ed3\u6784\u4f53\u6307\u9488<\/li>\n\n\n\n<li>\u7b2c12\u884c\uff1a\u8c03\u7528SetYear\u65b9\u6cd5\u8bbe\u7f6e\u5e74\u4efd\uff0c\u5982\u679c\u4e0d\u7b26\u5408\u4e0a\u9762\u6761\u4ef6\u4f1a\u8fd4\u56de\u9519\u8bef<\/li>\n\n\n\n<li>\u7b2c17\u884c\uff1a\u83b7\u53d6\u8bbe\u7f6e\u7684\u5e74\u4efd\u7684\u503c<\/li>\n<\/ul>\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=\"700\" height=\"89\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/7-2.png\" alt=\"\" class=\"wp-image-14763\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/7-2.png 700w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/7-2-300x38.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/7-2-600x76.png 600w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u4e0a\u8ff0\u4f8b\u5b50\u4e0d\u7528\u5de5\u7a0b\u51fd\u6570\u5176\u5b9e\u4e5f\u53ef\u4ee5\uff0c\u53ea\u9700\u8981\u5c06\u7ed3\u6784\u4f53data\u6539\u4e3aDate\uff0c\u90a3\u4e48\u7ed3\u6784\u4f53\u5c31\u53ef\u4ee5\u5bfc\u51fa\uff0c\u7136\u540e\u5b9e\u4f8b\u5316\u5e76\u8c03\u7528\u65b9\u6cd5\u5373\u53ef<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">getter\u65b9\u6cd5<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">getter\u65b9\u6cd5\u4e00\u822c\u7528\u4e8e\u83b7\u53d6\u503c\uff0c\u4e0a\u9762\u5728setter\u65b9\u6cd5\u7684\u4f7f\u7528\u4f8b\u5b50\u4e2d\u6211\u4eec\u5df2\u7ecf\u4f7f\u7528\u4e86getter\u65b9\u6cd5\uff0c\u5c31\u662fYear()\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u5199\u6210GetYear()\u5462\uff0c\u5176\u5b9eGo\u8bed\u8a00\u5141\u8bb8\u4f60\u8fd9\u6837\u5199\uff0c\u4f46\u662f\u4e0d\u63a8\u8350\uff0c\u63a8\u8350\u7684\u662f\u5728getter\u65b9\u6cd5\u524d\u9762\u53bb\u6389Get\u524d\u7f00<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u5185\u5d4c<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed3\u6784\u4f53\u5185\u5d4c\u540e\uff0c\u5916\u5c42\u7ed3\u6784\u4f53\u662f\u53ef\u4ee5\u8bbf\u95ee\u5185\u5c42\u7ed3\u6784\u4f53\u53ef\u5bfc\u51fa\u7684\u65b9\u6cd5\u7684\uff0c\u5bf9\u4e8e\u672a\u88ab\u5bfc\u51fa\u7684\u5b57\u6bb5\u548c\u65b9\u6cd5\u662f\u4e0d\u53ef\u8bbf\u95ee\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4fee\u6539\u4e0a\u9762\u4f8b\u5b50\uff0c\u5b9a\u4e49\u65b0\u7684\u7ed3\u6784\u4f53ImDate\uff0c\u5c06date\u7ed3\u6784\u4f53\u5185\u5d4c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"584\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/8.png\" alt=\"\" class=\"wp-image-14771\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/8.png 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/8-300x252.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/8-600x503.png 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u51fd\u6570\u4e2d\u5b9e\u4f8b\u5316\u7ed3\u6784\u4f53ImDate\uff0c\u7136\u540e\u53ef\u76f4\u63a5\u8c03\u7528date\u4e2d\u7684\u53ef\u5bfc\u51fa\u65b9\u6cd5\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"406\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/9.png\" alt=\"\" class=\"wp-image-14773\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/9.png 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/9-300x175.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/09\/9-600x351.png 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u8bf7\u6c42\u672a\u88ab\u5bfc\u51fa\u7684\u5b57\u6bb5\uff0c\u5c06\u4f1a\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date.year undefined (type gong.ImDate has no field or method year, but does have Year)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Golang\u662f\u4e00\u95e8\u975e\u5e38\u4f18\u79c0\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e9b\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u5c01\u88c5\u3002\u5c01\u88c5\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08O [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":14686,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-14685","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\/14685","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=14685"}],"version-history":[{"count":17,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/14685\/revisions"}],"predecessor-version":[{"id":14774,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/14685\/revisions\/14774"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/14686"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=14685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=14685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=14685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}