diff --git a/deploy/dev/build.py b/deploy/dev/build.py index b6361cf..f1a3d27 100644 --- a/deploy/dev/build.py +++ b/deploy/dev/build.py @@ -40,6 +40,7 @@ DOCKERFILE_NO_CONFIG_TPL = """\ FROM golang:1.25-alpine AS builder RUN apk add --no-cache tzdata WORKDIR /build +ARG GOPROXY="https://goproxy.cn,direct" COPY go.mod go.sum ./ RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY . . diff --git a/deploy/dev/docker-compose.yml b/deploy/dev/docker-compose.yml index 6e5da91..cc14ac0 100644 --- a/deploy/dev/docker-compose.yml +++ b/deploy/dev/docker-compose.yml @@ -119,6 +119,8 @@ services: condition: service_started email-api: condition: service_started + chat-api: + condition: service_started ratelimit: image: envoyproxy/ratelimit:05c08d03 @@ -255,6 +257,11 @@ services: snowflake: condition: service_started + chat-rpc: + image: juwan/chat-rpc:dev + container_name: juwan-chat-rpc + restart: unless-stopped + objectstory-rpc: image: juwan/objectstory-rpc:dev container_name: juwan-objectstory-rpc @@ -371,6 +378,20 @@ services: kafka: condition: service_healthy + chat-api: + image: juwan/chat-api:dev + container_name: juwan-chat-api + restart: unless-stopped + ports: + - "18810:8888" + - "18889:8889" + - "18443:8443/udp" + volumes: + - ./certs:/etc/certs:ro + depends_on: + chat-rpc: + condition: service_started + # ==================== MQ ==================== email-mq: image: juwan/email-mq:dev diff --git a/desc/api/chat.api b/desc/api/chat.api index 05dec40..93c1a58 100644 --- a/desc/api/chat.api +++ b/desc/api/chat.api @@ -6,38 +6,41 @@ type ( Id int64 `path:"id"` } + CreateGroupReq { + Name string `json:"name"` + Participants []int64 `json:"participants,optional"` + } + + CreateDMReq { + TargetId int64 `json:"targetId"` + } + ChatSession { - Id int64 `json:"id"` - Type string `json:"type"` // order, consultation - OrderId string `json:"orderId,optional"` - Participants []SimpleUser `json:"participants"` - LastMessage string `json:"lastMessage"` - UnreadCount int `json:"unreadCount"` + Id int64 `json:"id"` + Type string `json:"type"` + Name string `json:"name"` + CreatorId int64 `json:"creatorId"` + Participants []int64 `json:"participants"` + LastMessage string `json:"lastMessage"` + LastMessageAt int64 `json:"lastMessageAt"` + CreatedAt int64 `json:"createdAt"` } ChatSessionListResp { Items []ChatSession `json:"items"` - Meta PageMeta `json:"meta"` } ChatMessage { - Id int64 `json:"id"` - SessionId string `json:"sessionId"` - SenderId string `json:"senderId"` - Type string `json:"type"` // text, image, system - Content string `json:"content"` - CreatedAt string `json:"createdAt"` + Id int64 `json:"id"` + SessionId int64 `json:"sessionId"` + SenderId int64 `json:"senderId"` + Type string `json:"type"` + Content string `json:"content"` + CreatedAt int64 `json:"createdAt"` } ChatMessageListResp { Items []ChatMessage `json:"items"` - Meta PageMeta `json:"meta"` - } - - SendMessageReq { - SessionIdReq - Type string `json:"type"` - Content string `json:"content"` } ListMessageReq { @@ -51,27 +54,23 @@ type ( group: chat ) service chat-api { - @doc "获取会话列表" + @doc "create group session" + @handler CreateGroup + post /sessions/group (CreateGroupReq) returns (ChatSession) + + @doc "create dm session" + @handler CreateDM + post /sessions/dm (CreateDMReq) returns (ChatSession) + + @doc "list user sessions" @handler ListSessions get /sessions (PageReq) returns (ChatSessionListResp) - @doc "获取会话详情" + @doc "get session detail" @handler GetSession get /sessions/:id (SessionIdReq) returns (ChatSession) - @doc "获取消息历史" + @doc "get message history" @handler ListMessages get /sessions/:id/messages (ListMessageReq) returns (ChatMessageListResp) - - @doc "发送消息" - @handler SendMessage - post /sessions/:id/messages (SendMessageReq) returns (ChatMessage) - - @doc "创建/获取订单会话" - @handler EnsureOrderSession - post /sessions/order (EmptyResp) returns (ChatSession) - - @doc "创建咨询会话" - @handler CreateConsultation - post /sessions/consultation (EmptyResp) returns (ChatSession) -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index b7fd0d2..8fdda18 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module juwan-backend -go 1.25.1 +go 1.24.0 + +toolchain go1.24.4 require ( ariga.io/entcache v0.1.0 @@ -12,8 +14,12 @@ require ( github.com/envoyproxy/go-control-plane/envoy v1.36.0 github.com/golang-jwt/jwt/v4 v4.5.2 github.com/google/uuid v1.6.0 +<<<<<<< HEAD github.com/jackc/pgx/v5 v5.8.0 github.com/jinzhu/copier v0.4.0 +======= + github.com/gorilla/websocket v1.5.3 +>>>>>>> 79f2e26 (add: cn proxy) github.com/lib/pq v1.11.2 github.com/redis/go-redis/v9 v9.17.3 github.com/shopspring/decimal v1.4.0 @@ -54,6 +60,7 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/dunglas/httpsfv v1.1.0 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect github.com/fatih/color v1.18.0 // indirect @@ -96,8 +103,12 @@ require ( github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.66.1 // indirect github.com/prometheus/procfs v0.16.1 // indirect + github.com/quic-go/qpack v0.6.0 // indirect + github.com/quic-go/quic-go v0.59.0 // indirect + github.com/quic-go/webtransport-go v0.10.0 // indirect github.com/segmentio/kafka-go v0.4.47 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/wwweww/go-wst v0.0.0-20260408233151-39a5da1471a4 // indirect github.com/zclconf/go-cty v1.14.4 // indirect github.com/zclconf/go-cty-yaml v1.1.0 // indirect go.etcd.io/etcd/api/v3 v3.5.15 // indirect diff --git a/go.sum b/go.sum index 3ac27aa..5babe0f 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/dunglas/httpsfv v1.1.0 h1:Jw76nAyKWKZKFrpMMcL76y35tOpYHqQPzHQiwDvpe54= +github.com/dunglas/httpsfv v1.1.0/go.mod h1:zID2mqw9mFsnt7YC3vYQ9/cjq30q41W+1AnDwH8TiMg= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane/envoy v1.36.0 h1:yg/JjO5E7ubRyKX3m07GF3reDNEnfOboJ0QySbH736g= @@ -147,6 +149,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grafana/pyroscope-go v1.2.7 h1:VWBBlqxjyR0Cwk2W6UrE8CdcdD80GOFNutj0Kb1T8ac= github.com/grafana/pyroscope-go v1.2.7/go.mod h1:o/bpSLiJYYP6HQtvcoVKiE9s5RiNgjYTj1DhiddP2Pc= github.com/grafana/pyroscope-go/godeltaprof v0.1.9 h1:c1Us8i6eSmkW+Ez05d3co8kasnuOY813tbMN8i/a3Og= @@ -245,6 +249,12 @@ github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9Z github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= +github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= +github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw= +github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/quic-go/webtransport-go v0.10.0 h1:LqXXPOXuETY5Xe8ITdGisBzTYmUOy5eSj+9n4hLTjHI= +github.com/quic-go/webtransport-go v0.10.0/go.mod h1:LeGIXr5BQKE3UsynwVBeQrU1TPrbh73MGoC6jd+V7ow= github.com/redis/go-redis/v9 v9.17.3 h1:fN29NdNrE17KttK5Ndf20buqfDZwGNgoUr9qjl1DQx4= github.com/redis/go-redis/v9 v9.17.3/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= @@ -272,6 +282,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/wwweww/go-wst v0.0.0-20260408233151-39a5da1471a4 h1:Fz6e0U+e5YKhFkuN7uZcnvwRybBP2pMm7r2ZaKZqeOA= +github.com/wwweww/go-wst v0.0.0-20260408233151-39a5da1471a4/go.mod h1:mAAyIR064Gqme5mxiTL6ED589HtyJxDdKZ9ZiJX0VIk= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= diff --git a/package-lock.json b/package-lock.json index 9121b31..20daee9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,10 @@ { - "name": "st-1-example", + "name": "juwan-backend", "lockfileVersion": 3, "requires": true, "packages": { "": { + "name": "juwan-backend", "dependencies": { "@inquirer/prompts": "^8.2.0", "@inquirer/search": "^4.1.0", @@ -345,27 +346,6 @@ } } }, - "node_modules/@isaacs/balanced-match": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz", - "integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==", - "license": "MIT", - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/@isaacs/brace-expansion": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz", - "integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==", - "license": "MIT", - "dependencies": { - "@isaacs/balanced-match": "^4.0.1" - }, - "engines": { - "node": "20 || >=22" - } - }, "node_modules/@sec-ant/readable-stream": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz", @@ -419,6 +399,27 @@ "node": ">=8" } }, + "node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/brace-expansion": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz", + "integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==", + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -772,15 +773,15 @@ } }, "node_modules/minimatch": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.2.tgz", - "integrity": "sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==", + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz", + "integrity": "sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==", "license": "BlueOak-1.0.0", "dependencies": { - "@isaacs/brace-expansion": "^5.0.1" + "brace-expansion": "^5.0.5" }, "engines": { - "node": "20 || >=22" + "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs"