Compare commits
2 Commits
ae2c141efa
...
e916eb2395
Author | SHA1 | Date | |
---|---|---|---|
e916eb2395 | |||
c24ed1e7e6 |
20
go.mod
20
go.mod
@ -3,13 +3,10 @@ module git.solsynth.dev/hypernet/messaging
|
||||
go 1.23.2
|
||||
|
||||
require (
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250329053929-488793a2dc56
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20250315083747-32e91e26013c
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20250216145944-5fb769823a88
|
||||
github.com/dgraph-io/ristretto v0.2.0
|
||||
github.com/eko/gocache/lib/v4 v4.1.6
|
||||
github.com/eko/gocache/store/ristretto/v4 v4.2.2
|
||||
github.com/fatih/color v1.18.0
|
||||
github.com/go-playground/validator/v10 v10.22.1
|
||||
github.com/gofiber/fiber/v2 v2.52.6
|
||||
@ -37,9 +34,10 @@ require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/eapache/channels v1.1.0 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/eko/gocache/lib/v4 v4.2.0 // indirect
|
||||
github.com/eko/gocache/store/redis/v4 v4.2.2 // indirect
|
||||
github.com/frostbyte73/core v0.0.10 // indirect
|
||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
@ -97,14 +95,13 @@ require (
|
||||
github.com/pion/transport/v2 v2.2.4 // indirect
|
||||
github.com/pion/turn/v2 v2.1.3 // indirect
|
||||
github.com/pion/webrtc/v3 v3.2.28 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_golang v1.19.0 // indirect
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.48.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.52.3 // indirect
|
||||
github.com/prometheus/procfs v0.13.0 // indirect
|
||||
github.com/puzpuzpuz/xsync/v3 v3.1.0 // indirect
|
||||
github.com/redis/go-redis/v9 v9.5.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.7.3 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/sagikazarmark/locafero v0.6.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
@ -119,10 +116,9 @@ require (
|
||||
github.com/twitchtv/twirp v8.1.3+incompatible // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.59.0 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/zeebo/xxh3 v1.0.2 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
go.uber.org/zap/exp v0.2.0 // indirect
|
||||
|
43
go.sum
43
go.sum
@ -1,11 +1,9 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1 h1:Jf5yQr8Yln2YkDQ9CwJhVYNstR2vNKPViGnR2YAZLsE=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250301065153-8ac88413e0e1/go.mod h1:AXafZRL/2DISS37ZNngY0DreFAuBoeKu8mEDmCie8kw=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250329053929-488793a2dc56 h1:SnT9NVcXQ1WDka9kKAA+lH/r2UJouND7FDugu4ZZwLc=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20250329053929-488793a2dc56/go.mod h1:5tk62VQ1DcbR0EAN2jAOqYxHiegUPEC805JlfQ/G19I=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47 h1:fvu+bNKPTNtQocssnKbEZ66MqR0iBfAxY3HwlqnmYyE=
|
||||
git.solsynth.dev/hypernet/paperclip v0.0.0-20250310151112-1d866f317f47/go.mod h1:jvxq2qftz2v72x+24+cTFJdQKr9eHQTdk3KVR7cx36s=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20250304125607-1ed9816b12c4 h1:Yuydts3ON/dlhZDUHgFf59v8LOUP8mAQ+nY2C3oKd6o=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20250304125607-1ed9816b12c4/go.mod h1:iGN0Zf21niAsdaowbpX5p2gALqVoJIV5QL8seQQ5LKc=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20250315083747-32e91e26013c h1:XB8EBX34WB2skmjaVFot5IlxKF2qFZ2SueG/Y9SiJ6Y=
|
||||
git.solsynth.dev/hypernet/passport v0.0.0-20250315083747-32e91e26013c/go.mod h1:k7MZQWYBpxlk3g9bx0HTh5C3m+MG/wr0hAiRM/VyAqs=
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20250216145944-5fb769823a88 h1:2HEENe9KUrdaJeNBzx9lsuXQGyzWqCgnLTKQnr8xFr8=
|
||||
@ -29,22 +27,16 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
|
||||
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
|
||||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
|
||||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
|
||||
github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0=
|
||||
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/eko/gocache/lib/v4 v4.1.6 h1:5WWIGISKhE7mfkyF+SJyWwqa4Dp2mkdX8QsZpnENqJI=
|
||||
github.com/eko/gocache/lib/v4 v4.1.6/go.mod h1:HFxC8IiG2WeRotg09xEnPD72sCheJiTSr4Li5Ameg7g=
|
||||
github.com/eko/gocache/store/ristretto/v4 v4.2.2 h1:lXFzoZ5ck6Gy6ON7f5DHSkNt122qN7KoroCVgVwF7oo=
|
||||
github.com/eko/gocache/store/ristretto/v4 v4.2.2/go.mod h1:uIvBVJzqRepr5L0RsbkfQ2iYfbyos2fuji/s4yM+aUM=
|
||||
github.com/eko/gocache/lib/v4 v4.2.0 h1:MNykyi5Xw+5Wu3+PUrvtOCaKSZM1nUSVftbzmeC7Yuw=
|
||||
github.com/eko/gocache/lib/v4 v4.2.0/go.mod h1:7ViVmbU+CzDHzRpmB4SXKyyzyuJ8A3UW3/cszpcqB4M=
|
||||
github.com/eko/gocache/store/redis/v4 v4.2.2 h1:Thw31fzGuH3WzJywsdbMivOmP550D6JS7GDHhvCJPA0=
|
||||
github.com/eko/gocache/store/redis/v4 v4.2.2/go.mod h1:LaTxLKx9TG/YUEybQvPMij++D7PBTIJ4+pzvk0ykz0w=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
@ -254,16 +246,16 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
||||
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
||||
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
||||
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||
github.com/prometheus/common v0.52.3 h1:5f8uj6ZwHSscOGNdIQg6OiZv/ybiK2CO2q2drVZAQSA=
|
||||
github.com/prometheus/common v0.52.3/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
|
||||
github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o=
|
||||
github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.1.0 h1:EewKT7/LNac5SLiEblJeUu8z5eERHrmRLnMQL2d7qX4=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.1.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
|
||||
github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
||||
github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM=
|
||||
github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
@ -297,7 +289,6 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
@ -318,10 +309,6 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.59.0 h1:Qu0qYHfXvPk1mSLNqcFtEk6DpxgA26hy6bmydotDpRI=
|
||||
github.com/valyala/fasthttp v1.59.0/go.mod h1:GTxNb9Bc6r2a9D0TWNSPwDz78UxnTGBViY3xZNEqyYU=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
@ -345,6 +332,8 @@ go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
|
||||
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
|
24
pkg/internal/cache/store.go
vendored
24
pkg/internal/cache/store.go
vendored
@ -1,24 +0,0 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/eko/gocache/lib/v4/store"
|
||||
ristrettoCache "github.com/eko/gocache/store/ristretto/v4"
|
||||
)
|
||||
|
||||
var S store.StoreInterface
|
||||
|
||||
func NewStore() error {
|
||||
ristretto, err := ristretto.NewCache(&ristretto.Config{
|
||||
NumCounters: 1000,
|
||||
MaxCost: 100,
|
||||
BufferItems: 64,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
S = ristrettoCache.NewRistretto(ristretto)
|
||||
|
||||
return nil
|
||||
}
|
@ -2,19 +2,25 @@ package gap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/pusher/pkg/pushkit/pushcon"
|
||||
"github.com/samber/lo"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var Nx *nex.Conn
|
||||
var Px *pushcon.Conn
|
||||
var (
|
||||
Nx *nex.Conn
|
||||
Px *pushcon.Conn
|
||||
Ca *cachekit.CaConn
|
||||
)
|
||||
|
||||
func InitializeToNexus() error {
|
||||
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
|
||||
@ -47,6 +53,10 @@ func InitializeToNexus() error {
|
||||
return fmt.Errorf("error during initialize pushcon: %v", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Ca, err = cachekit.NewCaConn(Nx, 3*time.Second)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during initialize cachekit: %v", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
|
@ -1,17 +1,13 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
localCache "git.solsynth.dev/hypernet/messaging/pkg/internal/cache"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"github.com/eko/gocache/lib/v4/cache"
|
||||
"github.com/eko/gocache/lib/v4/marshaler"
|
||||
"github.com/eko/gocache/lib/v4/store"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
@ -81,16 +77,10 @@ func AddChannelMember(user authm.Account, target models.Channel) error {
|
||||
err := database.C.Save(&member).Error
|
||||
|
||||
if err == nil {
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
ctx := context.Background()
|
||||
|
||||
_ = marshal.Invalidate(
|
||||
ctx,
|
||||
store.WithInvalidateTags([]string{
|
||||
cachekit.DeleteByTags(
|
||||
gap.Ca,
|
||||
fmt.Sprintf("channel#%d", target.ID),
|
||||
fmt.Sprintf("user#%d", user.ID),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@ -101,16 +91,10 @@ func EditChannelMember(membership models.ChannelMember) (models.ChannelMember, e
|
||||
if err := database.C.Save(&membership).Error; err != nil {
|
||||
return membership, err
|
||||
} else {
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
_ = marshal.Invalidate(
|
||||
contx,
|
||||
store.WithInvalidateTags([]string{
|
||||
cachekit.DeleteByTags(
|
||||
gap.Ca,
|
||||
fmt.Sprintf("channel#%d", membership.ChannelID),
|
||||
fmt.Sprintf("user#%d", membership.AccountID),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@ -121,16 +105,10 @@ func RemoveChannelMember(member models.ChannelMember, target models.Channel) err
|
||||
if err := database.C.Delete(&member).Error; err == nil {
|
||||
database.C.Where("sender_id = ?").Delete(&models.Event{})
|
||||
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
ctx := context.Background()
|
||||
|
||||
_ = marshal.Invalidate(
|
||||
ctx,
|
||||
store.WithInvalidateTags([]string{
|
||||
cachekit.DeleteByTags(
|
||||
gap.Ca,
|
||||
fmt.Sprintf("channel#%d", target.ID),
|
||||
fmt.Sprintf("user#%d", target.AccountID),
|
||||
}),
|
||||
fmt.Sprintf("user#%d", member.AccountID),
|
||||
)
|
||||
|
||||
return nil
|
||||
|
@ -1,17 +1,15 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
localCache "git.solsynth.dev/hypernet/messaging/pkg/internal/cache"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"github.com/eko/gocache/lib/v4/cache"
|
||||
"github.com/eko/gocache/lib/v4/marshaler"
|
||||
"github.com/eko/gocache/lib/v4/store"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/viper"
|
||||
@ -19,11 +17,11 @@ import (
|
||||
)
|
||||
|
||||
type channelIdentityCacheEntry struct {
|
||||
Channel models.Channel
|
||||
ChannelMember models.ChannelMember
|
||||
Channel models.Channel `json:"channel"`
|
||||
ChannelMember models.ChannelMember `json:"channel_member"`
|
||||
}
|
||||
|
||||
func GetChannelIdentityCacheKey(channel string, user uint, realm ...uint) string {
|
||||
func KgChannelIdentityCache(channel string, user uint, realm ...uint) string {
|
||||
if len(realm) > 0 {
|
||||
return fmt.Sprintf("channel-identity-%s#%d@%d", channel, user, realm)
|
||||
} else {
|
||||
@ -31,18 +29,16 @@ func GetChannelIdentityCacheKey(channel string, user uint, realm ...uint) string
|
||||
}
|
||||
}
|
||||
|
||||
func CacheChannelIdentityCache(channel models.Channel, member models.ChannelMember, user uint, realm ...uint) {
|
||||
key := GetChannelIdentityCacheKey(channel.Alias, user, realm...)
|
||||
func CacheChannelIdentity(channel models.Channel, member models.ChannelMember, user uint, realm ...uint) {
|
||||
key := KgChannelIdentityCache(channel.Alias, user, realm...)
|
||||
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
_ = marshal.Set(
|
||||
contx,
|
||||
cachekit.Set(
|
||||
gap.Ca,
|
||||
key,
|
||||
channelIdentityCacheEntry{channel, member},
|
||||
store.WithTags([]string{"channel-identity", fmt.Sprintf("channel#%d", channel.ID), fmt.Sprintf("user#%d", user)}),
|
||||
60*time.Minute,
|
||||
fmt.Sprintf("channel#%d", channel.ID),
|
||||
fmt.Sprintf("user#%d", user),
|
||||
)
|
||||
}
|
||||
|
||||
@ -60,37 +56,37 @@ func GetChannelIdentityWithID(id uint, user uint) (models.Channel, models.Channe
|
||||
}
|
||||
|
||||
func GetChannelIdentity(alias string, user uint, realm ...authm.Realm) (models.Channel, models.ChannelMember, error) {
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
var err error
|
||||
var channel models.Channel
|
||||
var member models.ChannelMember
|
||||
|
||||
hitCache := false
|
||||
if len(realm) > 0 {
|
||||
if val, err := marshal.Get(contx, GetChannelIdentityCacheKey(alias, user, realm[0].ID), new(channelIdentityCacheEntry)); err == nil {
|
||||
entry := val.(*channelIdentityCacheEntry)
|
||||
channel = entry.Channel
|
||||
member = entry.ChannelMember
|
||||
if val, err := cachekit.Get[channelIdentityCacheEntry](
|
||||
gap.Ca,
|
||||
KgChannelIdentityCache(alias, user, realm[0].ID),
|
||||
); err == nil {
|
||||
channel = val.Channel
|
||||
member = val.ChannelMember
|
||||
hitCache = true
|
||||
}
|
||||
} else {
|
||||
if val, err := marshal.Get(contx, GetChannelIdentityCacheKey(alias, user), new(channelIdentityCacheEntry)); err == nil {
|
||||
entry := val.(*channelIdentityCacheEntry)
|
||||
channel = entry.Channel
|
||||
member = entry.ChannelMember
|
||||
if val, err := cachekit.Get[channelIdentityCacheEntry](
|
||||
gap.Ca,
|
||||
KgChannelIdentityCache(alias, user),
|
||||
); err == nil {
|
||||
channel = val.Channel
|
||||
member = val.ChannelMember
|
||||
hitCache = true
|
||||
}
|
||||
}
|
||||
if !hitCache {
|
||||
if len(realm) > 0 {
|
||||
channel, member, err = GetAvailableChannelWithAlias(alias, user, realm[0].ID)
|
||||
CacheChannelIdentityCache(channel, member, user, realm[0].ID)
|
||||
CacheChannelIdentity(channel, member, user, realm[0].ID)
|
||||
} else {
|
||||
channel, member, err = GetAvailableChannelWithAlias(alias, user)
|
||||
CacheChannelIdentityCache(channel, member, user)
|
||||
CacheChannelIdentity(channel, member, user)
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,14 +278,7 @@ func EditChannel(channel models.Channel) (models.Channel, error) {
|
||||
err := database.C.Save(&channel).Error
|
||||
|
||||
if err == nil {
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
_ = marshal.Invalidate(
|
||||
contx,
|
||||
store.WithInvalidateTags([]string{fmt.Sprintf("channel#%d", channel.ID)}),
|
||||
)
|
||||
cachekit.DeleteByTags(gap.Ca, fmt.Sprintf("channel#%d", channel.ID))
|
||||
}
|
||||
|
||||
return channel, err
|
||||
@ -302,14 +291,7 @@ func DeleteChannel(channel models.Channel) error {
|
||||
database.C.Where("channel_id = ?", channel.ID).Delete(&models.Event{})
|
||||
database.C.Where("channel_id = ?", channel.ID).Delete(&models.ChannelMember{})
|
||||
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
_ = marshal.Invalidate(
|
||||
contx,
|
||||
store.WithInvalidateTags([]string{fmt.Sprintf("channel#%d", channel.ID)}),
|
||||
)
|
||||
cachekit.DeleteByTags(gap.Ca, fmt.Sprintf("channel#%d", channel.ID))
|
||||
|
||||
return nil
|
||||
} else {
|
||||
|
@ -1,16 +1,14 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
localCache "git.solsynth.dev/hypernet/messaging/pkg/internal/cache"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"github.com/eko/gocache/lib/v4/cache"
|
||||
"github.com/eko/gocache/lib/v4/marshaler"
|
||||
"github.com/eko/gocache/lib/v4/store"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -20,23 +18,21 @@ type statusQueryCacheEntry struct {
|
||||
Data any
|
||||
}
|
||||
|
||||
func GetTypingStatusQueryCacheKey(channelId uint, userId uint) string {
|
||||
return fmt.Sprintf("typing-status-query#%d;%d", channelId, userId)
|
||||
func KgTypingStatusCache(channelId uint, userId uint) string {
|
||||
return fmt.Sprintf("chat-typing-status#%d@%d", userId, channelId)
|
||||
}
|
||||
|
||||
func SetTypingStatus(channelId uint, userId uint) error {
|
||||
var broadcastTarget []uint64
|
||||
var data any
|
||||
|
||||
cacheManager := cache.New[any](localCache.S)
|
||||
marshal := marshaler.New(cacheManager)
|
||||
contx := context.Background()
|
||||
|
||||
hitCache := false
|
||||
if val, err := marshal.Get(contx, GetTypingStatusQueryCacheKey(channelId, userId), new(statusQueryCacheEntry)); err == nil {
|
||||
entry := val.(*statusQueryCacheEntry)
|
||||
broadcastTarget = entry.Target
|
||||
data = entry.Data
|
||||
if val, err := cachekit.Get[statusQueryCacheEntry](
|
||||
gap.Ca,
|
||||
KgTypingStatusCache(channelId, userId),
|
||||
); err == nil {
|
||||
broadcastTarget = val.Target
|
||||
data = val.Data
|
||||
hitCache = true
|
||||
}
|
||||
|
||||
@ -69,11 +65,12 @@ func SetTypingStatus(channelId uint, userId uint) error {
|
||||
}
|
||||
|
||||
// Cache queries
|
||||
_ = marshal.Set(
|
||||
contx,
|
||||
GetTypingStatusQueryCacheKey(channelId, userId),
|
||||
cachekit.Set(
|
||||
gap.Ca,
|
||||
KgTypingStatusCache(channelId, userId),
|
||||
statusQueryCacheEntry{broadcastTarget, data},
|
||||
store.WithTags([]string{"typing-status-query", fmt.Sprintf("channel#%d", channelId), fmt.Sprintf("user#%d", userId)}),
|
||||
60*time.Minute,
|
||||
fmt.Sprintf("channel#%d", channelId),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
@ -8,7 +8,7 @@ import (
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
@ -7,7 +7,7 @@ import (
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
@ -7,7 +7,7 @@ import (
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
@ -5,7 +5,7 @@ import (
|
||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"strings"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/exts"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
@ -1,4 +1,4 @@
|
||||
package http
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http/api"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web/api"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
12
pkg/main.go
12
pkg/main.go
@ -15,10 +15,9 @@ import (
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/http"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/web"
|
||||
|
||||
pkg "git.solsynth.dev/hypernet/messaging/pkg/internal"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/cache"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
@ -57,7 +56,7 @@ func main() {
|
||||
if reader, err := sec.NewInternalTokenReader(viper.GetString("security.internal_public_key")); err != nil {
|
||||
log.Error().Err(err).Msg("An error occurred when reading internal public key for jwt. Authentication related features will be disabled.")
|
||||
} else {
|
||||
http.IReader = reader
|
||||
web.IReader = reader
|
||||
log.Info().Msg("Internal jwt public key loaded.")
|
||||
}
|
||||
|
||||
@ -68,16 +67,11 @@ func main() {
|
||||
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")
|
||||
}
|
||||
|
||||
// Initialize cache
|
||||
if err := cache.NewStore(); err != nil {
|
||||
log.Fatal().Err(err).Msg("An error occurred when initializing cache.")
|
||||
}
|
||||
|
||||
// Connect other services
|
||||
services.SetupLiveKit()
|
||||
|
||||
// Server
|
||||
go http.NewServer().Listen()
|
||||
go web.NewServer().Listen()
|
||||
|
||||
go grpc.NewGrpc().Listen()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user