From ea1f2ec43069eb29cc1ab946bb1fff01f7e63efb Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 15 Aug 2026 05:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=8D=81=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E6=88=90=20Go=20Cmd=20Tools=20=E6=B3=A8=E9=87=8A=E5=9F=BA?= =?UTF-8?q?=E7=BA=BF=E6=B8=85=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .commentlint/go-baseline.json | 4146 ------------------ cmd/browser-install/main.go | 22 +- cmd/dbseed/main.go | 95 +- cmd/dbseed/main_test.go | 15 + cmd/dbverify/main.go | 60 +- cmd/dbverify/main_test.go | 58 +- cmd/init-admin/main.go | 63 +- cmd/init-admin/main_test.go | 40 +- cmd/server/main.go | 119 +- cmd/server/main_test.go | 45 +- cmd/server/service_stub.go | 1 + cmd/server/service_windows.go | 15 +- cmd/spike/main.go | 16 +- cmd/tray/icon.go | 11 + cmd/tray/instance_lock_unix.go | 11 +- cmd/tray/instance_lock_unix_test.go | 4 + cmd/tray/instance_lock_windows.go | 3 + cmd/tray/main.go | 93 +- cmd/tray/main_test.go | 26 +- cmd/tray/service_control_darwin.go | 46 +- cmd/tray/service_control_other.go | 3 + cmd/tray/service_control_windows.go | 49 +- cmd/tray/service_control_windows_test.go | 24 +- docs/architecture/refactoring-master-plan.md | 1 + tools/iconconv/main.go | 9 +- 25 files changed, 694 insertions(+), 4281 deletions(-) diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index 96791d4..9483ca6 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -1,4102 +1,4 @@ [ - { - "file": "cmd/browser-install/main.go", - "line": 13, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/browser-install/main.go", - "line": 14, - "kind": "local-variable", - "name": "driverDir" - }, - { - "file": "cmd/browser-install/main.go", - "line": 15, - "kind": "local-variable", - "name": "browserDir" - }, - { - "file": "cmd/browser-install/main.go", - "line": 16, - "kind": "local-variable", - "name": "withDeps" - }, - { - "file": "cmd/browser-install/main.go", - "line": 17, - "kind": "local-variable", - "name": "depsOnly" - }, - { - "file": "cmd/browser-install/main.go", - "line": 24, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/browser-install/main.go", - "line": 29, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/browser-install/main.go", - "line": 34, - "kind": "local-variable", - "name": "options" - }, - { - "file": "cmd/browser-install/main.go", - "line": 41, - "kind": "local-variable", - "name": "driver" - }, - { - "file": "cmd/browser-install/main.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/browser-install/main.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/browser-install/main.go", - "line": 49, - "kind": "local-variable", - "name": "args" - }, - { - "file": "cmd/browser-install/main.go", - "line": 58, - "kind": "local-variable", - "name": "cmd" - }, - { - "file": "cmd/browser-install/main.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/browser-install/main.go", - "line": 66, - "kind": "function", - "name": "fatal" - }, - { - "file": "cmd/dbseed/main.go", - "line": 19, - "kind": "type", - "name": "seedOptions" - }, - { - "file": "cmd/dbseed/main.go", - "line": 27, - "kind": "type", - "name": "seedResult" - }, - { - "file": "cmd/dbseed/main.go", - "line": 33, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/dbseed/main.go", - "line": 34, - "kind": "local-variable", - "name": "sourcePath" - }, - { - "file": "cmd/dbseed/main.go", - "line": 35, - "kind": "local-variable", - "name": "targetURL" - }, - { - "file": "cmd/dbseed/main.go", - "line": 36, - "kind": "local-variable", - "name": "username" - }, - { - "file": "cmd/dbseed/main.go", - "line": 37, - "kind": "local-variable", - "name": "password" - }, - { - "file": "cmd/dbseed/main.go", - "line": 38, - "kind": "local-variable", - "name": "adminUsername" - }, - { - "file": "cmd/dbseed/main.go", - "line": 39, - "kind": "local-variable", - "name": "adminPassword" - }, - { - "file": "cmd/dbseed/main.go", - "line": 40, - "kind": "local-variable", - "name": "limit" - }, - { - "file": "cmd/dbseed/main.go", - "line": 47, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/dbseed/main.go", - "line": 47, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/dbseed/main.go", - "line": 49, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 49, - "kind": "local-variable", - "name": "source" - }, - { - "file": "cmd/dbseed/main.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 57, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/dbseed/main.go", - "line": 57, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 57, - "kind": "local-variable", - "name": "targetDB" - }, - { - "file": "cmd/dbseed/main.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 63, - "kind": "local-variable", - "name": "result" - }, - { - "file": "cmd/dbseed/main.go", - "line": 76, - "kind": "function", - "name": "seedFromSQLite" - }, - { - "file": "cmd/dbseed/main.go", - "line": 89, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 92, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 92, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbseed/main.go", - "line": 96, - "kind": "const", - "name": "accountID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 97, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 100, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 104, - "kind": "local-variable", - "name": "result" - }, - { - "file": "cmd/dbseed/main.go", - "line": 105, - "kind": "local-variable", - "name": "count" - }, - { - "file": "cmd/dbseed/main.go", - "line": 105, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 105, - "kind": "local-variable", - "name": "itemMap" - }, - { - "file": "cmd/dbseed/main.go", - "line": 116, - "kind": "range-variable", - "name": "id" - }, - { - "file": "cmd/dbseed/main.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 136, - "kind": "function", - "name": "ensureFixtureAdmin" - }, - { - "file": "cmd/dbseed/main.go", - "line": 137, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 137, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbseed/main.go", - "line": 139, - "kind": "local-variable", - "name": "createErr" - }, - { - "file": "cmd/dbseed/main.go", - "line": 139, - "kind": "local-variable", - "name": "created" - }, - { - "file": "cmd/dbseed/main.go", - "line": 149, - "kind": "local-variable", - "name": "updateErr" - }, - { - "file": "cmd/dbseed/main.go", - "line": 149, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "cmd/dbseed/main.go", - "line": 154, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 168, - "kind": "function", - "name": "prepareFixtureUser" - }, - { - "file": "cmd/dbseed/main.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 169, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbseed/main.go", - "line": 171, - "kind": "local-variable", - "name": "createErr" - }, - { - "file": "cmd/dbseed/main.go", - "line": 171, - "kind": "local-variable", - "name": "created" - }, - { - "file": "cmd/dbseed/main.go", - "line": 191, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 195, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "cmd/dbseed/main.go", - "line": 199, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 205, - "kind": "function", - "name": "seedItems" - }, - { - "file": "cmd/dbseed/main.go", - "line": 206, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 206, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "cmd/dbseed/main.go", - "line": 212, - "kind": "local-variable", - "name": "mapping" - }, - { - "file": "cmd/dbseed/main.go", - "line": 213, - "kind": "local-variable", - "name": "count" - }, - { - "file": "cmd/dbseed/main.go", - "line": 215, - "kind": "var", - "name": "category" - }, - { - "file": "cmd/dbseed/main.go", - "line": 215, - "kind": "var", - "name": "description" - }, - { - "file": "cmd/dbseed/main.go", - "line": 215, - "kind": "var", - "name": "price" - }, - { - "file": "cmd/dbseed/main.go", - "line": 215, - "kind": "var", - "name": "sourceID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 215, - "kind": "var", - "name": "title" - }, - { - "file": "cmd/dbseed/main.go", - "line": 216, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 219, - "kind": "local-variable", - "name": "fixtureID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 220, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 232, - "kind": "function", - "name": "seedOrders" - }, - { - "file": "cmd/dbseed/main.go", - "line": 233, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 233, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "cmd/dbseed/main.go", - "line": 240, - "kind": "local-variable", - "name": "count" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "amount" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "quantity" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "sourceItemID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "sourceOrderID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "specName" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "specValue" - }, - { - "file": "cmd/dbseed/main.go", - "line": 242, - "kind": "var", - "name": "status" - }, - { - "file": "cmd/dbseed/main.go", - "line": 243, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 246, - "kind": "local-variable", - "name": "itemID" - }, - { - "file": "cmd/dbseed/main.go", - "line": 246, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/dbseed/main.go", - "line": 250, - "kind": "local-variable", - "name": "normalized" - }, - { - "file": "cmd/dbseed/main.go", - "line": 250, - "kind": "local-variable", - "name": "valid" - }, - { - "file": "cmd/dbseed/main.go", - "line": 255, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 266, - "kind": "function", - "name": "seedCards" - }, - { - "file": "cmd/dbseed/main.go", - "line": 267, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 267, - "kind": "local-variable", - "name": "rows" - }, - { - "file": "cmd/dbseed/main.go", - "line": 273, - "kind": "local-variable", - "name": "count" - }, - { - "file": "cmd/dbseed/main.go", - "line": 275, - "kind": "var", - "name": "cardType" - }, - { - "file": "cmd/dbseed/main.go", - "line": 275, - "kind": "var", - "name": "name" - }, - { - "file": "cmd/dbseed/main.go", - "line": 276, - "kind": "var", - "name": "delay" - }, - { - "file": "cmd/dbseed/main.go", - "line": 277, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 280, - "kind": "local-variable", - "name": "card" - }, - { - "file": "cmd/dbseed/main.go", - "line": 289, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main.go", - "line": 297, - "kind": "function", - "name": "shortHash" - }, - { - "file": "cmd/dbseed/main.go", - "line": 298, - "kind": "local-variable", - "name": "sum" - }, - { - "file": "cmd/dbseed/main.go", - "line": 302, - "kind": "function", - "name": "fallback" - }, - { - "file": "cmd/dbseed/main.go", - "line": 309, - "kind": "function", - "name": "fatalf" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 12, - "kind": "function", - "name": "TestSeedFromSQLiteCopiesMetadataAndSanitizesSecrets" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 13, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 14, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 14, - "kind": "local-variable", - "name": "sourceDB" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 14, - "kind": "local-variable", - "name": "sourceDialect" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 19, - "kind": "local-variable", - "name": "source" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 21, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "targetDB" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "targetDialect" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 32, - "kind": "local-variable", - "name": "target" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 33, - "kind": "local-variable", - "name": "options" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 34, - "kind": "local-variable", - "name": "result" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 41, - "kind": "local-variable", - "name": "cookie" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 45, - "kind": "local-variable", - "name": "fixtureUser" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 46, - "kind": "local-variable", - "name": "adminErr" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 46, - "kind": "local-variable", - "name": "fixtureAdmin" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 50, - "kind": "local-variable", - "name": "cards" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 54, - "kind": "local-variable", - "name": "invalidOrder" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbseed/main_test.go", - "line": 59, - "kind": "local-variable", - "name": "second" - }, - { - "file": "cmd/dbverify/main.go", - "line": 26, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/dbverify/main.go", - "line": 27, - "kind": "var", - "name": "cleanup" - }, - { - "file": "cmd/dbverify/main.go", - "line": 28, - "kind": "local-variable", - "name": "fail" - }, - { - "file": "cmd/dbverify/main.go", - "line": 30, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 42, - "kind": "local-variable", - "name": "url" - }, - { - "file": "cmd/dbverify/main.go", - "line": 43, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/dbverify/main.go", - "line": 43, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/dbverify/main.go", - "line": 47, - "kind": "local-variable", - "name": "database" - }, - { - "file": "cmd/dbverify/main.go", - "line": 47, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/dbverify/main.go", - "line": 47, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 54, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/dbverify/main.go", - "line": 58, - "kind": "local-variable", - "name": "username" - }, - { - "file": "cmd/dbverify/main.go", - "line": 59, - "kind": "local-variable", - "name": "accountID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 60, - "kind": "local-variable", - "name": "orderID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 61, - "kind": "local-variable", - "name": "itemID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 62, - "kind": "local-variable", - "name": "buyerID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 64, - "kind": "local-variable", - "name": "cleanupCancel" - }, - { - "file": "cmd/dbverify/main.go", - "line": 64, - "kind": "local-variable", - "name": "cleanupCtx" - }, - { - "file": "cmd/dbverify/main.go", - "line": 68, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 68, - "kind": "local-variable", - "name": "password" - }, - { - "file": "cmd/dbverify/main.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 72, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/dbverify/main.go", - "line": 76, - "kind": "local-variable", - "name": "adminUser" - }, - { - "file": "cmd/dbverify/main.go", - "line": 76, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 80, - "kind": "local-variable", - "name": "userID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 87, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 94, - "kind": "local-variable", - "name": "v" - }, - { - "file": "cmd/dbverify/main.go", - "line": 101, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 126, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 169, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 169, - "kind": "local-variable", - "name": "started" - }, - { - "file": "cmd/dbverify/main.go", - "line": 187, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 196, - "kind": "function", - "name": "maskURL" - }, - { - "file": "cmd/dbverify/main.go", - "line": 200, - "kind": "local-variable", - "name": "rest" - }, - { - "file": "cmd/dbverify/main.go", - "line": 201, - "kind": "local-variable", - "name": "at" - }, - { - "file": "cmd/dbverify/main.go", - "line": 210, - "kind": "type", - "name": "verifyIDs" - }, - { - "file": "cmd/dbverify/main.go", - "line": 218, - "kind": "function", - "name": "newVerifyIDs" - }, - { - "file": "cmd/dbverify/main.go", - "line": 219, - "kind": "local-variable", - "name": "suffix" - }, - { - "file": "cmd/dbverify/main.go", - "line": 229, - "kind": "function", - "name": "newVerifyPassword" - }, - { - "file": "cmd/dbverify/main.go", - "line": 230, - "kind": "var", - "name": "b" - }, - { - "file": "cmd/dbverify/main.go", - "line": 231, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 237, - "kind": "function", - "name": "cleanupVerifyData" - }, - { - "file": "cmd/dbverify/main.go", - "line": 238, - "kind": "local-variable", - "name": "userID" - }, - { - "file": "cmd/dbverify/main.go", - "line": 239, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main.go", - "line": 239, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbverify/main.go", - "line": 242, - "kind": "local-variable", - "name": "queries" - }, - { - "file": "cmd/dbverify/main.go", - "line": 259, - "kind": "range-variable", - "name": "q" - }, - { - "file": "cmd/dbverify/main.go", - "line": 260, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 14, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 21, - "kind": "range-variable", - "name": "in" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 21, - "kind": "range-variable", - "name": "want" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 22, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 28, - "kind": "function", - "name": "TestNewVerifyIDsAreUniqueForPersistentRuns" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 29, - "kind": "local-variable", - "name": "ids" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 30, - "kind": "local-variable", - "name": "want" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 37, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 44, - "kind": "range-variable", - "name": "key" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 44, - "kind": "range-variable", - "name": "wantValue" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 54, - "kind": "function", - "name": "TestNewVerifyPasswordIsNotFixedDefault" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 55, - "kind": "local-variable", - "name": "first" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 59, - "kind": "local-variable", - "name": "second" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 71, - "kind": "function", - "name": "TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 72, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 73, - "kind": "local-variable", - "name": "database" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 73, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 78, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 79, - "kind": "local-variable", - "name": "ids" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 81, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 81, - "kind": "local-variable", - "name": "password" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 85, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 85, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 89, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 89, - "kind": "local-variable", - "name": "user" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 96, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 105, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 108, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 111, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 111, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 115, - "kind": "local-variable", - "name": "channelID" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 115, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 121, - "kind": "var", - "name": "channelEnabled" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 122, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 128, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 131, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 131, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 138, - "kind": "local-variable", - "name": "started" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 144, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 147, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 153, - "kind": "var", - "name": "count" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 154, - "kind": "range-variable", - "name": "name" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 154, - "kind": "range-variable", - "name": "query" - }, - { - "file": "cmd/dbverify/main_test.go", - "line": 161, - "kind": "var", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 23, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/init-admin/main.go", - "line": 24, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main.go", - "line": 25, - "kind": "local-variable", - "name": "dbURL" - }, - { - "file": "cmd/init-admin/main.go", - "line": 37, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 45, - "kind": "local-variable", - "name": "database" - }, - { - "file": "cmd/init-admin/main.go", - "line": 45, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/init-admin/main.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 50, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/init-admin/main.go", - "line": 52, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 52, - "kind": "local-variable", - "name": "existing" - }, - { - "file": "cmd/init-admin/main.go", - "line": 58, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 64, - "kind": "local-variable", - "name": "ans" - }, - { - "file": "cmd/init-admin/main.go", - "line": 66, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 71, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 71, - "kind": "local-variable", - "name": "pw" - }, - { - "file": "cmd/init-admin/main.go", - "line": 75, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 84, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 87, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 90, - "kind": "local-variable", - "name": "email" - }, - { - "file": "cmd/init-admin/main.go", - "line": 95, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 95, - "kind": "local-variable", - "name": "pw" - }, - { - "file": "cmd/init-admin/main.go", - "line": 100, - "kind": "local-variable", - "name": "created" - }, - { - "file": "cmd/init-admin/main.go", - "line": 100, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 105, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 115, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 115, - "kind": "local-variable", - "name": "p1" - }, - { - "file": "cmd/init-admin/main.go", - "line": 120, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 125, - "kind": "local-variable", - "name": "p2" - }, - { - "file": "cmd/init-admin/main.go", - "line": 130, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 142, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 146, - "kind": "local-variable", - "name": "b" - }, - { - "file": "cmd/init-admin/main.go", - "line": 146, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 160, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main.go", - "line": 166, - "kind": "function", - "name": "isNotFound" - }, - { - "file": "cmd/init-admin/main.go", - "line": 168, - "kind": "function", - "name": "fatalf" - }, - { - "file": "cmd/init-admin/main.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 17, - "kind": "function", - "name": "TestRunCreatesAdminInTemporaryDatabase" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 18, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 19, - "kind": "var", - "name": "out" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 20, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "d" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 32, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 32, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 38, - "kind": "function", - "name": "TestRunExistingAdminCanSkipReset" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 39, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 40, - "kind": "local-variable", - "name": "input" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 44, - "kind": "var", - "name": "out" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 53, - "kind": "function", - "name": "TestRunExistingAdminResetsPasswordAfterMismatchRetry" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 54, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 58, - "kind": "local-variable", - "name": "input" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 59, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 62, - "kind": "local-variable", - "name": "d" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 62, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 62, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 67, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 68, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 71, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 76, - "kind": "function", - "name": "TestRunRejectsEmptyEmail" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 77, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 84, - "kind": "function", - "name": "TestMainCLIEntrypointUsesDatabaseFlag" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 85, - "kind": "local-variable", - "name": "dbPath" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 86, - "kind": "local-variable", - "name": "stdin" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 86, - "kind": "local-variable", - "name": "writer" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 90, - "kind": "local-variable", - "name": "oldArgs" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 90, - "kind": "local-variable", - "name": "oldCommandLine" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 90, - "kind": "local-variable", - "name": "oldEnv" - }, - { - "file": "cmd/init-admin/main_test.go", - "line": 90, - "kind": "local-variable", - "name": "oldStdin" - }, - { - "file": "cmd/server/main.go", - "line": 36, - "kind": "type", - "name": "serverOptions" - }, - { - "file": "cmd/server/main.go", - "line": 60, - "kind": "const", - "name": "defaultDBPath" - }, - { - "file": "cmd/server/main.go", - "line": 61, - "kind": "const", - "name": "userDataDirName" - }, - { - "file": "cmd/server/main.go", - "line": 62, - "kind": "const", - "name": "defaultDataKeyName" - }, - { - "file": "cmd/server/main.go", - "line": 65, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/server/main.go", - "line": 66, - "kind": "local-variable", - "name": "opts" - }, - { - "file": "cmd/server/main.go", - "line": 72, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 78, - "kind": "local-variable", - "name": "run" - }, - { - "file": "cmd/server/main.go", - "line": 80, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 87, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/server/main.go", - "line": 87, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/server/main.go", - "line": 89, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 95, - "kind": "function", - "name": "parseOptions" - }, - { - "file": "cmd/server/main.go", - "line": 96, - "kind": "var", - "name": "opts" - }, - { - "file": "cmd/server/main.go", - "line": 121, - "kind": "function", - "name": "runServer" - }, - { - "file": "cmd/server/main.go", - "line": 122, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/server/main.go", - "line": 122, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/server/main.go", - "line": 125, - "kind": "local-variable", - "name": "dataDir" - }, - { - "file": "cmd/server/main.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 129, - "kind": "local-variable", - "name": "packagedPlaywrightRuntime" - }, - { - "file": "cmd/server/main.go", - "line": 132, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 151, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 161, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 161, - "kind": "local-variable", - "name": "key" - }, - { - "file": "cmd/server/main.go", - "line": 165, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 170, - "kind": "local-variable", - "name": "resolvedDBURL" - }, - { - "file": "cmd/server/main.go", - "line": 178, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 183, - "kind": "local-variable", - "name": "resolvedLogLevel" - }, - { - "file": "cmd/server/main.go", - "line": 184, - "kind": "local-variable", - "name": "explicitLogLevel" - }, - { - "file": "cmd/server/main.go", - "line": 193, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 196, - "kind": "local-variable", - "name": "resolvedLogFormat" - }, - { - "file": "cmd/server/main.go", - "line": 197, - "kind": "local-variable", - "name": "explicitLogFormat" - }, - { - "file": "cmd/server/main.go", - "line": 202, - "kind": "local-variable", - "name": "closeLog" - }, - { - "file": "cmd/server/main.go", - "line": 202, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 202, - "kind": "local-variable", - "name": "logWriter" - }, - { - "file": "cmd/server/main.go", - "line": 207, - "kind": "local-variable", - "name": "logger" - }, - { - "file": "cmd/server/main.go", - "line": 210, - "kind": "local-variable", - "name": "database" - }, - { - "file": "cmd/server/main.go", - "line": 210, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/server/main.go", - "line": 210, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 216, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/server/main.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 221, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 221, - "kind": "local-variable", - "name": "lv" - }, - { - "file": "cmd/server/main.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 228, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 228, - "kind": "local-variable", - "name": "format" - }, - { - "file": "cmd/server/main.go", - "line": 235, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 242, - "kind": "local-variable", - "name": "created" - }, - { - "file": "cmd/server/main.go", - "line": 242, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 251, - "kind": "local-variable", - "name": "init" - }, - { - "file": "cmd/server/main.go", - "line": 255, - "kind": "var", - "name": "bm" - }, - { - "file": "cmd/server/main.go", - "line": 258, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 263, - "kind": "local-variable", - "name": "ap" - }, - { - "file": "cmd/server/main.go", - "line": 264, - "kind": "local-variable", - "name": "chatService" - }, - { - "file": "cmd/server/main.go", - "line": 266, - "kind": "local-variable", - "name": "mgr" - }, - { - "file": "cmd/server/main.go", - "line": 267, - "kind": "local-variable", - "name": "autoCenter" - }, - { - "file": "cmd/server/main.go", - "line": 269, - "kind": "local-variable", - "name": "notifier" - }, - { - "file": "cmd/server/main.go", - "line": 274, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 277, - "kind": "local-variable", - "name": "automationScheduler" - }, - { - "file": "cmd/server/main.go", - "line": 279, - "kind": "local-variable", - "name": "renewalScheduler" - }, - { - "file": "cmd/server/main.go", - "line": 317, - "kind": "function", - "name": "openServerLogWriter" - }, - { - "file": "cmd/server/main.go", - "line": 318, - "kind": "local-variable", - "name": "logDir" - }, - { - "file": "cmd/server/main.go", - "line": 325, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 328, - "kind": "local-variable", - "name": "logPath" - }, - { - "file": "cmd/server/main.go", - "line": 329, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 329, - "kind": "local-variable", - "name": "file" - }, - { - "file": "cmd/server/main.go", - "line": 336, - "kind": "function", - "name": "applyPlaywrightRuntimeRoot" - }, - { - "file": "cmd/server/main.go", - "line": 340, - "kind": "local-variable", - "name": "root" - }, - { - "file": "cmd/server/main.go", - "line": 344, - "kind": "local-variable", - "name": "archRoot" - }, - { - "file": "cmd/server/main.go", - "line": 363, - "kind": "local-variable", - "name": "configDir" - }, - { - "file": "cmd/server/main.go", - "line": 363, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 370, - "kind": "function", - "name": "resolveDBPath" - }, - { - "file": "cmd/server/main.go", - "line": 377, - "kind": "function", - "name": "loadOrCreateDataKey" - }, - { - "file": "cmd/server/main.go", - "line": 382, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 382, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "cmd/server/main.go", - "line": 383, - "kind": "local-variable", - "name": "key" - }, - { - "file": "cmd/server/main.go", - "line": 392, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 395, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "cmd/server/main.go", - "line": 396, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 399, - "kind": "local-variable", - "name": "key" - }, - { - "file": "cmd/server/main.go", - "line": 400, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 406, - "kind": "function", - "name": "ensureAdmin" - }, - { - "file": "cmd/server/main.go", - "line": 413, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 417, - "kind": "function", - "name": "ensureAdminIfMissing" - }, - { - "file": "cmd/server/main.go", - "line": 418, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "cmd/server/main.go", - "line": 418, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main.go", - "line": 425, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 14, - "kind": "function", - "name": "TestEnsureAdminIfMissingCreatesOnlyOnce" - }, - { - "file": "cmd/server/main_test.go", - "line": 15, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/server/main_test.go", - "line": 16, - "kind": "local-variable", - "name": "database" - }, - { - "file": "cmd/server/main_test.go", - "line": 16, - "kind": "local-variable", - "name": "dialect" - }, - { - "file": "cmd/server/main_test.go", - "line": 16, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 21, - "kind": "local-variable", - "name": "store" - }, - { - "file": "cmd/server/main_test.go", - "line": 23, - "kind": "local-variable", - "name": "created" - }, - { - "file": "cmd/server/main_test.go", - "line": 23, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 31, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/server/main_test.go", - "line": 34, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 34, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "cmd/server/main_test.go", - "line": 39, - "kind": "function", - "name": "TestLoadOrCreateDataKeyPersists" - }, - { - "file": "cmd/server/main_test.go", - "line": 40, - "kind": "local-variable", - "name": "path" - }, - { - "file": "cmd/server/main_test.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 41, - "kind": "local-variable", - "name": "first" - }, - { - "file": "cmd/server/main_test.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 48, - "kind": "local-variable", - "name": "second" - }, - { - "file": "cmd/server/main_test.go", - "line": 55, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 55, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "cmd/server/main_test.go", - "line": 60, - "kind": "function", - "name": "TestOpenServerLogWriterUsesConfiguredDirectory" - }, - { - "file": "cmd/server/main_test.go", - "line": 61, - "kind": "local-variable", - "name": "logDir" - }, - { - "file": "cmd/server/main_test.go", - "line": 64, - "kind": "local-variable", - "name": "closeLog" - }, - { - "file": "cmd/server/main_test.go", - "line": 64, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 64, - "kind": "local-variable", - "name": "writer" - }, - { - "file": "cmd/server/main_test.go", - "line": 68, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 73, - "kind": "local-variable", - "name": "content" - }, - { - "file": "cmd/server/main_test.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 82, - "kind": "function", - "name": "TestResolveDataDirKeepsExplicitDirectory" - }, - { - "file": "cmd/server/main_test.go", - "line": 83, - "kind": "local-variable", - "name": "explicit" - }, - { - "file": "cmd/server/main_test.go", - "line": 84, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/main_test.go", - "line": 84, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/server/main_test.go", - "line": 93, - "kind": "function", - "name": "TestUserDataDirName" - }, - { - "file": "cmd/server/main_test.go", - "line": 94, - "kind": "local-variable", - "name": "base" - }, - { - "file": "cmd/server/main_test.go", - "line": 95, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/server/main_test.go", - "line": 96, - "kind": "local-variable", - "name": "want" - }, - { - "file": "cmd/server/main_test.go", - "line": 102, - "kind": "function", - "name": "TestResolveDBPathUsesDataDirectoryForDefault" - }, - { - "file": "cmd/server/main_test.go", - "line": 103, - "kind": "local-variable", - "name": "dataDir" - }, - { - "file": "cmd/server/main_test.go", - "line": 104, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/server/main_test.go", - "line": 105, - "kind": "local-variable", - "name": "want" - }, - { - "file": "cmd/server/main_test.go", - "line": 111, - "kind": "function", - "name": "TestResolveDBPathPreservesCustomPath" - }, - { - "file": "cmd/server/main_test.go", - "line": 112, - "kind": "local-variable", - "name": "dataDir" - }, - { - "file": "cmd/server/main_test.go", - "line": 113, - "kind": "local-variable", - "name": "custom" - }, - { - "file": "cmd/server/main_test.go", - "line": 114, - "kind": "local-variable", - "name": "got" - }, - { - "file": "cmd/server/main_test.go", - "line": 119, - "kind": "function", - "name": "TestPlaywrightRuntimeRootUsesProcessArchitecture" - }, - { - "file": "cmd/server/main_test.go", - "line": 120, - "kind": "local-variable", - "name": "opts" - }, - { - "file": "cmd/server/main_test.go", - "line": 122, - "kind": "local-variable", - "name": "wantRoot" - }, - { - "file": "cmd/server/service_stub.go", - "line": 10, - "kind": "function", - "name": "runPlatformService" - }, - { - "file": "cmd/server/service_windows.go", - "line": 12, - "kind": "type", - "name": "windowsServiceHandler" - }, - { - "file": "cmd/server/service_windows.go", - "line": 16, - "kind": "function", - "name": "runPlatformService" - }, - { - "file": "cmd/server/service_windows.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/server/service_windows.go", - "line": 23, - "kind": "function", - "name": "Execute" - }, - { - "file": "cmd/server/service_windows.go", - "line": 24, - "kind": "const", - "name": "accepted" - }, - { - "file": "cmd/server/service_windows.go", - "line": 27, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/server/service_windows.go", - "line": 27, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/server/service_windows.go", - "line": 28, - "kind": "local-variable", - "name": "done" - }, - { - "file": "cmd/server/service_windows.go", - "line": 34, - "kind": "local-variable", - "name": "request" - }, - { - "file": "cmd/server/service_windows.go", - "line": 40, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/spike/main.go", - "line": 39, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/spike/main.go", - "line": 40, - "kind": "local-variable", - "name": "cookieFile" - }, - { - "file": "cmd/spike/main.go", - "line": 41, - "kind": "local-variable", - "name": "verbose" - }, - { - "file": "cmd/spike/main.go", - "line": 44, - "kind": "local-variable", - "name": "logger" - }, - { - "file": "cmd/spike/main.go", - "line": 49, - "kind": "local-variable", - "name": "cookieStr" - }, - { - "file": "cmd/spike/main.go", - "line": 51, - "kind": "local-variable", - "name": "b" - }, - { - "file": "cmd/spike/main.go", - "line": 51, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/spike/main.go", - "line": 71, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "cmd/spike/main.go", - "line": 71, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "cmd/spike/main.go", - "line": 75, - "kind": "local-variable", - "name": "mc" - }, - { - "file": "cmd/spike/main.go", - "line": 77, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/spike/main.go", - "line": 77, - "kind": "local-variable", - "name": "res" - }, - { - "file": "cmd/spike/main.go", - "line": 86, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "cmd/spike/main.go", - "line": 92, - "kind": "local-variable", - "name": "conn" - }, - { - "file": "cmd/spike/main.go", - "line": 92, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/spike/main.go", - "line": 102, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/spike/main.go", - "line": 108, - "kind": "local-variable", - "name": "gotMessage" - }, - { - "file": "cmd/spike/main.go", - "line": 111, - "kind": "local-variable", - "name": "b" - }, - { - "file": "cmd/tray/icon.go", - "line": 15, - "kind": "var", - "name": "productIconGrayPNG" - }, - { - "file": "cmd/tray/icon.go", - "line": 20, - "kind": "local-variable", - "name": "data" - }, - { - "file": "cmd/tray/icon.go", - "line": 30, - "kind": "function", - "name": "pngToICO" - }, - { - "file": "cmd/tray/icon.go", - "line": 31, - "kind": "const", - "name": "headerSize" - }, - { - "file": "cmd/tray/icon.go", - "line": 32, - "kind": "const", - "name": "entrySize" - }, - { - "file": "cmd/tray/icon.go", - "line": 33, - "kind": "local-variable", - "name": "result" - }, - { - "file": "cmd/tray/icon.go", - "line": 38, - "kind": "local-variable", - "name": "entry" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 13, - "kind": "function", - "name": "acquireTrayInstance" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 14, - "kind": "local-variable", - "name": "cacheDirectory" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 14, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 18, - "kind": "local-variable", - "name": "lockDirectory" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 26, - "kind": "function", - "name": "acquireTrayFileLock" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 27, - "kind": "local-variable", - "name": "lockFile" - }, - { - "file": "cmd/tray/instance_lock_unix.go", - "line": 31, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 10, - "kind": "function", - "name": "TestAcquireTrayInstanceRejectsSecondInstance" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 11, - "kind": "local-variable", - "name": "lockPath" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 12, - "kind": "local-variable", - "name": "acquired" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 12, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 12, - "kind": "local-variable", - "name": "releaseFirst" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 21, - "kind": "local-variable", - "name": "acquired" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 21, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_unix_test.go", - "line": 21, - "kind": "local-variable", - "name": "releaseSecond" - }, - { - "file": "cmd/tray/instance_lock_windows.go", - "line": 11, - "kind": "function", - "name": "acquireTrayInstance" - }, - { - "file": "cmd/tray/instance_lock_windows.go", - "line": 12, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_windows.go", - "line": 12, - "kind": "local-variable", - "name": "mutexName" - }, - { - "file": "cmd/tray/instance_lock_windows.go", - "line": 16, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/instance_lock_windows.go", - "line": 16, - "kind": "local-variable", - "name": "handle" - }, - { - "file": "cmd/tray/main.go", - "line": 24, - "kind": "type", - "name": "healthResponse" - }, - { - "file": "cmd/tray/main.go", - "line": 31, - "kind": "var", - "name": "serviceURL" - }, - { - "file": "cmd/tray/main.go", - "line": 34, - "kind": "var", - "name": "actionMu" - }, - { - "file": "cmd/tray/main.go", - "line": 35, - "kind": "var", - "name": "transitioning" - }, - { - "file": "cmd/tray/main.go", - "line": 36, - "kind": "var", - "name": "exitRequested" - }, - { - "file": "cmd/tray/main.go", - "line": 39, - "kind": "function", - "name": "main" - }, - { - "file": "cmd/tray/main.go", - "line": 40, - "kind": "local-variable", - "name": "closeLog" - }, - { - "file": "cmd/tray/main.go", - "line": 42, - "kind": "local-variable", - "name": "acquired" - }, - { - "file": "cmd/tray/main.go", - "line": 42, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 42, - "kind": "local-variable", - "name": "releaseInstance" - }, - { - "file": "cmd/tray/main.go", - "line": 61, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 70, - "kind": "function", - "name": "watchTerminationSignals" - }, - { - "file": "cmd/tray/main.go", - "line": 71, - "kind": "local-variable", - "name": "signals" - }, - { - "file": "cmd/tray/main.go", - "line": 74, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "cmd/tray/main.go", - "line": 80, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 82, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 92, - "kind": "function", - "name": "onTrayExit" - }, - { - "file": "cmd/tray/main.go", - "line": 98, - "kind": "function", - "name": "configureTrayLogger" - }, - { - "file": "cmd/tray/main.go", - "line": 99, - "kind": "local-variable", - "name": "directory" - }, - { - "file": "cmd/tray/main.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 103, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 106, - "kind": "local-variable", - "name": "path" - }, - { - "file": "cmd/tray/main.go", - "line": 107, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 107, - "kind": "local-variable", - "name": "file" - }, - { - "file": "cmd/tray/main.go", - "line": 116, - "kind": "function", - "name": "onReady" - }, - { - "file": "cmd/tray/main.go", - "line": 121, - "kind": "local-variable", - "name": "statusItem" - }, - { - "file": "cmd/tray/main.go", - "line": 122, - "kind": "local-variable", - "name": "openItem" - }, - { - "file": "cmd/tray/main.go", - "line": 123, - "kind": "local-variable", - "name": "logItem" - }, - { - "file": "cmd/tray/main.go", - "line": 125, - "kind": "local-variable", - "name": "startItem" - }, - { - "file": "cmd/tray/main.go", - "line": 126, - "kind": "local-variable", - "name": "stopItem" - }, - { - "file": "cmd/tray/main.go", - "line": 127, - "kind": "local-variable", - "name": "restartItem" - }, - { - "file": "cmd/tray/main.go", - "line": 129, - "kind": "local-variable", - "name": "quitItem" - }, - { - "file": "cmd/tray/main.go", - "line": 145, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 173, - "kind": "function", - "name": "refreshStatus" - }, - { - "file": "cmd/tray/main.go", - "line": 174, - "kind": "local-variable", - "name": "client" - }, - { - "file": "cmd/tray/main.go", - "line": 187, - "kind": "function", - "name": "refreshStatusOnce" - }, - { - "file": "cmd/tray/main.go", - "line": 188, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 188, - "kind": "local-variable", - "name": "status" - }, - { - "file": "cmd/tray/main.go", - "line": 204, - "kind": "function", - "name": "runServiceAction" - }, - { - "file": "cmd/tray/main.go", - "line": 218, - "kind": "local-variable", - "name": "client" - }, - { - "file": "cmd/tray/main.go", - "line": 220, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 220, - "kind": "local-variable", - "name": "health" - }, - { - "file": "cmd/tray/main.go", - "line": 227, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 233, - "kind": "local-variable", - "name": "wantRunning" - }, - { - "file": "cmd/tray/main.go", - "line": 234, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 251, - "kind": "function", - "name": "exitTray" - }, - { - "file": "cmd/tray/main.go", - "line": 264, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 271, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 283, - "kind": "function", - "name": "setMenuItemsDisabled" - }, - { - "file": "cmd/tray/main.go", - "line": 284, - "kind": "range-variable", - "name": "item" - }, - { - "file": "cmd/tray/main.go", - "line": 293, - "kind": "function", - "name": "waitForService" - }, - { - "file": "cmd/tray/main.go", - "line": 294, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "cmd/tray/main.go", - "line": 296, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 296, - "kind": "local-variable", - "name": "health" - }, - { - "file": "cmd/tray/main.go", - "line": 296, - "kind": "local-variable", - "name": "reachable" - }, - { - "file": "cmd/tray/main.go", - "line": 297, - "kind": "local-variable", - "name": "running" - }, - { - "file": "cmd/tray/main.go", - "line": 316, - "kind": "function", - "name": "readHealth" - }, - { - "file": "cmd/tray/main.go", - "line": 317, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 317, - "kind": "local-variable", - "name": "health" - }, - { - "file": "cmd/tray/main.go", - "line": 321, - "kind": "function", - "name": "probeHealth" - }, - { - "file": "cmd/tray/main.go", - "line": 322, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 322, - "kind": "local-variable", - "name": "resp" - }, - { - "file": "cmd/tray/main.go", - "line": 330, - "kind": "var", - "name": "health" - }, - { - "file": "cmd/tray/main.go", - "line": 331, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 337, - "kind": "function", - "name": "openURL" - }, - { - "file": "cmd/tray/main.go", - "line": 344, - "kind": "function", - "name": "openLogDirectory" - }, - { - "file": "cmd/tray/main.go", - "line": 345, - "kind": "local-variable", - "name": "directory" - }, - { - "file": "cmd/tray/main.go", - "line": 345, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 349, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main.go", - "line": 362, - "kind": "function", - "name": "envOr" - }, - { - "file": "cmd/tray/main.go", - "line": 363, - "kind": "local-variable", - "name": "value" - }, - { - "file": "cmd/tray/main_test.go", - "line": 10, - "kind": "function", - "name": "TestWaitForServiceRequiresHealthyResponse" - }, - { - "file": "cmd/tray/main_test.go", - "line": 11, - "kind": "local-variable", - "name": "server" - }, - { - "file": "cmd/tray/main_test.go", - "line": 16, - "kind": "local-variable", - "name": "originalURL" - }, - { - "file": "cmd/tray/main_test.go", - "line": 20, - "kind": "local-variable", - "name": "client" - }, - { - "file": "cmd/tray/main_test.go", - "line": 21, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main_test.go", - "line": 26, - "kind": "function", - "name": "TestWaitForServiceAcceptsHealthyResponse" - }, - { - "file": "cmd/tray/main_test.go", - "line": 27, - "kind": "local-variable", - "name": "server" - }, - { - "file": "cmd/tray/main_test.go", - "line": 32, - "kind": "local-variable", - "name": "originalURL" - }, - { - "file": "cmd/tray/main_test.go", - "line": 36, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main_test.go", - "line": 41, - "kind": "function", - "name": "TestWaitForServiceDoesNotTreatUnhealthyResponseAsStopped" - }, - { - "file": "cmd/tray/main_test.go", - "line": 42, - "kind": "local-variable", - "name": "server" - }, - { - "file": "cmd/tray/main_test.go", - "line": 46, - "kind": "local-variable", - "name": "originalURL" - }, - { - "file": "cmd/tray/main_test.go", - "line": 50, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/main_test.go", - "line": 55, - "kind": "function", - "name": "TestWaitForServiceAcceptsUnreachableAsStopped" - }, - { - "file": "cmd/tray/main_test.go", - "line": 56, - "kind": "local-variable", - "name": "server" - }, - { - "file": "cmd/tray/main_test.go", - "line": 57, - "kind": "local-variable", - "name": "client" - }, - { - "file": "cmd/tray/main_test.go", - "line": 58, - "kind": "local-variable", - "name": "originalURL" - }, - { - "file": "cmd/tray/main_test.go", - "line": 63, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 14, - "kind": "function", - "name": "serviceAction" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 15, - "kind": "local-variable", - "name": "label" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 16, - "kind": "local-variable", - "name": "uid" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 17, - "kind": "local-variable", - "name": "domain" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 18, - "kind": "local-variable", - "name": "target" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 19, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 19, - "kind": "local-variable", - "name": "home" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 23, - "kind": "local-variable", - "name": "plistPath" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 26, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 33, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 37, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 42, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 45, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 51, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 63, - "kind": "function", - "name": "waitForLaunchctlGone" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 64, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 66, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 76, - "kind": "function", - "name": "quitTray" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 77, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 86, - "kind": "function", - "name": "logDirectoryPath" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 87, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 87, - "kind": "local-variable", - "name": "home" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 94, - "kind": "function", - "name": "launchctl" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 95, - "kind": "local-variable", - "name": "cmd" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 96, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 96, - "kind": "local-variable", - "name": "output" - }, - { - "file": "cmd/tray/service_control_darwin.go", - "line": 98, - "kind": "local-variable", - "name": "message" - }, - { - "file": "cmd/tray/service_control_other.go", - "line": 10, - "kind": "function", - "name": "serviceAction" - }, - { - "file": "cmd/tray/service_control_other.go", - "line": 14, - "kind": "function", - "name": "quitTray" - }, - { - "file": "cmd/tray/service_control_other.go", - "line": 16, - "kind": "function", - "name": "logDirectoryPath" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 16, - "kind": "const", - "name": "windowsServiceAccess" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 18, - "kind": "type", - "name": "windowsServiceController" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 25, - "kind": "type", - "name": "nativeWindowsServiceController" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 29, - "kind": "function", - "name": "serviceAction" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 34, - "kind": "local-variable", - "name": "name" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 35, - "kind": "local-variable", - "name": "controller" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 35, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 53, - "kind": "function", - "name": "openWindowsServiceController" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 54, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 54, - "kind": "local-variable", - "name": "manager" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 60, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 60, - "kind": "local-variable", - "name": "namePointer" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 64, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 64, - "kind": "local-variable", - "name": "handle" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 71, - "kind": "function", - "name": "controlWindowsService" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 87, - "kind": "function", - "name": "ensureWindowsServiceRunning" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 88, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 88, - "kind": "local-variable", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 98, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 103, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 109, - "kind": "function", - "name": "ensureWindowsServiceStopped" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 110, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 110, - "kind": "local-variable", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 120, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 125, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 131, - "kind": "function", - "name": "waitForWindowsServiceState" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 132, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 134, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 134, - "kind": "local-variable", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 148, - "kind": "function", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 149, - "kind": "var", - "name": "status" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 156, - "kind": "function", - "name": "start" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 160, - "kind": "function", - "name": "stop" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 161, - "kind": "var", - "name": "status" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 165, - "kind": "function", - "name": "close" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 169, - "kind": "function", - "name": "quitTray" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 170, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 176, - "kind": "function", - "name": "logDirectoryPath" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 177, - "kind": "local-variable", - "name": "base" - }, - { - "file": "cmd/tray/service_control_windows.go", - "line": 179, - "kind": "var", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 14, - "kind": "type", - "name": "fakeWindowsServiceController" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 19, - "kind": "function", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 23, - "kind": "local-variable", - "name": "state" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 30, - "kind": "function", - "name": "start" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 35, - "kind": "function", - "name": "stop" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 40, - "kind": "function", - "name": "close" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 42, - "kind": "function", - "name": "TestWindowsRestartWaitsForStoppedBeforeStarting" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 43, - "kind": "local-variable", - "name": "controller" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 53, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 56, - "kind": "local-variable", - "name": "want" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 61, - "kind": "function", - "name": "TestWindowsStartWaitsForPreviousStop" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 62, - "kind": "local-variable", - "name": "controller" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 70, - "kind": "local-variable", - "name": "err" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 73, - "kind": "local-variable", - "name": "want" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 78, - "kind": "function", - "name": "TestWindowsServiceAccessIsLimitedToStatusStartStop" - }, - { - "file": "cmd/tray/service_control_windows_test.go", - "line": 79, - "kind": "local-variable", - "name": "want" - }, { "file": "internal/auth/auth.go", "line": 29, @@ -8992,53 +4894,5 @@ "line": 13, "kind": "local-variable", "name": "err" - }, - { - "file": "tools/iconconv/main.go", - "line": 11, - "kind": "function", - "name": "main" - }, - { - "file": "tools/iconconv/main.go", - "line": 17, - "kind": "local-variable", - "name": "data" - }, - { - "file": "tools/iconconv/main.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "tools/iconconv/main.go", - "line": 24, - "kind": "const", - "name": "headerSize" - }, - { - "file": "tools/iconconv/main.go", - "line": 25, - "kind": "const", - "name": "entrySize" - }, - { - "file": "tools/iconconv/main.go", - "line": 26, - "kind": "local-variable", - "name": "result" - }, - { - "file": "tools/iconconv/main.go", - "line": 30, - "kind": "local-variable", - "name": "entry" - }, - { - "file": "tools/iconconv/main.go", - "line": 39, - "kind": "local-variable", - "name": "err" } ] diff --git a/cmd/browser-install/main.go b/cmd/browser-install/main.go index 6e51aba..55c19f3 100644 --- a/cmd/browser-install/main.go +++ b/cmd/browser-install/main.go @@ -10,10 +10,15 @@ import ( "github.com/mxschmitt/playwright-go" ) +// main 负责main相关处理。 func main() { + // driverDir 保存driverDir,供当前处理流程使用 driverDir := flag.String("driver-dir", "", "Playwright driver directory") + // browserDir 保存浏览器Dir,供当前处理流程使用 browserDir := flag.String("browser-dir", "", "Playwright browser cache directory") + // withDeps 保存withDeps,供当前处理流程使用 withDeps := flag.Bool("with-deps", false, "also install Linux system dependencies") + // depsOnly 保存depsOnly,供当前处理流程使用 depsOnly := flag.Bool("deps-only", false, "only install Linux system dependencies; do not download Chromium") flag.Parse() if *depsOnly && !*withDeps { @@ -21,16 +26,19 @@ func main() { } if *driverDir != "" { - if err := os.Setenv("PLAYWRIGHT_DRIVER_PATH", *driverDir); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Setenv("PLAYWRIGHT_DRIVER_PATH", *driverDir); err != nil { fatal("设置 driver 目录失败", err) } } if *browserDir != "" { - if err := os.Setenv("PLAYWRIGHT_BROWSERS_PATH", *browserDir); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Setenv("PLAYWRIGHT_BROWSERS_PATH", *browserDir); err != nil { fatal("设置浏览器目录失败", err) } } + // options 保存options,供当前处理流程使用 options := &playwright.RunOptions{ Browsers: []string{"chromium"}, Verbose: true, @@ -38,14 +46,17 @@ func main() { if *driverDir != "" { options.DriverDirectory = *driverDir } + // driver、err 保存driver、err,供当前处理流程使用 driver, err := playwright.NewDriver(options) if err != nil { fatal("创建 Playwright driver 失败", err) } - if err := driver.DownloadDriver(); err != nil { + if // err 保存err,供当前处理流程使用 + err := driver.DownloadDriver(); err != nil { fatal("下载 Playwright driver 失败", err) } + // args 保存args,供当前处理流程使用 args := []string{"install"} if *depsOnly { args = []string{"install-deps", "chromium"} @@ -55,14 +66,17 @@ func main() { } else { args = append(args, "chromium") } + // cmd 保存cmd,供当前处理流程使用 cmd := driver.Command(args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { + if // err 保存err,供当前处理流程使用 + err := cmd.Run(); err != nil { fatal("安装 Chromium 失败", err) } } +// fatal 负责fatal相关处理。 func fatal(message string, err error) { fmt.Fprintf(os.Stderr, "%s: %v\n", message, err) os.Exit(1) diff --git a/cmd/dbseed/main.go b/cmd/dbseed/main.go index 1309d4b..a1d8eff 100644 --- a/cmd/dbseed/main.go +++ b/cmd/dbseed/main.go @@ -16,6 +16,7 @@ import ( "xianyu-go/internal/db" ) +// seedOptions 保存seedOptions,供当前处理流程使用 type seedOptions struct { Username string Password string @@ -24,19 +25,28 @@ type seedOptions struct { Limit int } +// seedResult 保存seed结果,供当前处理流程使用 type seedResult struct { Items int Orders int Cards int } +// main 负责main相关处理。 func main() { + // sourcePath 保存source路径,供当前处理流程使用 sourcePath := flag.String("source", "/seed/xianyu_data.db", "源 SQLite 文件") + // targetURL 保存targetURL,供当前处理流程使用 targetURL := flag.String("target", "", "目标数据库 URL") + // username 保存username,供当前处理流程使用 username := flag.String("username", "docker_fixture", "测试登录用户名") + // password 保存密码,供当前处理流程使用 password := flag.String("password", "docker_fixture_password", "测试登录密码") + // adminUsername 保存adminUsername,供当前处理流程使用 adminUsername := flag.String("admin-username", "docker_admin", "测试管理员用户名") + // adminPassword 保存admin密码,供当前处理流程使用 adminPassword := flag.String("admin-password", "docker_admin_password", "测试管理员密码") + // limit 保存上限,供当前处理流程使用 limit := flag.Int("limit", 20, "每类最多抽取条数") flag.Parse() if strings.TrimSpace(*targetURL) == "" { @@ -44,22 +54,27 @@ func main() { os.Exit(2) } + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() + // source、err 保存source、err,供当前处理流程使用 source, err := sql.Open("sqlite", "file:"+*sourcePath+"?mode=ro&_pragma=busy_timeout(10000)") if err != nil { fatalf("打开源 SQLite: %v", err) } defer source.Close() - if err := source.PingContext(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := source.PingContext(ctx); err != nil { fatalf("连接源 SQLite: %v", err) } + // targetDB、dialect、err 保存targetDB、dialect、err,供当前处理流程使用 targetDB, dialect, err := db.Open(ctx, *targetURL) if err != nil { fatalf("打开目标数据库: %v", err) } defer targetDB.Close() + // result、err 保存result、err,供当前处理流程使用 result, err := seedFromSQLite(ctx, source, db.NewStore(targetDB, dialect), seedOptions{ Username: *username, Password: *password, @@ -73,6 +88,7 @@ func main() { fmt.Printf("数据库种子完成:items=%d orders=%d cards=%d user=%s\n", result.Items, result.Orders, result.Cards, *username) } +// seedFromSQLite 负责seedFromSQLite相关处理。 func seedFromSQLite(ctx context.Context, source *sql.DB, target *db.Store, options seedOptions) (seedResult, error) { if options.Limit <= 0 || options.Limit > 100 { options.Limit = 20 @@ -86,22 +102,29 @@ func seedFromSQLite(ctx context.Context, source *sql.DB, target *db.Store, optio if options.AdminPassword == "" { options.AdminPassword = "docker_admin_password" } - if err := ensureFixtureAdmin(ctx, target, options.AdminUsername, options.AdminPassword); err != nil { + if // err 保存err,供当前处理流程使用 + err := ensureFixtureAdmin(ctx, target, options.AdminUsername, options.AdminPassword); err != nil { return seedResult{}, err } + // user、err 保存user、err,供当前处理流程使用 user, err := prepareFixtureUser(ctx, target, options) if err != nil { return seedResult{}, err } + // accountID 保存账号ID,供当前处理流程使用 const accountID = "docker-fixture-account" - if err := target.Cookies.Save(ctx, accountID, "unb=docker-fixture; _m_h5_tk=fixture_1;", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := target.Cookies.Save(ctx, accountID, "unb=docker-fixture; _m_h5_tk=fixture_1;", user.ID); err != nil { return seedResult{}, err } - if err := target.Cookies.SetStatusWithReason(ctx, accountID, false, "Docker 脱敏测试账号"); err != nil { + if // err 保存err,供当前处理流程使用 + err := target.Cookies.SetStatusWithReason(ctx, accountID, false, "Docker 脱敏测试账号"); err != nil { return seedResult{}, err } + // result 保存结果,供当前处理流程使用 result := seedResult{} + // itemMap、count、err 保存商品Map、count、err,供当前处理流程使用 itemMap, count, err := seedItems(ctx, source, target, accountID, options.Limit) if err != nil { return result, err @@ -113,12 +136,14 @@ func seedFromSQLite(ctx context.Context, source *sql.DB, target *db.Store, optio } // 保留一条历史脏金额,用于验证三种数据库下统计接口都能安全跳过而不是 500。 fixtureItemID := "" + // id 表示当前遍历过程中的标识 for _, id := range itemMap { fixtureItemID = id break } if fixtureItemID != "" { - if err := target.Orders.Upsert(ctx, "docker-invalid-amount", db.OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := target.Orders.Upsert(ctx, "docker-invalid-amount", db.OrderUpsertOpts{ CookieID: accountID, ItemID: fixtureItemID, BuyerID: "docker-buyer-invalid", Quantity: "1", OrderStatus: "completed", }); err != nil { @@ -133,9 +158,12 @@ func seedFromSQLite(ctx context.Context, source *sql.DB, target *db.Store, optio return result, err } +// ensureFixtureAdmin 负责ensureFixtureAdmin相关处理。 func ensureFixtureAdmin(ctx context.Context, target *db.Store, username, password string) error { + // user、err 保存user、err,供当前处理流程使用 user, err := target.Users.GetByUsername(ctx, username) if errors.Is(err, db.ErrNotFound) { + // created、createErr 保存created、createErr,供当前处理流程使用 created, createErr := target.Users.Create(ctx, username, username+"@docker.test", password) if createErr != nil { return fmt.Errorf("创建测试管理员: %w", createErr) @@ -146,12 +174,14 @@ func ensureFixtureAdmin(ctx context.Context, target *db.Store, username, passwor } else if err != nil { return fmt.Errorf("查询测试管理员: %w", err) } else { + // updated、updateErr 保存updated、updateErr,供当前处理流程使用 updated, updateErr := target.Users.UpdatePassword(ctx, username, password) if updateErr != nil || !updated { return fmt.Errorf("重置测试管理员密码: updated=%v err=%v", updated, updateErr) } } - if err := target.Users.SetAdmin(ctx, username); err != nil { + if // err 保存err,供当前处理流程使用 + err := target.Users.SetAdmin(ctx, username); err != nil { return fmt.Errorf("设置测试管理员: %w", err) } if user != nil { @@ -165,9 +195,12 @@ func ensureFixtureAdmin(ctx context.Context, target *db.Store, username, passwor return nil } +// prepareFixtureUser 负责prepareFixture用户相关处理。 func prepareFixtureUser(ctx context.Context, target *db.Store, options seedOptions) (*db.User, error) { + // user、err 保存user、err,供当前处理流程使用 user, err := target.Users.GetByUsername(ctx, options.Username) if errors.Is(err, db.ErrNotFound) { + // created、createErr 保存created、createErr,供当前处理流程使用 created, createErr := target.Users.Create(ctx, options.Username, options.Username+"@docker.test", options.Password) if createErr != nil { return nil, fmt.Errorf("创建测试用户: %w", createErr) @@ -183,41 +216,53 @@ func prepareFixtureUser(ctx context.Context, target *db.Store, options seedOptio // 测试用户可能来自持久卷中的上一次执行。先移除其自动化规则,释放 // card_id 的 RESTRICT 外键,再清理账号数据和卡密,保留用户主键并重置密码。 + // query 表示当前遍历过程中的查询 for _, query := range []string{ `DELETE FROM automation_rules WHERE user_id=?`, `DELETE FROM cookies WHERE user_id=?`, `DELETE FROM cards WHERE user_id=?`, } { - if _, err := target.DB.ExecContext(ctx, query, user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := target.DB.ExecContext(ctx, query, user.ID); err != nil { return nil, fmt.Errorf("清理上次测试数据: %w", err) } } + // updated、err 保存updated、err,供当前处理流程使用 updated, err := target.Users.UpdatePassword(ctx, options.Username, options.Password) if err != nil || !updated { return nil, fmt.Errorf("重置测试用户密码: updated=%v err=%v", updated, err) } - if _, err := target.DB.ExecContext(ctx, `UPDATE users SET is_active=1,is_admin=0 WHERE id=?`, user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := target.DB.ExecContext(ctx, `UPDATE users SET is_active=1,is_admin=0 WHERE id=?`, user.ID); err != nil { return nil, fmt.Errorf("重置测试用户状态: %w", err) } return target.Users.GetByUsername(ctx, options.Username) } +// seedItems 负责seed商品列表相关处理。 func seedItems(ctx context.Context, source *sql.DB, target *db.Store, accountID string, limit int) (map[string]string, int, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := source.QueryContext(ctx, `SELECT item_id,COALESCE(item_title,''),COALESCE(item_description,''), COALESCE(item_category,''),COALESCE(item_price,'') FROM item_info ORDER BY updated_at DESC LIMIT ?`, limit) if err != nil { return nil, 0, err } defer rows.Close() + // mapping 保存mapping,供当前处理流程使用 mapping := make(map[string]string) + // count 保存数量,供当前处理流程使用 count := 0 for rows.Next() { + // sourceID、title、description、category、price 保存sourceID、title、description、category、price,供当前处理流程使用 var sourceID, title, description, category, price string - if err := rows.Scan(&sourceID, &title, &description, &category, &price); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&sourceID, &title, &description, &category, &price); err != nil { return nil, count, err } + // fixtureID 保存fixtureID,供当前处理流程使用 fixtureID := fmt.Sprintf("docker-item-%03d", count+1) - if err := target.Items.Upsert(ctx, &db.ItemInfoRow{ + if // err 保存err,供当前处理流程使用 + err := target.Items.Upsert(ctx, &db.ItemInfoRow{ CookieID: accountID, ItemID: fixtureID, ItemTitle: fallback(title, "SQLite 测试商品"), ItemDescription: description, ItemCategory: category, ItemPrice: price, }); err != nil { @@ -229,7 +274,9 @@ func seedItems(ctx context.Context, source *sql.DB, target *db.Store, accountID return mapping, count, rows.Err() } +// seedOrders 负责seed订单列表相关处理。 func seedOrders(ctx context.Context, source *sql.DB, target *db.Store, accountID string, items map[string]string, limit int) (int, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := source.QueryContext(ctx, `SELECT order_id,COALESCE(item_id,''),COALESCE(quantity,'1'), COALESCE(amount,'0'),COALESCE(order_status,'unknown'),COALESCE(spec_name,''),COALESCE(spec_value,'') FROM orders ORDER BY updated_at DESC LIMIT ?`, limit*4) @@ -237,22 +284,28 @@ func seedOrders(ctx context.Context, source *sql.DB, target *db.Store, accountID return 0, err } defer rows.Close() + // count 保存数量,供当前处理流程使用 count := 0 for rows.Next() && count < limit { + // sourceOrderID、sourceItemID、quantity、amount、status、specName、specValue 保存source订单ID、source商品ID、quantity、amount、status、specName、spec值,供当前处理流程使用 var sourceOrderID, sourceItemID, quantity, amount, status, specName, specValue string - if err := rows.Scan(&sourceOrderID, &sourceItemID, &quantity, &amount, &status, &specName, &specValue); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&sourceOrderID, &sourceItemID, &quantity, &amount, &status, &specName, &specValue); err != nil { return count, err } + // itemID、ok 保存商品ID、ok,供当前处理流程使用 itemID, ok := items[sourceItemID] if !ok { continue } - if normalized, valid := db.NormalizeOrderAmount(amount); valid { + if // normalized、valid 保存normalized、valid,供当前处理流程使用 + normalized, valid := db.NormalizeOrderAmount(amount); valid { amount = normalized } else { amount = "" } - if err := target.Orders.Upsert(ctx, "docker-order-"+shortHash(sourceOrderID), db.OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := target.Orders.Upsert(ctx, "docker-order-"+shortHash(sourceOrderID), db.OrderUpsertOpts{ CookieID: accountID, ItemID: itemID, BuyerID: "docker-buyer", Quantity: quantity, Amount: amount, OrderStatus: status, SpecName: specName, SpecValue: specValue, }); err != nil { @@ -263,20 +316,27 @@ func seedOrders(ctx context.Context, source *sql.DB, target *db.Store, accountID return count, rows.Err() } +// seedCards 负责seed卡密列表相关处理。 func seedCards(ctx context.Context, source *sql.DB, target *db.Store, userID int64, limit int) (int, error) { + // rows、err 保存rows、err,供当前处理流程使用 rows, err := source.QueryContext(ctx, `SELECT COALESCE(name,''),type,COALESCE(delay_seconds,0) FROM cards ORDER BY updated_at DESC LIMIT ?`, limit) if err != nil { return 0, err } defer rows.Close() + // count 保存数量,供当前处理流程使用 count := 0 for rows.Next() { + // name、cardType 保存name、card类型,供当前处理流程使用 var name, cardType string + // delay 保存延迟,供当前处理流程使用 var delay int - if err := rows.Scan(&name, &cardType, &delay); err != nil { + if // err 保存err,供当前处理流程使用 + err := rows.Scan(&name, &cardType, &delay); err != nil { return count, err } + // card 保存卡密,供当前处理流程使用 card := &db.CardFull{ Name: fmt.Sprintf("[Docker测试] %s %d", fallback(name, "SQLite 卡密"), count+1), Type: "text", TextContent: "Docker 脱敏测试发货内容", Enabled: true, @@ -286,7 +346,8 @@ func seedCards(ctx context.Context, source *sql.DB, target *db.Store, userID int card.Type = "data" card.DataContent = fmt.Sprintf("DOCKER-FIXTURE-%03d-A\nDOCKER-FIXTURE-%03d-B", count+1, count+1) } - if _, err := target.Cards.Create(ctx, card); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := target.Cards.Create(ctx, card); err != nil { return count, err } count++ @@ -294,11 +355,14 @@ func seedCards(ctx context.Context, source *sql.DB, target *db.Store, userID int return count, rows.Err() } +// shortHash 负责shortHash相关处理。 func shortHash(value string) string { + // sum 保存sum,供当前处理流程使用 sum := sha256.Sum256([]byte(value)) return fmt.Sprintf("%x", sum[:6]) } +// fallback 负责fallback相关处理。 func fallback(value, defaultValue string) string { if strings.TrimSpace(value) == "" { return defaultValue @@ -306,6 +370,7 @@ func fallback(value, defaultValue string) string { return value } +// fatalf 负责fatalf相关处理。 func fatalf(format string, args ...any) { fmt.Fprintf(os.Stderr, format+"\n", args...) os.Exit(1) diff --git a/cmd/dbseed/main_test.go b/cmd/dbseed/main_test.go index 8734fe1..146ab0e 100644 --- a/cmd/dbseed/main_test.go +++ b/cmd/dbseed/main_test.go @@ -9,28 +9,37 @@ import ( "xianyu-go/internal/db" ) +// TestSeedFromSQLiteCopiesMetadataAndSanitizesSecrets 负责TestSeedFromSQLiteCopiesMetadataAndSanitizesSecrets相关处理。 func TestSeedFromSQLiteCopiesMetadataAndSanitizesSecrets(t *testing.T) { + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // sourceDB、sourceDialect、err 保存sourceDB、sourceDialect、err,供当前处理流程使用 sourceDB, sourceDialect, err := db.Open(ctx, filepath.Join(t.TempDir(), "source.db")) if err != nil { t.Fatal(err) } defer sourceDB.Close() + // source 保存source,供当前处理流程使用 source := db.NewStore(sourceDB, sourceDialect) source.Users.Create(ctx, "source", "source@example.com", "pw") + // user 保存用户,供当前处理流程使用 user, _ := source.Users.GetByUsername(ctx, "source") source.Cookies.Save(ctx, "real-account", "unb=real-secret; _m_h5_tk=secret;", user.ID) source.Items.Upsert(ctx, &db.ItemInfoRow{CookieID: "real-account", ItemID: "real-item", ItemTitle: "真实商品", ItemPrice: "19.90"}) source.Orders.Upsert(ctx, "real-order", db.OrderUpsertOpts{CookieID: "real-account", ItemID: "real-item", BuyerID: "real-buyer", Amount: "19.90", OrderStatus: "completed"}) source.Cards.Create(ctx, &db.CardFull{Name: "真实卡密", Type: "data", DataContent: "SECRET-CODE", Enabled: true, UserID: user.ID}) + // targetDB、targetDialect、err 保存targetDB、targetDialect、err,供当前处理流程使用 targetDB, targetDialect, err := db.Open(ctx, filepath.Join(t.TempDir(), "target.db")) if err != nil { t.Fatal(err) } defer targetDB.Close() + // target 保存target,供当前处理流程使用 target := db.NewStore(targetDB, targetDialect) + // options 保存options,供当前处理流程使用 options := seedOptions{Username: "fixture", Password: "fixture-password", AdminUsername: "fixture-admin", AdminPassword: "fixture-admin-password", Limit: 10} + // result、err 保存result、err,供当前处理流程使用 result, err := seedFromSQLite(ctx, sourceDB, target, options) if err != nil { t.Fatal(err) @@ -38,24 +47,30 @@ func TestSeedFromSQLiteCopiesMetadataAndSanitizesSecrets(t *testing.T) { if result.Items != 1 || result.Orders != 1 || result.Cards != 1 { t.Fatalf("result=%+v", result) } + // cookie 保存登录凭证,供当前处理流程使用 cookie, _ := target.Cookies.GetValue(ctx, "docker-fixture-account") if strings.Contains(cookie, "real-secret") || strings.Contains(cookie, "secret") { t.Fatalf("source cookie leaked: %q", cookie) } + // fixtureUser 保存fixture用户,供当前处理流程使用 fixtureUser, _ := target.Users.GetByUsername(ctx, "fixture") + // fixtureAdmin、adminErr 保存fixtureAdmin、adminErr,供当前处理流程使用 fixtureAdmin, adminErr := target.Users.GetByUsername(ctx, "fixture-admin") if adminErr != nil || !fixtureAdmin.IsAdmin || !fixtureAdmin.IsActive { t.Fatalf("fixture admin missing or inactive: user=%+v err=%v", fixtureAdmin, adminErr) } + // cards 保存卡密列表,供当前处理流程使用 cards, _ := target.Cards.AllForUser(ctx, fixtureUser.ID) if len(cards) != 1 || strings.Contains(cards[0].DataContent, "SECRET-CODE") { t.Fatalf("source card secret leaked: %+v", cards) } + // invalidOrder、err 保存invalidOrder、err,供当前处理流程使用 invalidOrder, err := target.Orders.Get(ctx, "docker-invalid-amount") if err != nil || invalidOrder.Amount != "not-a-number" { t.Fatalf("invalid amount fixture missing: order=%+v err=%v", invalidOrder, err) } + // second、err 保存second、err,供当前处理流程使用 second, err := seedFromSQLite(ctx, sourceDB, target, options) if err != nil { t.Fatalf("second idempotent seed: %v", err) diff --git a/cmd/dbverify/main.go b/cmd/dbverify/main.go index b684b8f..d1882cb 100644 --- a/cmd/dbverify/main.go +++ b/cmd/dbverify/main.go @@ -23,11 +23,15 @@ import ( "xianyu-go/internal/db" ) +// main 负责main相关处理。 func main() { + // cleanup 保存cleanup,供当前处理流程使用 var cleanup func() error + // fail 保存fail,供当前处理流程使用 fail := func(format string, args ...any) { if cleanup != nil { - if err := cleanup(); err != nil { + if // err 保存err,供当前处理流程使用 + err := cleanup(); err != nil { fmt.Printf("⚠️ 清理验证数据失败: %v\n", err) } } @@ -39,11 +43,14 @@ func main() { fmt.Println("用法: dbverify ") os.Exit(1) } + // url 保存地址,供当前处理流程使用 url := os.Args[1] + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() fmt.Printf("连接 %s ...\n", maskURL(url)) + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := db.Open(ctx, url) if err != nil { fail("❌ Open 失败: %v\n", err) @@ -51,32 +58,43 @@ func main() { defer database.Close() fmt.Printf("✅ 迁移成功,方言=%s\n", dialect) + // store 保存store,供当前处理流程使用 store := db.NewStore(database, dialect) // 1) 创建用户(用唯一用户名,避免在已有数据的库上因 admin 重名而失败)。 ids := newVerifyIDs(time.Now().UnixNano()) + // username 保存username,供当前处理流程使用 username := ids.username + // accountID 保存账号ID,供当前处理流程使用 accountID := ids.accountID + // orderID 保存订单ID,供当前处理流程使用 orderID := ids.orderID + // itemID 保存商品ID,供当前处理流程使用 itemID := ids.itemID + // buyerID 保存买家ID,供当前处理流程使用 buyerID := ids.buyerID cleanup = func() error { + // cleanupCtx、cleanupCancel 保存cleanupCtx、cleanup取消,供当前处理流程使用 cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), 15*time.Second) defer cleanupCancel() return cleanupVerifyData(cleanupCtx, store, ids) } + // password、err 保存password、err,供当前处理流程使用 password, err := newVerifyPassword() if err != nil { fail("❌ 生成验证密码失败: %v\n", err) } + // ok、err 保存ok、err,供当前处理流程使用 ok, err := store.Users.Create(ctx, username, username+"@test.local", password) if err != nil || !ok { fail("❌ 创建用户失败: err=%v ok=%v\n", err, ok) } + // adminUser、err 保存adminUser、err,供当前处理流程使用 adminUser, err := store.Users.GetByUsername(ctx, username) if err != nil { fail("❌ 查询验证用户失败: %v\n", err) } + // userID 保存用户ID,供当前处理流程使用 userID := adminUser.ID fmt.Printf("✅ 创建验证用户 %s (id=%d)\n", username, userID) @@ -84,13 +102,15 @@ func main() { if err := store.Cookies.Save(ctx, accountID, "unb=123; _m_h5_tk=tk_1;", userID); err != nil { fail("❌ 保存 cookie 失败: %v\n", err) } - if err := store.Cookies.SetStatus(ctx, accountID, false); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.SetStatus(ctx, accountID, false); err != nil { fail("❌ 禁用验证账号失败: %v\n", err) } // 再 Save 一次验证 upsert if err := store.Cookies.Save(ctx, accountID, "unb=123; _m_h5_tk=tk_2;", userID); err != nil { fail("❌ 二次保存 cookie 失败: %v\n", err) } + // v 保存v,供当前处理流程使用 v, _ := store.Cookies.GetValue(ctx, accountID) fmt.Printf("✅ cookie upsert 成功,value=%s\n", v) @@ -98,7 +118,8 @@ func main() { if err := store.Settings.Set(ctx, "theme_color", "blue"); err != nil { fail("❌ 系统设置 Set 失败: %v\n", err) } - if err := store.Settings.Set(ctx, "theme_color", "green"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "theme_color", "green"); err != nil { fail("❌ 系统设置二次 Set 失败: %v\n", err) } fmt.Println("✅ 系统设置 upsert 成功(key 保留字处理 OK)") @@ -123,7 +144,8 @@ func main() { }); err != nil { fail("❌ 商品 Upsert 失败: %v\n", err) } - if err := store.Items.Upsert(ctx, &db.ItemInfoRow{ + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, &db.ItemInfoRow{ CookieID: accountID, ItemID: itemID, ItemTitle: "更新后商品", ItemPrice: "29.90", }); err != nil { fail("❌ 商品二次 Upsert 失败: %v\n", err) @@ -153,7 +175,8 @@ func main() { if err != nil { fail("❌ 创建通知渠道失败: %v\n", err) } - if err := store.Notifications.SetBindings(ctx, accountID, []int64{chID}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.SetBindings(ctx, accountID, []int64{chID}); err != nil { fail("❌ 绑定通知渠道失败: %v\n", err) } fmt.Printf("✅ 通知渠道 + 绑定 OK (channel=%d)\n", chID) @@ -166,6 +189,7 @@ func main() { if err != nil { fail("❌ 创建自动化规则失败: %v\n", err) } + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := store.Automation.TryStartRun(ctx, db.AutomationRun{ RuleID: ruleID, CookieID: accountID, TriggerType: "order_paid", TriggerKey: orderID, Status: "running", }) @@ -184,7 +208,8 @@ func main() { } fmt.Printf("✅ 自动化规则 + 防重 OK (rule=%d run=%d)\n", ruleID, runID) - if err := cleanup(); err != nil { + if // err 保存err,供当前处理流程使用 + err := cleanup(); err != nil { fmt.Printf("❌ 清理验证数据失败: %v\n", err) os.Exit(1) } @@ -193,12 +218,15 @@ func main() { fmt.Println("\n🎉 全部验证通过") } +// maskURL 负责maskURL相关处理。 func maskURL(url string) string { // 只显示 scheme 和 host,把 scheme 后到首个 '@' 之间的凭证替换为 ***。 for _, p := range []string{"mysql://", "postgres://", "postgresql://"} { if len(url) > len(p) && url[:len(p)] == p { + // rest 保存rest,供当前处理流程使用 rest := url[len(p):] - if at := strings.Index(rest, "@"); at >= 0 { + if // at 保存at,供当前处理流程使用 + at := strings.Index(rest, "@"); at >= 0 { return p + "***@" + rest[at+1:] } return url @@ -207,6 +235,7 @@ func maskURL(url string) string { return url } +// verifyIDs 保存verifyIDs,供当前处理流程使用 type verifyIDs struct { username string accountID string @@ -215,7 +244,9 @@ type verifyIDs struct { buyerID string } +// newVerifyIDs 负责newVerifyIDs相关处理。 func newVerifyIDs(n int64) verifyIDs { + // suffix 保存suffix,供当前处理流程使用 suffix := fmt.Sprintf("%d", n) return verifyIDs{ username: "verify_" + suffix, @@ -226,19 +257,26 @@ func newVerifyIDs(n int64) verifyIDs { } } +// newVerifyPassword 负责newVerify密码相关处理。 func newVerifyPassword() (string, error) { + // b 保存b,供当前处理流程使用 var b [24]byte - if _, err := rand.Read(b[:]); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := rand.Read(b[:]); err != nil { return "", err } return "verify_" + hex.EncodeToString(b[:]), nil } +// cleanupVerifyData 负责cleanupVerify数据相关处理。 func cleanupVerifyData(ctx context.Context, store *db.Store, ids verifyIDs) error { + // userID 保存用户ID,供当前处理流程使用 userID := int64(0) - if user, err := store.Users.GetByUsername(ctx, ids.username); err == nil { + if // user、err 保存user、err,供当前处理流程使用 + user, err := store.Users.GetByUsername(ctx, ids.username); err == nil { userID = user.ID } + // queries 保存queries,供当前处理流程使用 queries := []struct { query string args []any @@ -256,8 +294,10 @@ func cleanupVerifyData(ctx context.Context, store *db.Store, ids verifyIDs) erro {`DELETE FROM sessions WHERE user_id=?`, []any{userID}}, {`DELETE FROM users WHERE username=? AND email=?`, []any{ids.username, ids.username + "@test.local"}}, } + // q 表示当前遍历过程中的q for _, q := range queries { - if _, err := store.DB.ExecContext(ctx, q.query, q.args...); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, q.query, q.args...); err != nil { return err } } diff --git a/cmd/dbverify/main_test.go b/cmd/dbverify/main_test.go index c6403f4..0868b2e 100644 --- a/cmd/dbverify/main_test.go +++ b/cmd/dbverify/main_test.go @@ -11,6 +11,7 @@ import ( // TestMaskURL 验证带凭证的数据库 URL 脱敏:保留 scheme + host,密码替换为 ***。 func TestMaskURL(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := map[string]string{ "mysql://user:secret@tcp(host:3306)/db?x=1": "mysql://***@tcp(host:3306)/db?x=1", "postgres://user:pass@host:5432/db": "postgres://***@host:5432/db", @@ -18,15 +19,20 @@ func TestMaskURL(t *testing.T) { "sqlite://data/x.db": "sqlite://data/x.db", // 无密码,原样 "/local/path.db": "/local/path.db", // 非 URL,原样 } + // in、want 表示当前遍历过程中的in、want for in, want := range cases { - if got := maskURL(in); got != want { + if // got 保存got,供当前处理流程使用 + got := maskURL(in); got != want { t.Errorf("maskURL(%q) = %q; want %q", in, got, want) } } } +// TestNewVerifyIDsAreUniqueForPersistentRuns 负责TestNewVerifyIDsAreUniqueForPersistent运行记录相关处理。 func TestNewVerifyIDsAreUniqueForPersistentRuns(t *testing.T) { + // ids 保存ids,供当前处理流程使用 ids := newVerifyIDs(12345) + // want 保存want,供当前处理流程使用 want := map[string]string{ "username": "verify_12345", "accountID": "acc_12345", @@ -34,6 +40,7 @@ func TestNewVerifyIDsAreUniqueForPersistentRuns(t *testing.T) { "itemID": "item_12345", "buyerID": "buyer_12345", } + // got 保存got,供当前处理流程使用 got := map[string]string{ "username": ids.username, "accountID": ids.accountID, @@ -41,6 +48,7 @@ func TestNewVerifyIDsAreUniqueForPersistentRuns(t *testing.T) { "itemID": ids.itemID, "buyerID": ids.buyerID, } + // key、wantValue 表示当前遍历过程中的key、want值 for key, wantValue := range want { if got[key] != wantValue { t.Fatalf("%s=%q want %q", key, got[key], wantValue) @@ -51,11 +59,14 @@ func TestNewVerifyIDsAreUniqueForPersistentRuns(t *testing.T) { } } +// TestNewVerifyPasswordIsNotFixedDefault 负责TestNewVerify密码IsNotFixedDefault相关处理。 func TestNewVerifyPasswordIsNotFixedDefault(t *testing.T) { + // first、err 保存first、err,供当前处理流程使用 first, err := newVerifyPassword() if err != nil { t.Fatalf("newVerifyPassword: %v", err) } + // second、err 保存second、err,供当前处理流程使用 second, err := newVerifyPassword() if err != nil { t.Fatalf("newVerifyPassword second: %v", err) @@ -68,24 +79,32 @@ func TestNewVerifyPasswordIsNotFixedDefault(t *testing.T) { } } +// TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled 负责TestCleanupVerify数据RemovesRowsAndVerify数据IsDisabled相关处理。 func TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled(t *testing.T) { + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := db.Open(ctx, filepath.Join(t.TempDir(), "verify.db")) if err != nil { t.Fatalf("Open: %v", err) } defer database.Close() + // store 保存store,供当前处理流程使用 store := db.NewStore(database, dialect) + // ids 保存ids,供当前处理流程使用 ids := newVerifyIDs(987654321) + // password、err 保存password、err,供当前处理流程使用 password, err := newVerifyPassword() if err != nil { t.Fatalf("newVerifyPassword: %v", err) } + // ok、err 保存ok、err,供当前处理流程使用 ok, err := store.Users.Create(ctx, ids.username, ids.username+"@test.local", password) if err != nil || !ok { t.Fatalf("Create user: ok=%v err=%v", ok, err) } + // user、err 保存user、err,供当前处理流程使用 user, err := store.Users.GetByUsername(ctx, ids.username) if err != nil { t.Fatalf("GetByUsername: %v", err) @@ -93,41 +112,51 @@ func TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled(t *testing.T) { if user.IsAdmin { t.Fatal("dbverify 创建的验证用户不应是管理员") } - if err := store.Cookies.Save(ctx, ids.accountID, "unb=123; _m_h5_tk=tk_1;", user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, ids.accountID, "unb=123; _m_h5_tk=tk_1;", user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } - if err := store.Cookies.SetStatus(ctx, ids.accountID, false); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.SetStatus(ctx, ids.accountID, false); err != nil { t.Fatalf("SetStatus false: %v", err) } if store.Cookies.GetStatus(ctx, ids.accountID) { t.Fatal("dbverify 验证账号应默认禁用,避免被服务启动") } - if err := store.Orders.Upsert(ctx, ids.orderID, db.OrderUpsertOpts{ItemID: ids.itemID, BuyerID: ids.buyerID, CookieID: ids.accountID}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, ids.orderID, db.OrderUpsertOpts{ItemID: ids.itemID, BuyerID: ids.buyerID, CookieID: ids.accountID}); err != nil { t.Fatalf("Orders.Upsert: %v", err) } - if err := store.Items.Upsert(ctx, &db.ItemInfoRow{CookieID: ids.accountID, ItemID: ids.itemID, ItemTitle: "测试商品"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Items.Upsert(ctx, &db.ItemInfoRow{CookieID: ids.accountID, ItemID: ids.itemID, ItemTitle: "测试商品"}); err != nil { t.Fatalf("Items.Upsert: %v", err) } + // cardID、err 保存卡密ID、err,供当前处理流程使用 cardID, err := store.Cards.Create(ctx, &db.CardFull{Name: "测试卡组", Type: "data", DataContent: "card", Enabled: true, UserID: user.ID}) if err != nil || cardID == 0 { t.Fatalf("Cards.Create: id=%d err=%v", cardID, err) } + // channelID、err 保存渠道ID、err,供当前处理流程使用 channelID, err := store.Notifications.CreateChannel(ctx, &db.NotificationChannelRow{ Name: "测试渠道", Type: "webhook", Config: `{"webhook_url":"http://x"}`, Enabled: false, UserID: user.ID, }) if err != nil { t.Fatalf("CreateChannel: %v", err) } + // channelEnabled 保存渠道启用状态,供当前处理流程使用 var channelEnabled int - if err := store.DB.QueryRowContext(ctx, `SELECT enabled FROM notification_channels WHERE id=?`, channelID).Scan(&channelEnabled); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT enabled FROM notification_channels WHERE id=?`, channelID).Scan(&channelEnabled); err != nil { t.Fatalf("query channel enabled: %v", err) } if channelEnabled != 0 { t.Fatal("dbverify 验证通知渠道应默认禁用") } - if err := store.Notifications.SetBindings(ctx, ids.accountID, []int64{channelID}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Notifications.SetBindings(ctx, ids.accountID, []int64{channelID}); err != nil { t.Fatalf("SetBindings: %v", err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: user.ID, CookieID: ids.accountID, ItemID: ids.itemID, Name: "付款发货", TriggerType: "order_paid", Enabled: false, Priority: 100, @@ -135,22 +164,28 @@ func TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled(t *testing.T) { if err != nil { t.Fatalf("Automation.Create: %v", err) } - if _, started, err := store.Automation.TryStartRun(ctx, db.AutomationRun{ + if // started、err 保存started、err,供当前处理流程使用 + _, started, err := store.Automation.TryStartRun(ctx, db.AutomationRun{ RuleID: ruleID, CookieID: ids.accountID, TriggerType: "order_paid", TriggerKey: ids.orderID, Status: "running", }); err != nil || !started { t.Fatalf("TryStartRun: started=%v err=%v", started, err) } - if err := cleanupVerifyData(ctx, store, ids); err != nil { + if // err 保存err,供当前处理流程使用 + err := cleanupVerifyData(ctx, store, ids); err != nil { t.Fatalf("cleanupVerifyData: %v", err) } - if _, err := store.Users.GetByUsername(ctx, ids.username); !errors.Is(err, db.ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.GetByUsername(ctx, ids.username); !errors.Is(err, db.ErrNotFound) { t.Fatalf("验证用户应被清理,err=%v", err) } - if _, err := store.Cookies.GetValue(ctx, ids.accountID); !errors.Is(err, db.ErrNotFound) { + if // err 保存err,供当前处理流程使用 + _, err := store.Cookies.GetValue(ctx, ids.accountID); !errors.Is(err, db.ErrNotFound) { t.Fatalf("验证账号应被清理,err=%v", err) } + // count 保存数量,供当前处理流程使用 var count int + // name、query 表示当前遍历过程中的name、query for name, query := range map[string]string{ "automation_runs": `SELECT COUNT(*) FROM automation_runs WHERE cookie_id=? OR trigger_key=?`, "automation_rules": `SELECT COUNT(*) FROM automation_rules WHERE cookie_id=? OR item_id=?`, @@ -158,6 +193,7 @@ func TestCleanupVerifyDataRemovesRowsAndVerifyDataIsDisabled(t *testing.T) { "orders": `SELECT COUNT(*) FROM orders WHERE cookie_id=? OR order_id=?`, "items": `SELECT COUNT(*) FROM item_info WHERE cookie_id=? OR item_id=?`, } { + // err 保存err,供当前处理流程使用 var err error switch name { case "automation_runs", "orders": diff --git a/cmd/init-admin/main.go b/cmd/init-admin/main.go index 257dbd1..91cb6b9 100644 --- a/cmd/init-admin/main.go +++ b/cmd/init-admin/main.go @@ -20,8 +20,11 @@ import ( "xianyu-go/internal/db" ) +// main 负责main相关处理。 func main() { + // dbPath 保存db路径,供当前处理流程使用 dbPath := flag.String("db", "data/xianyu_data.db", "SQLite 数据库路径(兼容旧用法)") + // dbURL 保存dbURL,供当前处理流程使用 dbURL := flag.String("db-url", "", "数据库连接 URL(sqlite:// mysql:// postgres://),优先级高于 -db;也可用 DATABASE_URL 环境变量") flag.Parse() @@ -34,75 +37,93 @@ func main() { resolved = *dbPath } - if err := run(context.Background(), resolved, bufio.NewReader(os.Stdin), os.Stdout); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(context.Background(), resolved, bufio.NewReader(os.Stdin), os.Stdout); err != nil { fatalf("初始化管理员失败: %v", err) } } // run 执行一次初始化流程。把数据库、输入和输出显式注入后,CLI 的核心行为 // 可以在临时数据库中回归测试,而不会调用 os.Exit 或污染用户数据。 +// run 负责运行相关处理。 func run(ctx context.Context, resolved string, reader *bufio.Reader, out io.Writer) error { + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := db.Open(ctx, resolved) if err != nil { return fmt.Errorf("打开数据库失败: %w", err) } defer database.Close() + // store 保存store,供当前处理流程使用 store := db.NewStore(database, dialect) + // existing、err 保存existing、err,供当前处理流程使用 existing, err := store.Users.GetAdmin(ctx) if err != nil && !isNotFound(err) { return fmt.Errorf("查询 admin 失败: %w", err) } if existing != nil { - if _, err := fmt.Fprintf(out, "管理员用户 %s 已存在\n", existing.Username); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintf(out, "管理员用户 %s 已存在\n", existing.Username); err != nil { return err } - if _, err := fmt.Fprint(out, "是否重置管理员密码?(y/N): "); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprint(out, "是否重置管理员密码?(y/N): "); err != nil { return err } + // ans 保存ans,供当前处理流程使用 ans, _ := reader.ReadString('\n') if !strings.HasPrefix(strings.ToLower(strings.TrimSpace(ans)), "y") { - if _, err := fmt.Fprintln(out, "跳过初始化"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out, "跳过初始化"); err != nil { return err } return nil } + // pw、err 保存pw、err,供当前处理流程使用 pw, err := promptPasswordTwice(reader, out) if err != nil { return fmt.Errorf("读取密码失败: %w", err) } - if _, err := auth.InitAdmin(ctx, store, "", pw); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := auth.InitAdmin(ctx, store, "", pw); err != nil { return fmt.Errorf("重置 admin 密码失败: %w", err) } - if _, err := fmt.Fprintf(out, "重置完成:已更新 %s 的密码\n", existing.Username); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintf(out, "重置完成:已更新 %s 的密码\n", existing.Username); err != nil { return err } return nil } - if _, err := fmt.Fprintln(out, "=== 初始化管理员账号(CLI)==="); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out, "=== 初始化管理员账号(CLI)==="); err != nil { return err } - if _, err := fmt.Fprint(out, "请输入管理员邮箱: "); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprint(out, "请输入管理员邮箱: "); err != nil { return err } + // email 保存邮箱,供当前处理流程使用 email, _ := reader.ReadString('\n') email = strings.TrimSpace(email) if email == "" { return errors.New("邮箱不能为空") } + // pw、err 保存pw、err,供当前处理流程使用 pw, err := promptPasswordTwice(reader, out) if err != nil { return fmt.Errorf("读取密码失败: %w", err) } + // created、err 保存created、err,供当前处理流程使用 created, err := auth.InitAdmin(ctx, store, email, pw) if err != nil { return fmt.Errorf("创建 admin 用户失败:%w", err) } if created { - if _, err := fmt.Fprintln(out, "初始化完成:已创建 admin 用户"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out, "初始化完成:已创建 admin 用户"); err != nil { return err } } @@ -112,22 +133,26 @@ func run(ctx context.Context, resolved string, reader *bufio.Reader, out io.Writ // promptPasswordTwice 两次输入密码(不回显)并校验一致性。 func promptPasswordTwice(reader *bufio.Reader, out io.Writer) (string, error) { for { + // p1、err 保存p1、err,供当前处理流程使用 p1, err := readPasswordNoEcho(reader, "请输入管理员密码(不回显): ", out) if err != nil { return "", err } if p1 == "" { - if _, err := fmt.Fprintln(out, "密码不能为空"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out, "密码不能为空"); err != nil { return "", err } continue } + // p2、err 保存p2、err,供当前处理流程使用 p2, err := readPasswordNoEcho(reader, "请再次输入管理员密码(不回显): ", out) if err != nil { return "", err } if p1 != p2 { - if _, err := fmt.Fprintln(out, "两次输入不一致,请重试"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out, "两次输入不一致,请重试"); err != nil { return "", err } continue @@ -138,16 +163,20 @@ func promptPasswordTwice(reader *bufio.Reader, out io.Writer) (string, error) { // readPasswordNoEcho 不回显读取密码。非 TTY 时回退到普通读取(如管道), // 共用同一 bufio.Reader 避免缓冲吞掉后续输入。 +// readPasswordNoEcho 负责read密码NoEcho相关处理。 func readPasswordNoEcho(reader *bufio.Reader, prompt string, out io.Writer) (string, error) { - if _, err := fmt.Fprint(out, prompt); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprint(out, prompt); err != nil { return "", err } if term.IsTerminal(int(os.Stdin.Fd())) { + // b、err 保存b、err,供当前处理流程使用 b, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { return "", err } - if _, err := fmt.Fprintln(out); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out); err != nil { return "", err } return strings.TrimSpace(string(b)), nil @@ -157,16 +186,20 @@ func readPasswordNoEcho(reader *bufio.Reader, prompt string, out io.Writer) (str if err != nil && !errors.Is(err, io.EOF) { return "", err } - if _, err := fmt.Fprintln(out); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintln(out); err != nil { return "", err } return strings.TrimSpace(s), nil } +// isNotFound 负责isNotFound相关处理。 func isNotFound(err error) bool { return errors.Is(err, db.ErrNotFound) } +// fatalf 负责fatalf相关处理。 func fatalf(format string, a ...any) { - if _, err := fmt.Fprintf(os.Stderr, format+"\n", a...); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := fmt.Fprintf(os.Stderr, format+"\n", a...); err != nil { os.Exit(1) } os.Exit(1) diff --git a/cmd/init-admin/main_test.go b/cmd/init-admin/main_test.go index 4d02243..f7e2218 100644 --- a/cmd/init-admin/main_test.go +++ b/cmd/init-admin/main_test.go @@ -14,9 +14,13 @@ import ( "xianyu-go/internal/db" ) +// TestRunCreatesAdminInTemporaryDatabase 负责Test运行CreatesAdminInTemporaryDatabase相关处理。 func TestRunCreatesAdminInTemporaryDatabase(t *testing.T) { + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "init-admin.db") + // out 保存out,供当前处理流程使用 var out bytes.Buffer + // err 保存err,供当前处理流程使用 err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("admin@example.com\nsecret\nsecret\n")), &out) if err != nil { t.Fatalf("run create: %v", err) @@ -24,25 +28,33 @@ func TestRunCreatesAdminInTemporaryDatabase(t *testing.T) { if !strings.Contains(out.String(), "初始化完成") { t.Fatalf("missing create confirmation: %s", out.String()) } + // d、dialect、err 保存d、dialect、err,供当前处理流程使用 d, dialect, err := db.Open(context.Background(), dbPath) if err != nil { t.Fatal(err) } defer d.Close() + // admin、err 保存admin、err,供当前处理流程使用 admin, err := db.NewStore(d, dialect).Users.GetAdmin(context.Background()) if err != nil || admin == nil || admin.Email != "admin@example.com" { t.Fatalf("admin=%+v err=%v", admin, err) } } +// TestRunExistingAdminCanSkipReset 负责Test运行ExistingAdminCanSkipReset相关处理。 func TestRunExistingAdminCanSkipReset(t *testing.T) { + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "init-admin.db") + // input 保存input,供当前处理流程使用 input := "admin@example.com\nsecret\nsecret\n" - if err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader(input)), &bytes.Buffer{}); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader(input)), &bytes.Buffer{}); err != nil { t.Fatal(err) } + // out 保存out,供当前处理流程使用 var out bytes.Buffer - if err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("n\n")), &out); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("n\n")), &out); err != nil { t.Fatal(err) } if !strings.Contains(out.String(), "跳过初始化") { @@ -50,43 +62,59 @@ func TestRunExistingAdminCanSkipReset(t *testing.T) { } } +// TestRunExistingAdminResetsPasswordAfterMismatchRetry 负责Test运行ExistingAdminResets密码AfterMismatch重试相关处理。 func TestRunExistingAdminResetsPasswordAfterMismatchRetry(t *testing.T) { + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "init-admin.db") - if err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("admin@example.com\nold\nold\n")), &bytes.Buffer{}); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("admin@example.com\nold\nold\n")), &bytes.Buffer{}); err != nil { t.Fatal(err) } + // input 保存input,供当前处理流程使用 input := "y\nnew\nnot-the-same\nnew\nnew\n" - if err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader(input)), &bytes.Buffer{}); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader(input)), &bytes.Buffer{}); err != nil { t.Fatal(err) } + // d、dialect、err 保存d、dialect、err,供当前处理流程使用 d, dialect, err := db.Open(context.Background(), dbPath) if err != nil { t.Fatal(err) } defer d.Close() + // store 保存store,供当前处理流程使用 store := db.NewStore(d, dialect) - if _, ok, _ := store.Users.VerifyAndUpgrade(context.Background(), "admin", "old"); ok { + if // ok 保存ok,供当前处理流程使用 + _, ok, _ := store.Users.VerifyAndUpgrade(context.Background(), "admin", "old"); ok { t.Fatal("old password should be invalid") } - if _, ok, _ := store.Users.VerifyAndUpgrade(context.Background(), "admin", "new"); !ok { + if // ok 保存ok,供当前处理流程使用 + _, ok, _ := store.Users.VerifyAndUpgrade(context.Background(), "admin", "new"); !ok { t.Fatal("new password should be valid") } } +// TestRunRejectsEmptyEmail 负责Test运行RejectsEmpty邮箱相关处理。 func TestRunRejectsEmptyEmail(t *testing.T) { + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "init-admin.db") + // err 保存err,供当前处理流程使用 err := run(context.Background(), dbPath, bufio.NewReader(strings.NewReader("\n")), &bytes.Buffer{}) if err == nil || !strings.Contains(err.Error(), "邮箱不能为空") { t.Fatalf("err=%v, want empty email error", err) } } +// TestMainCLIEntrypointUsesDatabaseFlag 负责TestMainCLIEntrypointUsesDatabaseFlag相关处理。 func TestMainCLIEntrypointUsesDatabaseFlag(t *testing.T) { + // dbPath 保存db路径,供当前处理流程使用 dbPath := filepath.Join(t.TempDir(), "main.db") + // stdin、writer、err 保存stdin、writer、err,供当前处理流程使用 stdin, writer, err := os.Pipe() if err != nil { t.Fatal(err) } + // oldArgs、oldStdin、oldEnv、oldCommandLine 保存oldArgs、oldStdin、oldEnv、oldCommandLine,供当前处理流程使用 oldArgs, oldStdin, oldEnv, oldCommandLine := os.Args, os.Stdin, os.Getenv("DATABASE_URL"), flag.CommandLine defer func() { os.Args, os.Stdin, flag.CommandLine = oldArgs, oldStdin, oldCommandLine diff --git a/cmd/server/main.go b/cmd/server/main.go index 19ab471..848379a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -33,6 +33,7 @@ import ( appversion "xianyu-go/internal/version" ) +// serverOptions 保存serverOptions,供当前处理流程使用 type serverOptions struct { dbPath string dbURL string @@ -56,43 +57,53 @@ type serverOptions struct { showVersion bool } +// defaultDBPath 保存defaultDB路径,供当前处理流程使用 const ( defaultDBPath = "data/xianyu_data.db" userDataDirName = "YdisksXianyuHelper" defaultDataKeyName = "data-key" ) +// main 负责main相关处理。 func main() { + // opts 保存opts,供当前处理流程使用 opts := parseOptions() if opts.showVersion { fmt.Printf("Ydisks Xianyu Helper %s (commit %s, built %s)\n", appversion.Version, appversion.ShortCommit(), appversion.BuildTime) return } if opts.workDir != "" { - if err := os.Chdir(opts.workDir); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Chdir(opts.workDir); err != nil { fmt.Fprintf(os.Stderr, "切换工作目录失败: %v\n", err) os.Exit(2) } } + // run 保存运行,供当前处理流程使用 run := func(ctx context.Context) error { return runServer(ctx, opts) } if opts.service { - if err := runPlatformService("YdisksXianyuHelper", run); err != nil { + if // err 保存err,供当前处理流程使用 + err := runPlatformService("YdisksXianyuHelper", run); err != nil { fmt.Fprintf(os.Stderr, "服务运行失败: %v\n", err) os.Exit(1) } return } + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer cancel() - if err := run(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := run(ctx); err != nil { slog.Error("服务退出", "err", err) os.Exit(1) } } +// parseOptions 负责parseOptions相关处理。 func parseOptions() serverOptions { + // opts 保存opts,供当前处理流程使用 var opts serverOptions flag.StringVar(&opts.dbPath, "db", defaultDBPath, "SQLite 数据库路径(兼容旧用法)") flag.StringVar(&opts.dbURL, "db-url", "", "数据库连接 URL(sqlite:// mysql:// postgres://),优先级高于 -db;也可用 DATABASE_URL 环境变量") @@ -118,18 +129,23 @@ func parseOptions() serverOptions { return opts } +// runServer 负责运行Server相关处理。 func runServer(parent context.Context, opts serverOptions) error { + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithCancel(parent) defer cancel() + // dataDir、err 保存数据Dir、err,供当前处理流程使用 dataDir, err := resolveDataDir(opts.workDir) if err != nil { return err } + // packagedPlaywrightRuntime 保存packagedPlaywrightRuntime,供当前处理流程使用 packagedPlaywrightRuntime := strings.TrimSpace(opts.playwrightRuntimeRoot) != "" applyPlaywrightRuntimeRoot(&opts) if dataDir != "" { - if err := os.MkdirAll(dataDir, 0o700); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(dataDir, 0o700); err != nil { return fmt.Errorf("创建应用数据目录失败: %w", err) } if opts.dataKeyFile == "" { @@ -148,25 +164,30 @@ func runServer(parent context.Context, opts serverOptions) error { } if opts.playwrightDriverDir != "" { - if err := os.Setenv("PLAYWRIGHT_DRIVER_PATH", opts.playwrightDriverDir); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Setenv("PLAYWRIGHT_DRIVER_PATH", opts.playwrightDriverDir); err != nil { return fmt.Errorf("设置 Playwright driver 目录失败: %w", err) } } if opts.playwrightBrowserDir != "" { - if err := os.Setenv("PLAYWRIGHT_BROWSERS_PATH", opts.playwrightBrowserDir); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Setenv("PLAYWRIGHT_BROWSERS_PATH", opts.playwrightBrowserDir); err != nil { return fmt.Errorf("设置 Playwright 浏览器目录失败: %w", err) } } if strings.TrimSpace(os.Getenv("XIANYU_DATA_KEY")) == "" && opts.dataKeyFile != "" { + // key、err 保存key、err,供当前处理流程使用 key, err := loadOrCreateDataKey(opts.dataKeyFile) if err != nil { return err } - if err := os.Setenv("XIANYU_DATA_KEY", key); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.Setenv("XIANYU_DATA_KEY", key); err != nil { return fmt.Errorf("设置 XIANYU_DATA_KEY 失败: %w", err) } } + // resolvedDBURL 保存resolvedDBURL,供当前处理流程使用 resolvedDBURL := strings.TrimSpace(os.Getenv("DATABASE_URL")) if resolvedDBURL == "" { resolvedDBURL = strings.TrimSpace(opts.dbURL) @@ -175,12 +196,15 @@ func runServer(parent context.Context, opts serverOptions) error { resolvedDBURL = resolveDBPath(dataDir, opts.dbPath) } if dataDir != "" && resolvedDBURL == resolveDBPath(dataDir, defaultDBPath) { - if err := os.MkdirAll(filepath.Dir(resolvedDBURL), 0o700); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(filepath.Dir(resolvedDBURL), 0o700); err != nil { return fmt.Errorf("创建数据库目录失败: %w", err) } } + // resolvedLogLevel 保存resolvedLogLevel,供当前处理流程使用 resolvedLogLevel := strings.TrimSpace(os.Getenv("LOG_LEVEL")) + // explicitLogLevel 保存explicitLogLevel,供当前处理流程使用 explicitLogLevel := resolvedLogLevel != "" if strings.TrimSpace(opts.logLevel) != "" { resolvedLogLevel = strings.TrimSpace(opts.logLevel) @@ -190,55 +214,68 @@ func runServer(parent context.Context, opts serverOptions) error { resolvedLogLevel = "debug" explicitLogLevel = true } - if err := logging.SetLevel(resolvedLogLevel); err != nil { + if // err 保存err,供当前处理流程使用 + err := logging.SetLevel(resolvedLogLevel); err != nil { return fmt.Errorf("日志等级无效: %w", err) } + // resolvedLogFormat 保存resolvedLogFormat,供当前处理流程使用 resolvedLogFormat := strings.TrimSpace(os.Getenv("LOG_FORMAT")) + // explicitLogFormat 保存explicitLogFormat,供当前处理流程使用 explicitLogFormat := resolvedLogFormat != "" if strings.TrimSpace(opts.logFormat) != "" { resolvedLogFormat = strings.TrimSpace(opts.logFormat) explicitLogFormat = true } + // logWriter、closeLog、err 保存logWriter、closeLog、err,供当前处理流程使用 logWriter, closeLog, err := openServerLogWriter(dataDir) if err != nil { return err } defer closeLog() + // logger 保存logger,供当前处理流程使用 logger := logging.NewLogger(logWriter, resolvedLogFormat) slog.SetDefault(logger) + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := db.Open(ctx, resolvedDBURL) if err != nil { return fmt.Errorf("打开数据库失败: %w", err) } defer database.Close() logger.Info("数据库已就绪", "dialect", dialect) + // store 保存store,供当前处理流程使用 store := db.NewStore(database, dialect) - if err := store.EncryptLegacySecrets(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.EncryptLegacySecrets(ctx); err != nil { return fmt.Errorf("校验或升级数据库敏感字段失败: %w", err) } if !explicitLogLevel { - if lv, err := store.Settings.Get(ctx, "log_level"); err == nil && strings.TrimSpace(lv) != "" { - if err := logging.SetLevel(lv); err != nil { + if // lv、err 保存lv、err,供当前处理流程使用 + lv, err := store.Settings.Get(ctx, "log_level"); err == nil && strings.TrimSpace(lv) != "" { + if // err 保存err,供当前处理流程使用 + err := logging.SetLevel(lv); err != nil { logger.Warn("忽略无效的系统日志设置", "value", lv, "err", err) } } } if !explicitLogFormat { - if format, err := store.Settings.Get(ctx, "log_format"); err == nil && strings.TrimSpace(format) != "" { + if // format、err 保存format、err,供当前处理流程使用 + format, err := store.Settings.Get(ctx, "log_format"); err == nil && strings.TrimSpace(format) != "" { logger = logging.NewLogger(logWriter, format) slog.SetDefault(logger) } } if opts.initAdmin { - if err := ensureAdmin(ctx, store, opts.adminEmail, opts.adminPassword); err != nil { + if // err 保存err,供当前处理流程使用 + err := ensureAdmin(ctx, store, opts.adminEmail, opts.adminPassword); err != nil { return fmt.Errorf("初始化管理员失败: %w", err) } logger.Info("管理员初始化完成", "username", "admin") return nil } if opts.ensureAdmin { + // created、err 保存created、err,供当前处理流程使用 created, err := ensureAdminIfMissing(ctx, store, opts.adminEmail, opts.adminPassword) if err != nil { return fmt.Errorf("检查或初始化管理员失败: %w", err) @@ -248,34 +285,45 @@ func runServer(parent context.Context, opts serverOptions) error { } } - if init, _ := store.Users.IsSystemInitialized(ctx); !init { + if // init 保存init,供当前处理流程使用 + init, _ := store.Users.IsSystemInitialized(ctx); !init { logger.Warn("系统尚未初始化,请先运行本二进制的 -init-admin 初始化管理员") } + // bm 保存bm,供当前处理流程使用 var bm *browser.Manager if !opts.noBrowser { bm = browser.NewManager(logger) - if err := bm.Initialize(); err != nil { + if // err 保存err,供当前处理流程使用 + err := bm.Initialize(); err != nil { return fmt.Errorf("初始化 Playwright Chromium 指纹失败: %w", err) } } + // ap 保存ap,供当前处理流程使用 ap := adapter.New(store, bm, logger) + // chatService 保存聊天Service,供当前处理流程使用 chatService := chat.New(store) ap.SetChatService(chatService) + // mgr 保存mgr,供当前处理流程使用 mgr := account.NewManager(store, ap, logger) + // autoCenter 保存autoCenter,供当前处理流程使用 autoCenter := automation.New(store, mgr, logger) autoCenter.SetOrderDetailFetcher(ap) + // notifier 保存notifier,供当前处理流程使用 notifier := notify.New("", store, logger) notifier.Start(ctx) autoCenter.SetNotifier(notifier) ap.SetAutomation(autoCenter) ap.SetNotifier(notifier) - if err := mgr.StartAll(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := mgr.StartAll(ctx); err != nil { logger.Error("启动账号引擎失败", "err", err) } + // automationScheduler 保存自动化Scheduler,供当前处理流程使用 automationScheduler := automation.NewScheduler(autoCenter) go automationScheduler.Run(ctx) + // renewalScheduler 保存renewalScheduler,供当前处理流程使用 renewalScheduler := renewal.NewScheduler(store, mgr, ap, logger, notifier) go renewalScheduler.Run(ctx) @@ -297,6 +345,7 @@ func runServer(parent context.Context, opts serverOptions) error { cancel() // stopCtx 是关闭 HTTP 服务及其后台 worker 的有限等待上下文。 // stopCancel 释放 stopCtx 的定时器资源。 + // stopCtx、stopCancel 保存stopCtx、stop取消,供当前处理流程使用 stopCtx, stopCancel := context.WithTimeout(context.Background(), 10*time.Second) _ = srv.Stop(stopCtx) stopCancel() @@ -314,7 +363,9 @@ func runServer(parent context.Context, opts serverOptions) error { // desktop/system-service installations persist logs in their platform log // directory. Windows services do not have a useful console, so they get a // default log file beside the service data directory. +// openServerLogWriter 负责openServerLogWriter相关处理。 func openServerLogWriter(dataDir string) (io.Writer, func(), error) { + // logDir 保存logDir,供当前处理流程使用 logDir := strings.TrimSpace(os.Getenv("XIANYU_LOG_DIR")) if logDir == "" && runtime.GOOS == "windows" && dataDir != "" { logDir = filepath.Join(dataDir, "logs") @@ -322,10 +373,13 @@ func openServerLogWriter(dataDir string) (io.Writer, func(), error) { if logDir == "" { return os.Stdout, func() {}, nil } - if err := os.MkdirAll(logDir, 0o700); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(logDir, 0o700); err != nil { return nil, nil, fmt.Errorf("创建日志目录失败: %w", err) } + // logPath 保存log路径,供当前处理流程使用 logPath := filepath.Join(logDir, "server.log") + // file、err 保存file、err,供当前处理流程使用 file, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600) if err != nil { return nil, nil, fmt.Errorf("打开日志文件失败: %w", err) @@ -333,14 +387,17 @@ func openServerLogWriter(dataDir string) (io.Writer, func(), error) { return file, func() { _ = file.Close() }, nil } +// applyPlaywrightRuntimeRoot 负责applyPlaywrightRuntimeRoot相关处理。 func applyPlaywrightRuntimeRoot(opts *serverOptions) { if opts == nil { return } + // root 保存root,供当前处理流程使用 root := strings.TrimSpace(opts.playwrightRuntimeRoot) if root == "" { return } + // archRoot 保存archRoot,供当前处理流程使用 archRoot := filepath.Join(root, runtime.GOARCH) if opts.playwrightDriverDir == "" { opts.playwrightDriverDir = filepath.Join(archRoot, "playwright-driver") @@ -353,6 +410,7 @@ func applyPlaywrightRuntimeRoot(opts *serverOptions) { // resolveDataDir 返回桌面端的标准用户数据目录。 // Linux/Docker 保留原有相对路径行为;macOS 和 Windows 在没有显式 -workdir // 时使用当前用户的系统配置目录,避免把具体用户路径写进安装包或代码。 +// resolveDataDir 负责resolve数据Dir相关处理。 func resolveDataDir(workDir string) (string, error) { if strings.TrimSpace(workDir) != "" { return filepath.Clean(workDir), nil @@ -360,6 +418,7 @@ func resolveDataDir(workDir string) (string, error) { if runtime.GOOS != "darwin" && runtime.GOOS != "windows" { return "", nil } + // configDir、err 保存配置Dir、err,供当前处理流程使用 configDir, err := os.UserConfigDir() if err != nil { return "", fmt.Errorf("读取用户配置目录失败: %w", err) @@ -367,6 +426,7 @@ func resolveDataDir(workDir string) (string, error) { return filepath.Join(configDir, userDataDirName), nil } +// resolveDBPath 负责resolveDB路径相关处理。 func resolveDBPath(dataDir, configuredPath string) string { if dataDir != "" && configuredPath == defaultDBPath { return filepath.Join(dataDir, "data", "xianyu_data.db") @@ -374,12 +434,15 @@ func resolveDBPath(dataDir, configuredPath string) string { return configuredPath } +// loadOrCreateDataKey 负责loadOrCreate数据Key相关处理。 func loadOrCreateDataKey(path string) (string, error) { path = strings.TrimSpace(path) if path == "" { return "", fmt.Errorf("data key 文件路径不能为空") } - if raw, err := os.ReadFile(path); err == nil { + if // raw、err 保存raw、err,供当前处理流程使用 + raw, err := os.ReadFile(path); err == nil { + // key 保存key,供当前处理流程使用 key := strings.TrimSpace(string(raw)) if key == "" { return "", fmt.Errorf("data key 文件为空: %s", path) @@ -389,20 +452,26 @@ func loadOrCreateDataKey(path string) (string, error) { return "", fmt.Errorf("读取 data key 文件失败: %w", err) } - if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { return "", fmt.Errorf("创建 data key 目录失败: %w", err) } + // raw 保存原始,供当前处理流程使用 raw := make([]byte, 48) - if _, err := rand.Read(raw); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := rand.Read(raw); err != nil { return "", fmt.Errorf("生成 data key 失败: %w", err) } + // key 保存key,供当前处理流程使用 key := base64.RawStdEncoding.EncodeToString(raw) - if err := os.WriteFile(path, []byte(key+"\n"), 0o600); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.WriteFile(path, []byte(key+"\n"), 0o600); err != nil { return "", fmt.Errorf("写入 data key 文件失败: %w", err) } return key, nil } +// ensureAdmin 负责ensureAdmin相关处理。 func ensureAdmin(ctx context.Context, store *db.Store, email, password string) error { if password == "" { password = os.Getenv("XIANYU_ADMIN_PASSWORD") @@ -410,11 +479,14 @@ func ensureAdmin(ctx context.Context, store *db.Store, email, password string) e if password == "" { return fmt.Errorf("admin 密码不能为空,请传 -admin-password 或设置 XIANYU_ADMIN_PASSWORD") } + // err 保存err,供当前处理流程使用 _, err := auth.InitAdmin(ctx, store, email, password) return err } +// ensureAdminIfMissing 负责ensureAdminIfMissing相关处理。 func ensureAdminIfMissing(ctx context.Context, store *db.Store, email, password string) (bool, error) { + // admin、err 保存admin、err,供当前处理流程使用 admin, err := store.Users.GetAdmin(ctx) if err != nil && !errors.Is(err, db.ErrNotFound) { return false, fmt.Errorf("查询 admin 失败: %w", err) @@ -422,7 +494,8 @@ func ensureAdminIfMissing(ctx context.Context, store *db.Store, email, password if admin != nil { return false, nil } - if err := ensureAdmin(ctx, store, email, password); err != nil { + if // err 保存err,供当前处理流程使用 + err := ensureAdmin(ctx, store, email, password); err != nil { return false, err } return true, nil diff --git a/cmd/server/main_test.go b/cmd/server/main_test.go index c57d01a..68362a3 100644 --- a/cmd/server/main_test.go +++ b/cmd/server/main_test.go @@ -11,15 +11,20 @@ import ( "xianyu-go/internal/db" ) +// TestEnsureAdminIfMissingCreatesOnlyOnce 负责TestEnsureAdminIfMissingCreatesOnlyOnce相关处理。 func TestEnsureAdminIfMissingCreatesOnlyOnce(t *testing.T) { + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // database、dialect、err 保存database、dialect、err,供当前处理流程使用 database, dialect, err := db.Open(ctx, "sqlite://"+filepath.Join(t.TempDir(), "server.db")) if err != nil { t.Fatalf("open database: %v", err) } t.Cleanup(func() { _ = database.Close() }) + // store 保存store,供当前处理流程使用 store := db.NewStore(database, dialect) + // created、err 保存created、err,供当前处理流程使用 created, err := ensureAdminIfMissing(ctx, store, "admin@example.com", "first-password") if err != nil || !created { t.Fatalf("first ensure: created=%v err=%v", created, err) @@ -28,16 +33,21 @@ func TestEnsureAdminIfMissingCreatesOnlyOnce(t *testing.T) { if err != nil || created { t.Fatalf("second ensure: created=%v err=%v", created, err) } - if _, ok, err := store.Users.VerifyAndUpgrade(ctx, "admin", "first-password"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + _, ok, err := store.Users.VerifyAndUpgrade(ctx, "admin", "first-password"); err != nil || !ok { t.Fatalf("original password should remain valid: ok=%v err=%v", ok, err) } - if _, ok, err := store.Users.VerifyAndUpgrade(ctx, "admin", "second-password"); err == nil || ok { + if // ok、err 保存ok、err,供当前处理流程使用 + _, ok, err := store.Users.VerifyAndUpgrade(ctx, "admin", "second-password"); err == nil || ok { t.Fatalf("later password must not reset admin: ok=%v err=%v", ok, err) } } +// TestLoadOrCreateDataKeyPersists 负责TestLoadOrCreate数据KeyPersists相关处理。 func TestLoadOrCreateDataKeyPersists(t *testing.T) { + // path 保存路径,供当前处理流程使用 path := filepath.Join(t.TempDir(), "data-key") + // first、err 保存first、err,供当前处理流程使用 first, err := loadOrCreateDataKey(path) if err != nil { t.Fatalf("create data key: %v", err) @@ -45,6 +55,7 @@ func TestLoadOrCreateDataKeyPersists(t *testing.T) { if first == "" { t.Fatal("created data key is empty") } + // second、err 保存second、err,供当前处理流程使用 second, err := loadOrCreateDataKey(path) if err != nil { t.Fatalf("load data key: %v", err) @@ -52,24 +63,30 @@ func TestLoadOrCreateDataKeyPersists(t *testing.T) { if first != second { t.Fatalf("data key changed between loads") } - if raw, err := os.ReadFile(path); err != nil || string(raw) == "" { + if // raw、err 保存raw、err,供当前处理流程使用 + raw, err := os.ReadFile(path); err != nil || string(raw) == "" { t.Fatalf("data key file was not written: err=%v", err) } } +// TestOpenServerLogWriterUsesConfiguredDirectory 负责TestOpenServerLogWriterUsesConfiguredDirectory相关处理。 func TestOpenServerLogWriterUsesConfiguredDirectory(t *testing.T) { + // logDir 保存logDir,供当前处理流程使用 logDir := t.TempDir() t.Setenv("XIANYU_LOG_DIR", logDir) + // writer、closeLog、err 保存writer、closeLog、err,供当前处理流程使用 writer, closeLog, err := openServerLogWriter("") if err != nil { t.Fatalf("open log writer: %v", err) } - if _, err := io.WriteString(writer, "test log\n"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := io.WriteString(writer, "test log\n"); err != nil { t.Fatalf("write log: %v", err) } closeLog() + // content、err 保存content、err,供当前处理流程使用 content, err := os.ReadFile(filepath.Join(logDir, "server.log")) if err != nil { t.Fatalf("read log file: %v", err) @@ -79,8 +96,11 @@ func TestOpenServerLogWriterUsesConfiguredDirectory(t *testing.T) { } } +// TestResolveDataDirKeepsExplicitDirectory 负责TestResolve数据DirKeepsExplicitDirectory相关处理。 func TestResolveDataDirKeepsExplicitDirectory(t *testing.T) { + // explicit 保存explicit,供当前处理流程使用 explicit := filepath.Join(t.TempDir(), "ydisks-data") + // got、err 保存got、err,供当前处理流程使用 got, err := resolveDataDir(explicit) if err != nil { t.Fatalf("resolve explicit data directory: %v", err) @@ -90,35 +110,50 @@ func TestResolveDataDirKeepsExplicitDirectory(t *testing.T) { } } +// TestUserDataDirName 负责Test用户数据Dir名称相关处理。 func TestUserDataDirName(t *testing.T) { + // base 保存base,供当前处理流程使用 base := filepath.Join(t.TempDir(), "Application Support") + // got 保存got,供当前处理流程使用 got := filepath.Join(base, userDataDirName) + // want 保存want,供当前处理流程使用 want := filepath.Join(base, "YdisksXianyuHelper") if got != want { t.Fatalf("unexpected user data directory: got %q want %q", got, want) } } +// TestResolveDBPathUsesDataDirectoryForDefault 负责TestResolveDB路径Uses数据DirectoryForDefault相关处理。 func TestResolveDBPathUsesDataDirectoryForDefault(t *testing.T) { + // dataDir 保存数据Dir,供当前处理流程使用 dataDir := filepath.Join(t.TempDir(), "YdisksXianyuHelper") + // got 保存got,供当前处理流程使用 got := resolveDBPath(dataDir, defaultDBPath) + // want 保存want,供当前处理流程使用 want := filepath.Join(dataDir, "data", "xianyu_data.db") if got != want { t.Fatalf("unexpected default database path: got %q want %q", got, want) } } +// TestResolveDBPathPreservesCustomPath 负责TestResolveDB路径PreservesCustom路径相关处理。 func TestResolveDBPathPreservesCustomPath(t *testing.T) { + // dataDir 保存数据Dir,供当前处理流程使用 dataDir := filepath.Join(t.TempDir(), "YdisksXianyuHelper") + // custom 保存custom,供当前处理流程使用 custom := filepath.Join(t.TempDir(), "custom.db") - if got := resolveDBPath(dataDir, custom); got != custom { + if // got 保存got,供当前处理流程使用 + got := resolveDBPath(dataDir, custom); got != custom { t.Fatalf("custom database path changed: got %q want %q", got, custom) } } +// TestPlaywrightRuntimeRootUsesProcessArchitecture 负责TestPlaywrightRuntimeRootUsesProcessArchitecture相关处理。 func TestPlaywrightRuntimeRootUsesProcessArchitecture(t *testing.T) { + // opts 保存opts,供当前处理流程使用 opts := serverOptions{playwrightRuntimeRoot: filepath.Join(t.TempDir(), "playwright-runtime")} applyPlaywrightRuntimeRoot(&opts) + // wantRoot 保存wantRoot,供当前处理流程使用 wantRoot := filepath.Join(opts.playwrightRuntimeRoot, runtime.GOARCH) if opts.playwrightDriverDir != filepath.Join(wantRoot, "playwright-driver") { t.Fatalf("driver 目录=%q", opts.playwrightDriverDir) diff --git a/cmd/server/service_stub.go b/cmd/server/service_stub.go index 951fac5..d9a80b6 100644 --- a/cmd/server/service_stub.go +++ b/cmd/server/service_stub.go @@ -7,6 +7,7 @@ import ( "fmt" ) +// runPlatformService 负责运行PlatformService相关处理。 func runPlatformService(_ string, _ func(context.Context) error) error { return fmt.Errorf("当前平台不支持 -service;请使用系统服务管理器启动普通进程") } diff --git a/cmd/server/service_windows.go b/cmd/server/service_windows.go index 0e362a4..d4d4e27 100644 --- a/cmd/server/service_windows.go +++ b/cmd/server/service_windows.go @@ -9,35 +9,44 @@ import ( "golang.org/x/sys/windows/svc" ) +// windowsServiceHandler 保存windowsServiceHandler,供当前处理流程使用 type windowsServiceHandler struct { run func(context.Context) error } +// runPlatformService 负责运行PlatformService相关处理。 func runPlatformService(name string, run func(context.Context) error) error { - if err := svc.Run(name, windowsServiceHandler{run: run}); err != nil { + if // err 保存err,供当前处理流程使用 + err := svc.Run(name, windowsServiceHandler{run: run}); err != nil { return fmt.Errorf("Windows Service %q: %w", name, err) } return nil } +// Execute 负责Execute相关处理。 func (h windowsServiceHandler) Execute(_ []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) { + // accepted 保存accepted,供当前处理流程使用 const accepted = svc.AcceptStop | svc.AcceptShutdown status <- svc.Status{State: svc.StartPending} + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithCancel(context.Background()) + // done 保存done,供当前处理流程使用 done := make(chan error, 1) go func() { done <- h.run(ctx) }() status <- svc.Status{State: svc.Running, Accepts: accepted} for { select { - case request := <-requests: + case // request 保存请求,供当前处理流程使用 + request := <-requests: switch request.Cmd { case svc.Stop, svc.Shutdown: status <- svc.Status{State: svc.StopPending, Accepts: accepted} cancel() } - case err := <-done: + case // err 保存err,供当前处理流程使用 + err := <-done: cancel() if err != nil { return true, 1 diff --git a/cmd/spike/main.go b/cmd/spike/main.go index 8bc3c5e..f49b1e9 100644 --- a/cmd/spike/main.go +++ b/cmd/spike/main.go @@ -36,18 +36,24 @@ import ( "xianyu-go/internal/xianyu/ws" ) +// main 负责main相关处理。 func main() { + // cookieFile 保存登录凭证文件,供当前处理流程使用 cookieFile := flag.String("cookie-file", "", "从文件读取 cookie(首行)") + // verbose 保存verbose,供当前处理流程使用 verbose := flag.Bool("v", false, "调试日志") flag.Parse() + // logger 保存logger,供当前处理流程使用 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) if *verbose { logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) } + // cookieStr 保存登录凭证Str,供当前处理流程使用 cookieStr := strings.TrimSpace(os.Getenv("XIANYU_COOKIE")) if *cookieFile != "" { + // b、err 保存b、err,供当前处理流程使用 b, err := os.ReadFile(*cookieFile) if err != nil { logger.Error("读取 cookie 文件失败", "err", err) @@ -68,12 +74,15 @@ func main() { } logger.Info("cookie 已加载", "account_hash", logsafe.ID(c["unb"]), "fields", len(c)) + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer cancel() // 1) mtop token API → accessToken。 + // mc 保存mc,供当前处理流程使用 mc := mtop.NewClient() logger.Info("步骤 1/3:刷新 token") + // res、err 保存res、err,供当前处理流程使用 res, err := mc.RefreshToken(cookieStr) if err != nil { logger.Error("刷新 token 失败", "err", err) @@ -83,12 +92,14 @@ func main() { // 2) WS 连接 + 注册。 deviceID := protocol.GenerateDeviceID(c["unb"]) + // cfg 保存cfg,供当前处理流程使用 cfg := ws.Config{ CookieStr: res.UpdatedCookies, DeviceID: deviceID, AccessToken: res.AccessToken, } logger.Info("步骤 2/3:连接 WebSocket", "device_id", deviceID) + // conn、err 保存conn、err,供当前处理流程使用 conn, err := ws.Dial(ctx, cfg, logger) if err != nil { logger.Error("WS 连接/注册失败", "err", err) @@ -99,15 +110,18 @@ func main() { // 3) 心跳 + 收消息。 logger.Info("步骤 3/3:心跳与消息接收(等待闲鱼消息…)") go func() { - if err := conn.HeartbeatLoop(ctx, 15*time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := conn.HeartbeatLoop(ctx, 15*time.Second); err != nil { logger.Error("心跳循环退出", "err", err) cancel() } }() + // gotMessage 保存got消息,供当前处理流程使用 gotMessage := false err = conn.ReceiveLoop(ctx, func(decrypted map[string]any) { gotMessage = true + // b 保存b,供当前处理流程使用 b, _ := json.MarshalIndent(decrypted, "", " ") fmt.Println("\n========== 收到并解密一条消息 ==========") fmt.Println(string(b)) diff --git a/cmd/tray/icon.go b/cmd/tray/icon.go index c3c4913..afe9b32 100644 --- a/cmd/tray/icon.go +++ b/cmd/tray/icon.go @@ -8,15 +8,21 @@ import ( // icon.png 是从根目录 icon/windows/icon.png 同步的彩色产品图标,并直接嵌入托盘二进制。 // +// productIconPNG 保存productIconPNG,供当前处理流程使用 +// //go:embed icon.png var productIconPNG []byte +// productIconGrayPNG 保存productIconGrayPNG,供当前处理流程使用 +// //go:embed icon-gray.png var productIconGrayPNG []byte // trayIconBytes 返回当前服务状态对应的图标,避免运行时依赖外部图标文件。 // Windows 的 Shell_NotifyIcon 需要 ICO;macOS/Linux 可以直接使用 PNG。 +// trayIconBytes 负责trayIconBytes相关处理。 func trayIconBytes(running bool) []byte { + // data 保存数据,供当前处理流程使用 data := productIconGrayPNG if running { data = productIconPNG @@ -27,14 +33,19 @@ func trayIconBytes(running bool) []byte { return pngToICO(data, 256) } +// pngToICO 负责pngToICO相关处理。 func pngToICO(data []byte, size int) []byte { + // headerSize 保存header数量,供当前处理流程使用 const headerSize = 6 + // entrySize 保存entry数量,供当前处理流程使用 const entrySize = 16 + // result 保存结果,供当前处理流程使用 result := make([]byte, headerSize+entrySize+len(data)) // ICONDIR: reserved, type=icon, image count=1. binary.LittleEndian.PutUint16(result[0:2], 0) binary.LittleEndian.PutUint16(result[2:4], 1) binary.LittleEndian.PutUint16(result[4:6], 1) + // entry 保存entry,供当前处理流程使用 entry := result[headerSize : headerSize+entrySize] if size >= 256 { entry[0] = 0 diff --git a/cmd/tray/instance_lock_unix.go b/cmd/tray/instance_lock_unix.go index 01f7911..628b067 100644 --- a/cmd/tray/instance_lock_unix.go +++ b/cmd/tray/instance_lock_unix.go @@ -10,25 +10,32 @@ import ( "golang.org/x/sys/unix" ) +// acquireTrayInstance 负责acquireTrayInstance相关处理。 func acquireTrayInstance() (release func(), acquired bool, err error) { + // cacheDirectory、err 保存cacheDirectory、err,供当前处理流程使用 cacheDirectory, err := os.UserCacheDir() if err != nil { return nil, false, fmt.Errorf("获取用户缓存目录失败: %w", err) } + // lockDirectory 保存锁Directory,供当前处理流程使用 lockDirectory := filepath.Join(cacheDirectory, "YdisksXianyuHelper") - if err := os.MkdirAll(lockDirectory, 0o755); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(lockDirectory, 0o755); err != nil { return nil, false, fmt.Errorf("创建托盘锁目录失败: %w", err) } return acquireTrayFileLock(filepath.Join(lockDirectory, "tray.lock")) } +// acquireTrayFileLock 负责acquireTray文件锁相关处理。 func acquireTrayFileLock(lockPath string) (release func(), acquired bool, err error) { + // lockFile、err 保存锁File、err,供当前处理流程使用 lockFile, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0o600) if err != nil { return nil, false, fmt.Errorf("打开托盘锁文件失败: %w", err) } - if err := unix.Flock(int(lockFile.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil { + if // err 保存err,供当前处理流程使用 + err := unix.Flock(int(lockFile.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil { _ = lockFile.Close() if err == unix.EWOULDBLOCK || err == unix.EAGAIN { return func() {}, false, nil diff --git a/cmd/tray/instance_lock_unix_test.go b/cmd/tray/instance_lock_unix_test.go index b97fd9a..b15b9f7 100644 --- a/cmd/tray/instance_lock_unix_test.go +++ b/cmd/tray/instance_lock_unix_test.go @@ -7,8 +7,11 @@ import ( "testing" ) +// TestAcquireTrayInstanceRejectsSecondInstance 负责TestAcquireTrayInstanceRejectsSecondInstance相关处理。 func TestAcquireTrayInstanceRejectsSecondInstance(t *testing.T) { + // lockPath 保存锁路径,供当前处理流程使用 lockPath := filepath.Join(t.TempDir(), "tray.lock") + // releaseFirst、acquired、err 保存releaseFirst、acquired、err,供当前处理流程使用 releaseFirst, acquired, err := acquireTrayFileLock(lockPath) if err != nil { t.Fatalf("acquire first tray instance: %v", err) @@ -18,6 +21,7 @@ func TestAcquireTrayInstanceRejectsSecondInstance(t *testing.T) { } defer releaseFirst() + // releaseSecond、acquired、err 保存releaseSecond、acquired、err,供当前处理流程使用 releaseSecond, acquired, err := acquireTrayFileLock(lockPath) if err != nil { t.Fatalf("acquire second tray instance: %v", err) diff --git a/cmd/tray/instance_lock_windows.go b/cmd/tray/instance_lock_windows.go index d2f9f9d..fad88a2 100644 --- a/cmd/tray/instance_lock_windows.go +++ b/cmd/tray/instance_lock_windows.go @@ -8,11 +8,14 @@ import ( "golang.org/x/sys/windows" ) +// acquireTrayInstance 负责acquireTrayInstance相关处理。 func acquireTrayInstance() (release func(), acquired bool, err error) { + // mutexName、err 保存mutexName、err,供当前处理流程使用 mutexName, err := windows.UTF16PtrFromString(`Local\YdisksXianyuHelperTray`) if err != nil { return nil, false, fmt.Errorf("生成托盘互斥锁名称失败: %w", err) } + // handle、err 保存handle、err,供当前处理流程使用 handle, err := windows.CreateMutex(nil, false, mutexName) if err == windows.ERROR_ALREADY_EXISTS { if handle != 0 { diff --git a/cmd/tray/main.go b/cmd/tray/main.go index 31f8a7f..eb599fa 100644 --- a/cmd/tray/main.go +++ b/cmd/tray/main.go @@ -21,6 +21,7 @@ import ( "fyne.io/systray" ) +// healthResponse 保存health响应,供当前处理流程使用 type healthResponse struct { Status string `json:"status"` Database string `json:"database"` @@ -28,17 +29,22 @@ type healthResponse struct { Commit string `json:"commit"` } +// serviceURL 保存serviceURL,供当前处理流程使用 var serviceURL = strings.TrimRight(envOr("XIANYU_SERVICE_URL", "http://127.0.0.1:59188"), "/") +// actionMu 保存动作Mu,供当前处理流程使用 var ( actionMu sync.Mutex transitioning atomic.Bool exitRequested atomic.Bool ) +// main 负责main相关处理。 func main() { + // closeLog 保存closeLog,供当前处理流程使用 closeLog := configureTrayLogger() defer closeLog() + // releaseInstance、acquired、err 保存releaseInstance、acquired、err,供当前处理流程使用 releaseInstance, acquired, err := acquireTrayInstance() if err != nil { log.Printf("获取托盘单实例锁失败: %v", err) @@ -58,28 +64,35 @@ func main() { // 但实际托盘进程仍然存活。等事件循环真正返回后再处理外部退出。 if !exitRequested.Load() { log.Printf("托盘事件循环结束,清理后台服务") - if err := quitTray(); err != nil { + if // err 保存err,供当前处理流程使用 + err := quitTray(); err != nil { log.Printf("清理后台服务失败: %v", err) - } else if err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { + } else if // err 保存err,供当前处理流程使用 + err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { log.Printf("等待后台服务退出失败: %v", err) } } log.Printf("托盘退出") } +// watchTerminationSignals 负责watchTerminationSignals相关处理。 func watchTerminationSignals() { + // signals 保存signals,供当前处理流程使用 signals := make(chan os.Signal, 1) signal.Notify(signals, os.Interrupt, syscall.SIGTERM) go func() { + // reason 保存原因,供当前处理流程使用 reason := <-signals log.Printf("收到进程终止信号: %s", reason) actionMu.Lock() // actionMu 保证不会与菜单动作并发;拿到锁时其它动作已经完成。 transitioning.Store(true) - if err := quitTray(); err != nil { + if // err 保存err,供当前处理流程使用 + err := quitTray(); err != nil { log.Printf("终止前停止后台服务失败: %v", err) - } else if err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { + } else if // err 保存err,供当前处理流程使用 + err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { log.Printf("终止前等待后台服务退出失败: %v", err) } transitioning.Store(false) @@ -89,21 +102,27 @@ func watchTerminationSignals() { }() } +// onTrayExit 负责onTrayExit相关处理。 func onTrayExit() { // 这里只记录事件。服务清理由 main 在 systray.Run 返回后执行,避免 // 阻塞原生托盘事件循环。 log.Printf("收到托盘退出事件") } +// configureTrayLogger 负责configureTrayLogger相关处理。 func configureTrayLogger() func() { + // directory、err 保存directory、err,供当前处理流程使用 directory, err := logDirectoryPath() if err != nil { return func() {} } - if err := os.MkdirAll(directory, 0o755); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(directory, 0o755); err != nil { return func() {} } + // path 保存路径,供当前处理流程使用 path := filepath.Join(directory, "tray.log") + // file、err 保存file、err,供当前处理流程使用 file, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) if err != nil { return func() {} @@ -113,19 +132,27 @@ func configureTrayLogger() func() { return func() { _ = file.Close() } } +// onReady 负责onReady相关处理。 func onReady() { systray.SetTitle("") systray.SetIcon(trayIconBytes(false)) systray.SetTooltip("Ydisks闲鱼助手服务") + // statusItem 保存状态商品,供当前处理流程使用 statusItem := systray.AddMenuItem("服务状态:检查中", "读取后台服务状态") + // openItem 保存open商品,供当前处理流程使用 openItem := systray.AddMenuItem("打开管理页面", "在默认浏览器打开管理页面") + // logItem 保存log商品,供当前处理流程使用 logItem := systray.AddMenuItem("打开日志目录", "打开后台服务和托盘日志所在目录") systray.AddSeparator() + // startItem 保存开始商品,供当前处理流程使用 startItem := systray.AddMenuItem("启动服务", "启动后台服务") + // stopItem 保存stop商品,供当前处理流程使用 stopItem := systray.AddMenuItem("停止服务", "停止后台服务") + // restartItem 保存restart商品,供当前处理流程使用 restartItem := systray.AddMenuItem("重启服务", "重启后台服务") systray.AddSeparator() + // quitItem 保存quit商品,供当前处理流程使用 quitItem := systray.AddMenuItem("退出托盘", "停止后台服务并退出菜单栏控制器") // 安装脚本只负责注册平台服务。用户再次打开托盘时,托盘本身必须确保 @@ -136,41 +163,50 @@ func onReady() { refreshStatus(statusItem) }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range openItem.ClickedCh { _ = openURL(serviceURL) } }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range logItem.ClickedCh { - if err := openLogDirectory(); err != nil { + if // err 保存err,供当前处理流程使用 + err := openLogDirectory(); err != nil { statusItem.SetTitle("日志目录:打开失败") systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:打开日志目录失败:%v", err)) } } }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range startItem.ClickedCh { runServiceAction(statusItem, "启动服务", "启动中", "start", startItem, stopItem, restartItem, quitItem) } }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range stopItem.ClickedCh { runServiceAction(statusItem, "停止服务", "正在停止", "stop", startItem, stopItem, restartItem, quitItem) } }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range restartItem.ClickedCh { runServiceAction(statusItem, "重启服务", "正在重启", "restart", startItem, stopItem, restartItem, quitItem) } }() go func() { + // 局部数据 表示当前遍历过程中的局部数据 for range quitItem.ClickedCh { exitTray(statusItem, startItem, stopItem, restartItem, quitItem) } }() } +// refreshStatus 负责refresh状态相关处理。 func refreshStatus(item *systray.MenuItem) { + // client 保存client,供当前处理流程使用 client := &http.Client{Timeout: 2 * time.Second} for { // 与菜单动作使用同一把锁,避免一次已经开始的健康检查在“启动中” @@ -184,7 +220,9 @@ func refreshStatus(item *systray.MenuItem) { } } +// refreshStatusOnce 负责refresh状态Once相关处理。 func refreshStatusOnce(item *systray.MenuItem, client *http.Client) { + // status、err 保存status、err,供当前处理流程使用 status, err := readHealth(client) if err != nil { systray.SetIcon(trayIconBytes(false)) @@ -201,6 +239,7 @@ func refreshStatusOnce(item *systray.MenuItem, client *http.Client) { } } +// runServiceAction 负责运行Service动作相关处理。 func runServiceAction(statusItem *systray.MenuItem, actionName, transitionTitle, action string, actionItems ...*systray.MenuItem) { actionMu.Lock() defer actionMu.Unlock() @@ -215,23 +254,28 @@ func runServiceAction(statusItem *systray.MenuItem, actionName, transitionTitle, systray.SetIcon(trayIconBytes(false)) statusItem.SetTitle("服务状态:" + transitionTitle) systray.SetTooltip("Ydisks闲鱼助手:" + transitionTitle) + // client 保存client,供当前处理流程使用 client := &http.Client{Timeout: 2 * time.Second} if action == "start" { - if health, err := readHealth(client); err == nil && health.Status == "ok" && health.Database == "ok" { + if // health、err 保存health、err,供当前处理流程使用 + health, err := readHealth(client); err == nil && health.Status == "ok" && health.Database == "ok" { statusItem.SetTitle("服务状态:运行正常") systray.SetIcon(trayIconBytes(true)) systray.SetTooltip("Ydisks闲鱼助手:运行正常") return } } - if err := serviceAction(action); err != nil { + if // err 保存err,供当前处理流程使用 + err := serviceAction(action); err != nil { log.Printf("服务操作失败: %s: %v", actionName, err) statusItem.SetTitle("服务状态:操作失败") systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:%s失败:%v", actionName, err)) return } + // wantRunning 保存wantRunning,供当前处理流程使用 wantRunning := action != "stop" - if err := waitForService(client, wantRunning, 30*time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(client, wantRunning, 30*time.Second); err != nil { log.Printf("服务操作状态确认失败: %s: %v", actionName, err) statusItem.SetTitle("服务状态:操作失败") systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:%s后状态确认失败:%v", actionName, err)) @@ -248,6 +292,7 @@ func runServiceAction(statusItem *systray.MenuItem, actionName, transitionTitle, log.Printf("服务操作完成: %s", actionName) } +// exitTray 负责exitTray相关处理。 func exitTray(statusItem *systray.MenuItem, actionItems ...*systray.MenuItem) { actionMu.Lock() defer actionMu.Unlock() @@ -261,14 +306,16 @@ func exitTray(statusItem *systray.MenuItem, actionItems ...*systray.MenuItem) { systray.SetIcon(trayIconBytes(false)) statusItem.SetTitle("托盘状态:正在退出") systray.SetTooltip("Ydisks闲鱼助手:正在停止后台服务") - if err := quitTray(); err != nil { + if // err 保存err,供当前处理流程使用 + err := quitTray(); err != nil { log.Printf("退出托盘停止服务失败: %v", err) statusItem.SetTitle("托盘状态:退出失败") systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:后台服务停止失败:%v", err)) setMenuItemsDisabled(false, actionItems...) return } - if err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(&http.Client{Timeout: 2 * time.Second}, false, 30*time.Second); err != nil { log.Printf("退出托盘等待服务停止失败: %v", err) statusItem.SetTitle("托盘状态:退出失败") systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:后台服务仍未退出:%v", err)) @@ -280,7 +327,9 @@ func exitTray(statusItem *systray.MenuItem, actionItems ...*systray.MenuItem) { systray.Quit() } +// setMenuItemsDisabled 负责setMenu商品列表Disabled相关处理。 func setMenuItemsDisabled(disabled bool, items ...*systray.MenuItem) { + // item 表示当前遍历过程中的商品 for _, item := range items { if disabled { item.Disable() @@ -290,10 +339,14 @@ func setMenuItemsDisabled(disabled bool, items ...*systray.MenuItem) { } } +// waitForService 负责waitForService相关处理。 func waitForService(client *http.Client, wantRunning bool, timeout time.Duration) error { + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(timeout) for { + // health、reachable、err 保存health、reachable、err,供当前处理流程使用 health, reachable, err := probeHealth(client) + // running 保存running,供当前处理流程使用 running := reachable && err == nil && health.Status == "ok" && health.Database == "ok" if wantRunning && running { return nil @@ -313,12 +366,16 @@ func waitForService(client *http.Client, wantRunning bool, timeout time.Duration } } +// readHealth 负责readHealth相关处理。 func readHealth(client *http.Client) (healthResponse, error) { + // health、err 保存health、err,供当前处理流程使用 health, _, err := probeHealth(client) return health, err } +// probeHealth 负责probeHealth相关处理。 func probeHealth(client *http.Client) (healthResponse, bool, error) { + // resp、err 保存resp、err,供当前处理流程使用 resp, err := client.Get(serviceURL + "/health") if err != nil { return healthResponse{}, false, err @@ -327,13 +384,16 @@ func probeHealth(client *http.Client) (healthResponse, bool, error) { if resp.StatusCode < 200 || resp.StatusCode >= 300 { return healthResponse{}, true, fmt.Errorf("health status %d", resp.StatusCode) } + // health 保存health,供当前处理流程使用 var health healthResponse - if err := json.NewDecoder(resp.Body).Decode(&health); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.NewDecoder(resp.Body).Decode(&health); err != nil { return healthResponse{}, true, err } return health, true, nil } +// openURL 负责openURL相关处理。 func openURL(url string) error { if runtime.GOOS == "windows" { return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() @@ -341,12 +401,15 @@ func openURL(url string) error { return exec.Command("open", url).Start() } +// openLogDirectory 负责openLogDirectory相关处理。 func openLogDirectory() error { + // directory、err 保存directory、err,供当前处理流程使用 directory, err := logDirectoryPath() if err != nil { return err } - if err := os.MkdirAll(directory, 0o755); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.MkdirAll(directory, 0o755); err != nil { return fmt.Errorf("创建日志目录失败: %w", err) } switch runtime.GOOS { @@ -359,8 +422,10 @@ func openLogDirectory() error { } } +// envOr 负责envOr相关处理。 func envOr(name, fallback string) string { - if value := strings.TrimSpace(os.Getenv(name)); value != "" { + if // value 保存值,供当前处理流程使用 + value := strings.TrimSpace(os.Getenv(name)); value != "" { return value } return fallback diff --git a/cmd/tray/main_test.go b/cmd/tray/main_test.go index 61949d0..e9af0ee 100644 --- a/cmd/tray/main_test.go +++ b/cmd/tray/main_test.go @@ -7,60 +7,78 @@ import ( "time" ) +// TestWaitForServiceRequiresHealthyResponse 负责TestWaitForServiceRequiresHealthy响应相关处理。 func TestWaitForServiceRequiresHealthyResponse(t *testing.T) { + // server 保存server,供当前处理流程使用 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"status":"degraded","database":"error"}`)) })) t.Cleanup(server.Close) + // originalURL 保存originalURL,供当前处理流程使用 originalURL := serviceURL serviceURL = server.URL t.Cleanup(func() { serviceURL = originalURL }) + // client 保存client,供当前处理流程使用 client := server.Client() - if err := waitForService(client, true, 20*time.Millisecond); err == nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(client, true, 20*time.Millisecond); err == nil { t.Fatal("degraded health response must not count as running") } } +// TestWaitForServiceAcceptsHealthyResponse 负责TestWaitForServiceAcceptsHealthy响应相关处理。 func TestWaitForServiceAcceptsHealthyResponse(t *testing.T) { + // server 保存server,供当前处理流程使用 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"status":"ok","database":"ok"}`)) })) t.Cleanup(server.Close) + // originalURL 保存originalURL,供当前处理流程使用 originalURL := serviceURL serviceURL = server.URL t.Cleanup(func() { serviceURL = originalURL }) - if err := waitForService(server.Client(), true, time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(server.Client(), true, time.Second); err != nil { t.Fatalf("healthy response should count as running: %v", err) } } +// TestWaitForServiceDoesNotTreatUnhealthyResponseAsStopped 负责TestWaitForServiceDoesNotTreatUnhealthy响应AsStopped相关处理。 func TestWaitForServiceDoesNotTreatUnhealthyResponseAsStopped(t *testing.T) { + // server 保存server,供当前处理流程使用 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusServiceUnavailable) })) t.Cleanup(server.Close) + // originalURL 保存originalURL,供当前处理流程使用 originalURL := serviceURL serviceURL = server.URL t.Cleanup(func() { serviceURL = originalURL }) - if err := waitForService(server.Client(), false, 20*time.Millisecond); err == nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(server.Client(), false, 20*time.Millisecond); err == nil { t.Fatal("reachable unhealthy service must not count as stopped") } } +// TestWaitForServiceAcceptsUnreachableAsStopped 负责TestWaitForServiceAcceptsUnreachableAsStopped相关处理。 func TestWaitForServiceAcceptsUnreachableAsStopped(t *testing.T) { + // server 保存server,供当前处理流程使用 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) + // client 保存client,供当前处理流程使用 client := server.Client() + // originalURL 保存originalURL,供当前处理流程使用 originalURL := serviceURL serviceURL = server.URL t.Cleanup(func() { serviceURL = originalURL }) server.Close() - if err := waitForService(client, false, time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForService(client, false, time.Second); err != nil { t.Fatalf("unreachable service should count as stopped: %v", err) } } diff --git a/cmd/tray/service_control_darwin.go b/cmd/tray/service_control_darwin.go index 39fcfbb..9355fbe 100644 --- a/cmd/tray/service_control_darwin.go +++ b/cmd/tray/service_control_darwin.go @@ -11,47 +11,62 @@ import ( "time" ) +// serviceAction 负责service动作相关处理。 func serviceAction(action string) error { + // label 保存label,供当前处理流程使用 label := envOr("XIANYU_SERVICE_NAME", "com.ydisks.xianyu-helper.server") + // uid 保存uid,供当前处理流程使用 uid := fmt.Sprint(os.Getuid()) + // domain 保存domain,供当前处理流程使用 domain := "gui/" + uid + // target 保存target,供当前处理流程使用 target := domain + "/" + label + // home、err 保存home、err,供当前处理流程使用 home, err := os.UserHomeDir() if err != nil { return fmt.Errorf("获取用户目录失败: %w", err) } + // plistPath 保存plist路径,供当前处理流程使用 plistPath := filepath.Join(home, "Library", "LaunchAgents", label+".plist") switch action { case "start": - if err := launchctl("print", target); err == nil { - if err := launchctl("kickstart", target); err == nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("print", target); err == nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("kickstart", target); err == nil { return nil } // launchd 可能仍保留一个正在退出的旧 job;先完整卸载, // 等它消失后再 bootstrap,避免第二次启动报 Input/output error。 _ = launchctl("bootout", target) - if err := waitForLaunchctlGone(target, 10*time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForLaunchctlGone(target, 10*time.Second); err != nil { return err } } - if err := launchctl("bootstrap", domain, plistPath); err != nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("bootstrap", domain, plistPath); err != nil { return err } return launchctl("kickstart", target) case "stop": - if err := launchctl("print", target); err != nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("print", target); err != nil { return nil } - if err := launchctl("bootout", target); err != nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("bootout", target); err != nil { return err } return waitForLaunchctlGone(target, 10*time.Second) case "restart": _ = launchctl("bootout", target) - if err := waitForLaunchctlGone(target, 10*time.Second); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForLaunchctlGone(target, 10*time.Second); err != nil { return err } - if err := launchctl("bootstrap", domain, plistPath); err != nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("bootstrap", domain, plistPath); err != nil { return err } return launchctl("kickstart", target) @@ -60,10 +75,13 @@ func serviceAction(action string) error { } } +// waitForLaunchctlGone 负责waitForLaunchctlGone相关处理。 func waitForLaunchctlGone(target string, timeout time.Duration) error { + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(timeout) for { - if err := launchctl("print", target); err != nil { + if // err 保存err,供当前处理流程使用 + err := launchctl("print", target); err != nil { return nil } if time.Now().After(deadline) { @@ -73,8 +91,10 @@ func waitForLaunchctlGone(target string, timeout time.Duration) error { } } +// quitTray 负责quitTray相关处理。 func quitTray() error { - if err := serviceAction("stop"); err != nil { + if // err 保存err,供当前处理流程使用 + err := serviceAction("stop"); err != nil { return fmt.Errorf("停止后台服务失败: %w", err) } // 不要从托盘进程内部 bootout 自己的 LaunchAgent。launchctl 可能会先 @@ -83,7 +103,9 @@ func quitTray() error { return nil } +// logDirectoryPath 负责logDirectory路径相关处理。 func logDirectoryPath() (string, error) { + // home、err 保存home、err,供当前处理流程使用 home, err := os.UserHomeDir() if err != nil { return "", fmt.Errorf("获取用户目录失败: %w", err) @@ -91,10 +113,14 @@ func logDirectoryPath() (string, error) { return filepath.Join(home, "Library", "Logs", "YdisksXianyuHelper"), nil } +// launchctl 负责launchctl相关处理。 func launchctl(args ...string) error { + // cmd 保存cmd,供当前处理流程使用 cmd := exec.Command("launchctl", args...) + // output、err 保存output、err,供当前处理流程使用 output, err := cmd.CombinedOutput() if err != nil { + // message 保存消息,供当前处理流程使用 message := strings.TrimSpace(string(output)) if message == "" { return fmt.Errorf("launchctl %s 失败: %w", strings.Join(args, " "), err) diff --git a/cmd/tray/service_control_other.go b/cmd/tray/service_control_other.go index 6cbca54..7dec7ad 100644 --- a/cmd/tray/service_control_other.go +++ b/cmd/tray/service_control_other.go @@ -7,12 +7,15 @@ import ( "path/filepath" ) +// serviceAction 负责service动作相关处理。 func serviceAction(action string) error { return fmt.Errorf("当前平台不支持托盘服务操作: %s", action) } +// quitTray 负责quitTray相关处理。 func quitTray() error { return nil } +// logDirectoryPath 负责logDirectory路径相关处理。 func logDirectoryPath() (string, error) { return filepath.Join("/var", "log", "ydisks-xianyu-helper"), nil } diff --git a/cmd/tray/service_control_windows.go b/cmd/tray/service_control_windows.go index 1ca4aa8..70b909a 100644 --- a/cmd/tray/service_control_windows.go +++ b/cmd/tray/service_control_windows.go @@ -13,8 +13,10 @@ import ( "golang.org/x/sys/windows" ) +// windowsServiceAccess 保存windowsServiceAccess,供当前处理流程使用 const windowsServiceAccess = windows.SERVICE_QUERY_STATUS | windows.SERVICE_START | windows.SERVICE_STOP +// windowsServiceController 保存windowsService请求取消控制器,供当前处理流程使用 type windowsServiceController interface { state() (uint32, error) start() error @@ -22,16 +24,20 @@ type windowsServiceController interface { close() } +// nativeWindowsServiceController 保存nativeWindowsService请求取消控制器,供当前处理流程使用 type nativeWindowsServiceController struct { handle windows.Handle } +// serviceAction 负责service动作相关处理。 func serviceAction(action string) error { if action != "start" && action != "stop" && action != "restart" { return fmt.Errorf("未知服务操作: %s", action) } + // name 保存名称,供当前处理流程使用 name := envOr("XIANYU_SERVICE_NAME", "YdisksXianyuHelper") + // controller、err 保存controller、err,供当前处理流程使用 controller, err := openWindowsServiceController(name) if err != nil { if action == "stop" && errors.Is(err, windows.ERROR_SERVICE_DOES_NOT_EXIST) { @@ -50,17 +56,21 @@ func serviceAction(action string) error { return controlWindowsService(controller, action, 30*time.Second, 250*time.Millisecond) } +// openWindowsServiceController 负责openWindowsService请求取消控制器相关处理。 func openWindowsServiceController(name string) (windowsServiceController, error) { + // manager、err 保存manager、err,供当前处理流程使用 manager, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_CONNECT) if err != nil { return nil, err } defer windows.CloseServiceHandle(manager) //nolint:errcheck + // namePointer、err 保存名称Pointer、err,供当前处理流程使用 namePointer, err := windows.UTF16PtrFromString(name) if err != nil { return nil, err } + // handle、err 保存handle、err,供当前处理流程使用 handle, err := windows.OpenService(manager, namePointer, windowsServiceAccess) if err != nil { return nil, err @@ -68,6 +78,7 @@ func openWindowsServiceController(name string) (windowsServiceController, error) return &nativeWindowsServiceController{handle: handle}, nil } +// controlWindowsService 负责controlWindowsService相关处理。 func controlWindowsService(controller windowsServiceController, action string, timeout, pollInterval time.Duration) error { switch action { case "start": @@ -75,7 +86,8 @@ func controlWindowsService(controller windowsServiceController, action string, t case "stop": return ensureWindowsServiceStopped(controller, timeout, pollInterval) case "restart": - if err := ensureWindowsServiceStopped(controller, timeout, pollInterval); err != nil { + if // err 保存err,供当前处理流程使用 + err := ensureWindowsServiceStopped(controller, timeout, pollInterval); err != nil { return err } return ensureWindowsServiceRunning(controller, timeout, pollInterval) @@ -84,7 +96,9 @@ func controlWindowsService(controller windowsServiceController, action string, t } } +// ensureWindowsServiceRunning 负责ensureWindowsServiceRunning相关处理。 func ensureWindowsServiceRunning(controller windowsServiceController, timeout, pollInterval time.Duration) error { + // state、err 保存state、err,供当前处理流程使用 state, err := controller.state() if err != nil { return fmt.Errorf("查询 Windows 服务状态失败: %w", err) @@ -95,18 +109,22 @@ func ensureWindowsServiceRunning(controller windowsServiceController, timeout, p case windows.SERVICE_START_PENDING: return waitForWindowsServiceState(controller, windows.SERVICE_RUNNING, timeout, pollInterval) case windows.SERVICE_STOP_PENDING: - if err := waitForWindowsServiceState(controller, windows.SERVICE_STOPPED, timeout, pollInterval); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForWindowsServiceState(controller, windows.SERVICE_STOPPED, timeout, pollInterval); err != nil { return err } } - if err := controller.start(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_ALREADY_RUNNING) { + if // err 保存err,供当前处理流程使用 + err := controller.start(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_ALREADY_RUNNING) { return fmt.Errorf("启动 Windows 服务失败: %w", err) } return waitForWindowsServiceState(controller, windows.SERVICE_RUNNING, timeout, pollInterval) } +// ensureWindowsServiceStopped 负责ensureWindowsServiceStopped相关处理。 func ensureWindowsServiceStopped(controller windowsServiceController, timeout, pollInterval time.Duration) error { + // state、err 保存state、err,供当前处理流程使用 state, err := controller.state() if err != nil { return fmt.Errorf("查询 Windows 服务状态失败: %w", err) @@ -117,20 +135,25 @@ func ensureWindowsServiceStopped(controller windowsServiceController, timeout, p case windows.SERVICE_STOP_PENDING: return waitForWindowsServiceState(controller, windows.SERVICE_STOPPED, timeout, pollInterval) case windows.SERVICE_START_PENDING: - if err := waitForWindowsServiceState(controller, windows.SERVICE_RUNNING, timeout, pollInterval); err != nil { + if // err 保存err,供当前处理流程使用 + err := waitForWindowsServiceState(controller, windows.SERVICE_RUNNING, timeout, pollInterval); err != nil { return err } } - if err := controller.stop(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_NOT_ACTIVE) { + if // err 保存err,供当前处理流程使用 + err := controller.stop(); err != nil && !errors.Is(err, windows.ERROR_SERVICE_NOT_ACTIVE) { return fmt.Errorf("停止 Windows 服务失败: %w", err) } return waitForWindowsServiceState(controller, windows.SERVICE_STOPPED, timeout, pollInterval) } +// waitForWindowsServiceState 负责waitForWindowsService状态相关处理。 func waitForWindowsServiceState(controller windowsServiceController, expected uint32, timeout, pollInterval time.Duration) error { + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(timeout) for { + // state、err 保存state、err,供当前处理流程使用 state, err := controller.state() if err != nil { return fmt.Errorf("查询 Windows 服务状态失败: %w", err) @@ -145,37 +168,49 @@ func waitForWindowsServiceState(controller windowsServiceController, expected ui } } +// state 负责状态相关处理。 func (controller *nativeWindowsServiceController) state() (uint32, error) { + // status 保存状态,供当前处理流程使用 var status windows.SERVICE_STATUS - if err := windows.QueryServiceStatus(controller.handle, &status); err != nil { + if // err 保存err,供当前处理流程使用 + err := windows.QueryServiceStatus(controller.handle, &status); err != nil { return 0, err } return status.CurrentState, nil } +// start 负责开始相关处理。 func (controller *nativeWindowsServiceController) start() error { return windows.StartService(controller.handle, 0, nil) } +// stop 负责stop相关处理。 func (controller *nativeWindowsServiceController) stop() error { + // status 保存状态,供当前处理流程使用 var status windows.SERVICE_STATUS return windows.ControlService(controller.handle, windows.SERVICE_CONTROL_STOP, &status) } +// close 负责close相关处理。 func (controller *nativeWindowsServiceController) close() { _ = windows.CloseServiceHandle(controller.handle) } +// quitTray 负责quitTray相关处理。 func quitTray() error { - if err := serviceAction("stop"); err != nil { + if // err 保存err,供当前处理流程使用 + err := serviceAction("stop"); err != nil { return fmt.Errorf("停止后台服务失败: %w", err) } return nil } +// logDirectoryPath 负责logDirectory路径相关处理。 func logDirectoryPath() (string, error) { + // base 保存base,供当前处理流程使用 base := strings.TrimSpace(os.Getenv("PROGRAMDATA")) if base == "" { + // err 保存err,供当前处理流程使用 var err error base, err = os.UserConfigDir() if err != nil { diff --git a/cmd/tray/service_control_windows_test.go b/cmd/tray/service_control_windows_test.go index 3160193..97a4193 100644 --- a/cmd/tray/service_control_windows_test.go +++ b/cmd/tray/service_control_windows_test.go @@ -11,15 +11,18 @@ import ( "golang.org/x/sys/windows" ) +// fakeWindowsServiceController 保存fakeWindowsService请求取消控制器,供当前处理流程使用 type fakeWindowsServiceController struct { states []uint32 actions []string } +// state 负责状态相关处理。 func (controller *fakeWindowsServiceController) state() (uint32, error) { if len(controller.states) == 0 { return 0, fmt.Errorf("测试状态序列为空") } + // state 保存状态,供当前处理流程使用 state := controller.states[0] if len(controller.states) > 1 { controller.states = controller.states[1:] @@ -27,19 +30,24 @@ func (controller *fakeWindowsServiceController) state() (uint32, error) { return state, nil } +// start 负责开始相关处理。 func (controller *fakeWindowsServiceController) start() error { controller.actions = append(controller.actions, "start") return nil } +// stop 负责stop相关处理。 func (controller *fakeWindowsServiceController) stop() error { controller.actions = append(controller.actions, "stop") return nil } +// close 负责close相关处理。 func (controller *fakeWindowsServiceController) close() {} +// TestWindowsRestartWaitsForStoppedBeforeStarting 负责TestWindowsRestartWaitsForStoppedBeforeStarting相关处理。 func TestWindowsRestartWaitsForStoppedBeforeStarting(t *testing.T) { + // controller 保存请求取消控制器,供当前处理流程使用 controller := &fakeWindowsServiceController{ states: []uint32{ windows.SERVICE_RUNNING, @@ -50,15 +58,19 @@ func TestWindowsRestartWaitsForStoppedBeforeStarting(t *testing.T) { windows.SERVICE_RUNNING, }, } - if err := controlWindowsService(controller, "restart", time.Second, time.Millisecond); err != nil { + if // err 保存err,供当前处理流程使用 + err := controlWindowsService(controller, "restart", time.Second, time.Millisecond); err != nil { t.Fatalf("restart Windows service: %v", err) } - if want := []string{"stop", "start"}; !reflect.DeepEqual(controller.actions, want) { + if // want 保存want,供当前处理流程使用 + want := []string{"stop", "start"}; !reflect.DeepEqual(controller.actions, want) { t.Fatalf("actions = %v, want %v", controller.actions, want) } } +// TestWindowsStartWaitsForPreviousStop 负责TestWindows开始WaitsForPreviousStop相关处理。 func TestWindowsStartWaitsForPreviousStop(t *testing.T) { + // controller 保存请求取消控制器,供当前处理流程使用 controller := &fakeWindowsServiceController{ states: []uint32{ windows.SERVICE_STOP_PENDING, @@ -67,15 +79,19 @@ func TestWindowsStartWaitsForPreviousStop(t *testing.T) { windows.SERVICE_RUNNING, }, } - if err := controlWindowsService(controller, "start", time.Second, time.Millisecond); err != nil { + if // err 保存err,供当前处理流程使用 + err := controlWindowsService(controller, "start", time.Second, time.Millisecond); err != nil { t.Fatalf("start Windows service: %v", err) } - if want := []string{"start"}; !reflect.DeepEqual(controller.actions, want) { + if // want 保存want,供当前处理流程使用 + want := []string{"start"}; !reflect.DeepEqual(controller.actions, want) { t.Fatalf("actions = %v, want %v", controller.actions, want) } } +// TestWindowsServiceAccessIsLimitedToStatusStartStop 负责TestWindowsServiceAccessIsLimitedTo状态开始Stop相关处理。 func TestWindowsServiceAccessIsLimitedToStatusStartStop(t *testing.T) { + // want 保存want,供当前处理流程使用 want := uint32(windows.SERVICE_QUERY_STATUS | windows.SERVICE_START | windows.SERVICE_STOP) if windowsServiceAccess != want { t.Fatalf("service access = %#x, want %#x", windowsServiceAccess, want) diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 21fb4c8..1ef069f 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -638,3 +638,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成阶段 10 第十二个 PR 切片“Go internal/notify 注释基线按领域清零” | 为通知器、渠道与账号绑定、通知 outbox、SMTP 守卫及其测试补齐函数、变量、字段和常量中文注释;`internal/notify` 注释基线清零;Notify 定向测试、`go test -race ./internal/notify`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/chat 领域注释基线 | | 2026-08-15 | 完成阶段 10 第十三个 PR 切片“Go internal/chat 注释基线按领域清零” | 为聊天 repository、消息服务、账号订阅、已读状态、事件广播及其测试补齐函数、变量、字段和常量中文注释;`internal/chat` 注释基线清零;Chat 定向测试、`go test -race ./internal/chat`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:进入非冻结 browser、cmd 与 tools 注释基线清理 | | 2026-08-15 | 完成阶段 10 第十四个 PR 切片“Go 非冻结 internal/browser 注释基线按领域清零” | 为 Cookie、订单、密码登录、二维码刷新、生命周期、用户数据目录和浏览器辅助测试补齐函数、变量、字段及常量中文注释;严格跳过冻结的 slider/CAPTCHA 实现与测试;非冻结 browser 注释基线清零,冻结文件保留 664 项原有基线;Browser 定向测试和全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 cmd 与 tools 注释基线,并保留冻结基线边界 | +| 2026-08-15 | 完成阶段 10 第十五个 PR 切片“Go cmd 与 tools 注释基线按领域清零” | 为 server、tray、dbseed、dbverify、init-admin、browser-install、spike 命令及 iconconv 工具补齐函数、变量、字段和常量中文注释;`cmd` 与 `tools` 注释基线清零;命令/工具定向测试和全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理剩余基础内部包并保留冻结 browser 基线 | diff --git a/tools/iconconv/main.go b/tools/iconconv/main.go index 00444a5..8ea27c1 100644 --- a/tools/iconconv/main.go +++ b/tools/iconconv/main.go @@ -8,12 +8,14 @@ import ( "os" ) +// main 负责main相关处理。 func main() { if len(os.Args) != 3 { fmt.Fprintln(os.Stderr, "usage: iconconv input.png output.ico") os.Exit(2) } + // data、err 保存data、err,供当前处理流程使用 data, err := os.ReadFile(os.Args[1]) if err != nil { panic(err) @@ -21,12 +23,16 @@ func main() { // A PNG-compressed 256x256 image is valid in an ICO file and keeps the // alpha channel of the original product icon. + // headerSize 保存header数量,供当前处理流程使用 const headerSize = 6 + // entrySize 保存entry数量,供当前处理流程使用 const entrySize = 16 + // result 保存结果,供当前处理流程使用 result := make([]byte, headerSize+entrySize+len(data)) binary.LittleEndian.PutUint16(result[0:2], 0) binary.LittleEndian.PutUint16(result[2:4], 1) binary.LittleEndian.PutUint16(result[4:6], 1) + // entry 保存entry,供当前处理流程使用 entry := result[headerSize : headerSize+entrySize] entry[0] = 0 // 0 means 256 in the ICO format. entry[1] = 0 @@ -36,7 +42,8 @@ func main() { binary.LittleEndian.PutUint32(entry[12:16], headerSize+entrySize) copy(result[headerSize+entrySize:], data) - if err := os.WriteFile(os.Args[2], result, 0644); err != nil { + if // err 保存err,供当前处理流程使用 + err := os.WriteFile(os.Args[2], result, 0644); err != nil { panic(err) } }