{"id":207979,"date":"2025-07-08T08:17:27","date_gmt":"2025-07-08T00:17:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207979\/"},"modified":"2025-07-08T08:17:27","modified_gmt":"2025-07-08T00:17:27","slug":"%e6%97%a0%e6%b3%95%e5%b0%86%e7%bb%93%e6%9e%84%e5%85%83%e7%b4%a0%e5%88%86%e9%85%8d%e4%b8%ba-google-uuid-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207979\/","title":{"rendered":"\u65e0\u6cd5\u5c06\u7ed3\u6784\u5143\u7d20\u5206\u914d\u4e3a Google\/uuid \u6570\u636e\u7c7b\u578b"},"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>\u65e0\u6cd5\u5c06\u7ed3\u6784\u5143\u7d20\u5206\u914d\u4e3a Google\/uuid \u6570\u636e\u7c7b\u578b<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 15:24:58<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u65e0\u6cd5\u5c06\u7ed3\u6784\u5143\u7d20\u5206\u914d\u4e3a Google\/uuid \u6570\u636e\u7c7b\u578b\u300b\uff0c\u8986\u76d6\u4e86Golang\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u5728\u6211\u7684\u9879\u76ee\u4e2d\u4f7f\u7528 https:\/\/github.com\/google\/uuid\uff0c\u6211\u5e0c\u671b\u6211\u7684 user struct \u6709\u4e00\u4e2a id \u4f5c\u4e3a uuid\uff0c\u4f46\u5b83\u4e0d\u5141\u8bb8\u6211\u5c06\u5176\u5206\u914d\u4e3a\u6570\u636e\u7c7b\u578b\u3002\u5f53\u6211\u5c1d\u8bd5\u65f6\uff0c\u5b83\u7ed9\u51fa\u4e86\u9519\u8bef <code>syntax error: unexpected :, waiting type<\/code>\u3002\u8fd9\u662f\u6211\u7684\u4ee3\u7801\u4f9b\u53c2\u8003\uff1a<\/p>\n<pre>package postgres\n\nimport (\n  \"time\"\n  \"github.com\/google\/uuid\"\n)\n\ntype DbUser struct {\n  ID: uuid.UUID,\n  Username: string,\n  Password: string,\n  Email: string,\n  DateOfBirth: time,\n  dateCreated: time, \n}<\/pre>\n<p>\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5e2e\u52a9\u6211\u9610\u660e\u5c06\u7ed3\u6784\u5143\u7d20\u6216\u53d8\u91cf\u4f5c\u4e3a uuid \u4f20\u9012\u7684\u8bed\u6cd5\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u7684 \u9519\u8bef\uff0c\u60a8\u4f7f\u7528\u7684\u662f \u7684\u8bed\u6cd5\u3002 \u5e94\u8be5\u662f\uff1a<\/p>\n<pre>type dbuser struct {\n  id uuid.uuid\n  username string\n  password string\n  email string\n  dateofbirth time.time\n  datecreated time.time\n}<\/pre>\n<p>\u53e6\u8bf7\u6ce8\u610f\uff0c<code>time<\/code> \u4e0d\u662f\u7c7b\u578b\uff0c\u800c\u662f\u5305\u540d\u79f0\u3002<\/p>\n<p>\u4f60\u53ef\u80fd\u60f3\u62ff\u6765\u5b66\u4e60\u57fa\u672c\u8bed\u6cd5\u3002<\/p>\n<p>time\u662f\u5305\u540d\uff0c\u4e0d\u80fd\u5b9a\u4e49\u5b57\u6bb5\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528time.time\u3002<\/p>\n<pre>import (\n      \"time\"\n      \"github.com\/google\/uuid\"\n    )\n    \n    type DbUser struct {\n        ID          uuid.UUID\n        Username    string\n        Password    string\n        Email       string\n        DateOfBirth time.Time\n        dateCreated time.Time\n    }<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u65e0\u6cd5\u5c06\u7ed3\u6784\u5143\u7d20\u5206\u914d\u4e3a Google\/uuid \u6570\u636e\u7c7b\u578b\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207979","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207979","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=207979"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207979\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}