{"id":147,"date":"2026-05-11T16:28:10","date_gmt":"2026-05-11T08:28:10","guid":{"rendered":"https:\/\/hi.tionmon.de\/?p=147"},"modified":"2026-05-11T16:30:40","modified_gmt":"2026-05-11T08:30:40","slug":"%e6%9e%81%e7%ae%80%e7%9f%ad%e9%93%be%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/hi.tionmon.de\/?p=147","title":{"rendered":"\u6781\u7b80\u77ed\u94fe\u7cfb\u7edf"},"content":{"rendered":"<p># shortlink-go<\/p>\n<p>\u6781\u7b80\u77ed\u94fe\u7cfb\u7edf\uff08Go + SQLite\uff09\uff0c\u7531 Python \u7248\u672c\u91cd\u5199\u800c\u6765\uff0c\u5185\u5b58\u5360\u7528\u6781\u4f4e\u3001\u8fd0\u884c\u7a33\u5b9a\u53ef\u9760\u3002<\/p>\n<h2>\u76f8\u6bd4 Python \u7248\u672c\u7684\u4f18\u52bf<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u5bf9\u6bd4\u9879<\/th>\n<th>Python \u7248<\/th>\n<th>Go \u7248<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8fd0\u884c\u5185\u5b58<\/td>\n<td>\u7ea6 50\u201380 MB<\/td>\n<td>\u7ea6 5\u201310 MB<\/td>\n<\/tr>\n<tr>\n<td>Docker \u955c\u50cf<\/td>\n<td>\u7ea6 150 MB<\/td>\n<td>\u7ea6 15 MB<\/td>\n<\/tr>\n<tr>\n<td>\u542f\u52a8\u65f6\u95f4<\/td>\n<td>2\u20133 \u79d2<\/td>\n<td>&lt;0.1 \u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u4f9d\u8d56<\/td>\n<td>Flask + Python \u8fd0\u884c\u65f6<\/td>\n<td>\u5355\u4e2a\u9759\u6001\u4e8c\u8fdb\u5236\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>\u5e76\u53d1\u80fd\u529b<\/td>\n<td>\u53d7 GIL \u9650\u5236<\/td>\n<td>\u539f\u751f goroutine \u5e76\u53d1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u65b0\u589e\u529f\u80fd<\/h2>\n<ul>\n<li><strong>\u5907\u6ce8\u529f\u80fd<\/strong>\uff1a\u6bcf\u6761\u77ed\u94fe\u53ef\u6dfb\u52a0\u5907\u6ce8\uff0c\u4fbf\u4e8e\u540e\u7eed\u68c0\u67e5\u4e0e\u8bc6\u522b\u7528\u9014<\/li>\n<li><strong>\u5206\u7ec4\u529f\u80fd\uff08\u53ef\u9009\uff09<\/strong>\uff1a\u4e3a\u77ed\u94fe\u5206\u914d\u5206\u7ec4\uff08\u5982\u201c\u5de5\u4f5c\u201d\u201c\u4e2a\u4eba\u201d\uff09\uff0c\u652f\u6301\u4e0b\u62c9\u7b5b\u9009\u4e0e\u81ea\u52a8\u8865\u5168<\/li>\n<li><strong>\u6807\u7b7e\u529f\u80fd\uff08\u53ef\u9009\uff09<\/strong>\uff1a\u4e3a\u77ed\u94fe\u6dfb\u52a0\u591a\u4e2a\u6807\u7b7e\uff08\u9017\u53f7\u5206\u9694\uff09\uff0c\u70b9\u51fb\u6807\u7b7e\u5373\u53ef\u5feb\u901f\u7b5b\u9009<\/li>\n<li><strong>\u591a\u9009\u5220\u9664<\/strong>\uff1a\u652f\u6301\u52fe\u9009\u591a\u6761\u77ed\u94fe\u5e76\u4e00\u952e\u6279\u91cf\u5220\u9664\uff0c\u65b9\u4fbf\u65e5\u5e38\u7ef4\u62a4<\/li>\n<li><strong>\u7b5b\u9009\u8fc7\u6ee4<\/strong>\uff1a\u9876\u90e8\u7b5b\u9009\u680f\u652f\u6301\u6309\u5206\u7ec4\u4e0e\u6807\u7b7e\u7ec4\u5408\u8fc7\u6ee4<\/li>\n<li><strong>\u6570\u636e\u5e93\u517c\u5bb9<\/strong>\uff1a\u81ea\u52a8\u68c0\u6d4b\u65e7\u6570\u636e\u5e93\u5e76\u65b0\u589e\u6240\u9700\u5217\uff0c\u5b9e\u73b0\u5e73\u6ed1\u8fc1\u79fb<\/li>\n<\/ul>\n<h2>\u90e8\u7f72\u65b9\u5f0f<\/h2>\n<h3>Docker Compose\uff08\u63a8\u8350\uff09<\/h3>\n<div class=\"xun-code-wrapper\"><div class=\"xun-code-header\"><div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div><div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div><\/div><pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">services:\r\n  shortlink:\r\n    build: .\r\n    # image: yourname\/shortlink-go:latest\r\n    container_name: shortlink-service\r\n    ports:\r\n      - &quot;5000:5000&quot;\r\n    volumes:\r\n      - .\/data:\/app\/data\r\n    environment:\r\n      - ADMIN_USERNAME=admin\r\n      - ADMIN_PASSWORD=admin123\r\n      # - SECRET_KEY=your-random-secret-key\r\n    restart: unless-stopped<\/code><\/pre><\/div>\n<h3>\u73af\u5883\u53d8\u91cf\u8bf4\u660e<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u53d8\u91cf\u540d<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>ADMIN_USERNAME<\/code><\/td>\n<td>admin<\/td>\n<td>\u7ba1\u7406\u5458\u7528\u6237\u540d<\/td>\n<\/tr>\n<tr>\n<td><code>ADMIN_PASSWORD<\/code><\/td>\n<td>admin123<\/td>\n<td>\u7ba1\u7406\u5458\u5bc6\u7801<\/td>\n<\/tr>\n<tr>\n<td><code>DATABASE_PATH<\/code><\/td>\n<td>\/app\/data\/shortlinks.db<\/td>\n<td>\u6570\u636e\u5e93\u6587\u4ef6\u8def\u5f84<\/td>\n<\/tr>\n<tr>\n<td><code>SECRET_KEY<\/code><\/td>\n<td>change-this-secret-key<\/td>\n<td>Cookie \u7b7e\u540d\u5bc6\u94a5<\/td>\n<\/tr>\n<tr>\n<td><code>HOST<\/code><\/td>\n<td>0.0.0.0<\/td>\n<td>\u76d1\u542c\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td><code>PORT<\/code><\/td>\n<td>5000<\/td>\n<td>\u76d1\u542c\u7aef\u53e3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5185\u5b58\u4f18\u5316\u63aa\u65bd<\/h2>\n<ul>\n<li>SQLite \u4f7f\u7528 WAL \u6a21\u5f0f\uff0c\u8fde\u63a5\u6c60\u4e0a\u9650\u4e3a 2 \u4e2a\u8fde\u63a5<\/li>\n<li>\u901a\u8fc7 <code>embed.FS<\/code> \u5d4c\u5165\u6a21\u677f\uff0c\u907f\u514d\u8fd0\u884c\u65f6\u8bfb\u53d6\u6587\u4ef6<\/li>\n<li>\u91c7\u7528 HMAC \u7b7e\u540d Cookie\uff0c\u66ff\u4ee3\u670d\u52a1\u7aef Session \u5b58\u50a8<\/li>\n<li>\u7f16\u8bd1\u65f6\u4f7f\u7528 <code>-ldflags=\"-s -w\"<\/code> \u51cf\u5c0f\u4e8c\u8fdb\u5236\u4f53\u79ef<\/li>\n<li>\u5f02\u6b65\u66f4\u65b0\u8bbf\u95ee\u8ba1\u6570\uff0c\u964d\u4f4e\u963b\u585e\u5f71\u54cd<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p># shortlink-go \u6781\u7b80\u77ed\u94fe\u7cfb\u7edf\uff08Go + SQLite\uff09\uff0c\u7531 Python \u7248\u672c\u91cd\u5199\u800c\u6765\uff0c\u5185\u5b58\u5360\u7528<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"special":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-vps"],"_links":{"self":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":4,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fspecial&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}