From 4d4ea3c37f91ec7595365ca47917166c88ca0b02 Mon Sep 17 00:00:00 2001 From: Zak <34372536+ZakShearman@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:20:09 +0000 Subject: [PATCH] feat: add relationship-manager-service --- Makefile | 12 + go.work | 1 + go.work.sum | 59 +-- .../relationship-manager-service/Dockerfile | 33 ++ .../cmd/relationship-manager-service/main.go | 36 ++ services/relationship-manager-service/go.mod | 51 +++ services/relationship-manager-service/go.sum | 249 +++++++++++ .../internal/app/relationship.go | 50 +++ .../internal/clients/creator.go | 27 ++ .../internal/config/global.go | 48 +++ .../internal/kafka/consumer.go | 134 ++++++ .../internal/kafka/writer.go | 123 ++++++ .../internal/repository/model/model.go | 37 ++ .../internal/repository/mongo.go | 304 +++++++++++++ .../internal/repository/mongo_block.go | 86 ++++ .../internal/repository/public.go | 32 ++ .../repository/registrytypes/uuid_types.go | 58 +++ .../internal/service/public.go | 58 +++ .../internal/service/relationship.go | 403 ++++++++++++++++++ .../run/config.yaml | 14 + 20 files changed, 1768 insertions(+), 47 deletions(-) create mode 100644 Makefile create mode 100644 services/relationship-manager-service/Dockerfile create mode 100644 services/relationship-manager-service/cmd/relationship-manager-service/main.go create mode 100644 services/relationship-manager-service/go.mod create mode 100644 services/relationship-manager-service/go.sum create mode 100644 services/relationship-manager-service/internal/app/relationship.go create mode 100644 services/relationship-manager-service/internal/clients/creator.go create mode 100644 services/relationship-manager-service/internal/config/global.go create mode 100644 services/relationship-manager-service/internal/kafka/consumer.go create mode 100644 services/relationship-manager-service/internal/kafka/writer.go create mode 100644 services/relationship-manager-service/internal/repository/model/model.go create mode 100644 services/relationship-manager-service/internal/repository/mongo.go create mode 100644 services/relationship-manager-service/internal/repository/mongo_block.go create mode 100644 services/relationship-manager-service/internal/repository/public.go create mode 100644 services/relationship-manager-service/internal/repository/registrytypes/uuid_types.go create mode 100644 services/relationship-manager-service/internal/service/public.go create mode 100644 services/relationship-manager-service/internal/service/relationship.go create mode 100644 services/relationship-manager-service/run/config.yaml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..faf2bcc --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +lint: + golangci-lint run + +go-tidy: + go work sync + go mod tidy + # Loop through all directories containing a go.mod file and run go mod tidy in each + find . -type f -name "go.mod" -execdir go mod tidy \; + +pre-commit: + go-tidy + lint diff --git a/go.work b/go.work index 0846ec4..87a6993 100644 --- a/go.work +++ b/go.work @@ -7,4 +7,5 @@ use ( ./services/matchmaker ./services/mc-player-service ./services/message-handler + ./services/relationship-manager-service ) diff --git a/go.work.sum b/go.work.sum index 6511b0a..253bc9d 100644 --- a/go.work.sum +++ b/go.work.sum @@ -341,7 +341,6 @@ github.com/circonus-labs/circonusllhist v0.1.3 h1:TJH+oke8D16535+jHExHj4nQvzlZrj github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f h1:WBZRG4aNOuI15bLRrCgN8fCq8E5Xuty6jGbmSNEvSsU= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe h1:QQ3GSy+MqSHxm/d8nCtnAiZdYFd45cYZPs8vOOIYKfk= github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20 h1:N+3sFI5GUjRKBi+i0TxYVST9h4Ie192jJWpHvthBBgg= @@ -376,7 +375,6 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= @@ -385,33 +383,18 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/cel-go v0.17.1 h1:s2151PDGy/eqpCI80/8dl4VL3xTkqI/YubXLXCFw0mw= github.com/google/cel-go v0.17.1/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY= github.com/google/flatbuffers v23.5.26+incompatible h1:M9dgRyhJemaM4Sw8+66GHBu8ioaQmyPLg1b8VwK5WJg= github.com/google/flatbuffers v23.5.26+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9 h1:OF1IPgv+F4NmqmJ98KTjdN97Vs1JxDPB3vbmYzV2dpk= github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY= @@ -423,7 +406,6 @@ github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2 h1:LR89qFljJ48s990kEK github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= @@ -482,7 +464,6 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= @@ -612,27 +593,23 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f h1:UFr9zpz4xgTnIE5yIMtWAMngCdZ9p/+q6lTbgelo80M= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/crypt v0.19.0 h1:WMyLTjHBo64UvNcWqpzY3pbZTYgnemZU8FBZigKc42E= github.com/sagikazarmark/crypt v0.19.0/go.mod h1:c6vimRziqqERhtSe0MhIvzE1w54FrCHtrXb5NH/ja78= -github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/segmentio/kafka-go v0.4.39/go.mod h1:T0MLgygYvmqmBvC+s8aCcbVNfJN4znVne5j0Pzowp/Q= -github.com/segmentio/kafka-go v0.4.46/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= -github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= @@ -698,6 +675,7 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= @@ -707,7 +685,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= @@ -719,13 +696,14 @@ golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -735,8 +713,6 @@ golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -751,20 +727,20 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= @@ -779,22 +755,22 @@ google.golang.org/api v0.171.0 h1:w174hnBPqut76FzW5Qaupt7zY8Kql6fiVjgys4f58sU= google.golang.org/api v0.171.0/go.mod h1:Hnq5AHm4OTMt2BUVjael2CWZFD6vksJdWCWiUAmjC9o= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:+Rvu7ElI+aLzyDQhpHMFMMltsD6m7nqpuWDd2CwJw3k= google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro= google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:mqHbVIp48Muh7Ywss/AD6I5kNVKZMmAa/QEW58Gxp2s= +google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA= google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014/go.mod h1:rbHMSEDyoYX62nRVLOCc4Qt1HbsdytAYoVwgjiOhF3I= google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= google.golang.org/genproto/googleapis/api v0.0.0-20240304161311-37d4d3c04a78/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y= google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y= -google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= google.golang.org/genproto/googleapis/bytestream v0.0.0-20240314234333-6e1732d8331c h1:4z0DVWmDWWZ4OeQHLrb6lLBE3uCgSLs9DDA5Zb36DFg= google.golang.org/genproto/googleapis/bytestream v0.0.0-20240314234333-6e1732d8331c/go.mod h1:IN9OQUXZ0xT+26MDwZL8fJcYw+y99b0eYPA2U15Jt8o= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:KSqppvjFjtoCI+KGd4PELB0qLNxdJHRGqRI09mB6pQA= google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA= google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014/go.mod h1:SaPjaZGWb0lPqs6Ittu0spdfrOArqji4ZdeP5IC/9N4= @@ -803,10 +779,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240304161311-37d4d3c04a78/go. google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2/go.mod h1:UCOku4NytXMJuLQE5VuqA5lX3PcHCBo8pxNyvkf4xBs= google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= @@ -815,18 +789,9 @@ google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJai google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdrxJNoY= gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw= diff --git a/services/relationship-manager-service/Dockerfile b/services/relationship-manager-service/Dockerfile new file mode 100644 index 0000000..f21be28 --- /dev/null +++ b/services/relationship-manager-service/Dockerfile @@ -0,0 +1,33 @@ +FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build + +ARG SERVICE_NAME=relationship-manager-service + +WORKDIR /build + +# Copy sources +COPY . . + +WORKDIR /build/services/$SERVICE_NAME + +RUN go mod download + +WORKDIR /build + +ARG TARGETOS +ARG TARGETARCH + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + CGO_ENABLED=0 \ + GOOS=$TARGETOS \ + GOARCH=$TARGETARCH \ + go build -ldflags="-s -w" -o $SERVICE_NAME ./services/$SERVICE_NAME/cmd/$SERVICE_NAME + +FROM alpine + +ARG SERVICE_NAME=relationship-manager-service + +WORKDIR /app + +COPY --from=build /build/$SERVICE_NAME /build/services/$SERVICE_NAME/run ./ +CMD ["./relationship-manager-service"] \ No newline at end of file diff --git a/services/relationship-manager-service/cmd/relationship-manager-service/main.go b/services/relationship-manager-service/cmd/relationship-manager-service/main.go new file mode 100644 index 0000000..8008b4f --- /dev/null +++ b/services/relationship-manager-service/cmd/relationship-manager-service/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/emortalmc/mono-services/services/relationship-manager-service/internal/app" + "github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" + "go.uber.org/zap" + "log" +) + +func main() { + cfg, err := config.LoadGlobalConfig() + if err != nil { + log.Fatalf("failed to load config: %v", err) + } + + logger, err := createLogger(cfg) + if err != nil { + log.Fatal(err) + } + + app.Run(cfg, logger) +} + +func createLogger(cfg *config.Config) (*zap.SugaredLogger, error) { + var logger *zap.Logger + var err error + if cfg.Development { + logger, err = zap.NewDevelopment() + } else { + logger, err = zap.NewProduction() + } + if err != nil { + return nil, err + } + return logger.Sugar(), nil +} diff --git a/services/relationship-manager-service/go.mod b/services/relationship-manager-service/go.mod new file mode 100644 index 0000000..42c9c99 --- /dev/null +++ b/services/relationship-manager-service/go.mod @@ -0,0 +1,51 @@ +module github.com/emortalmc/mono-services/services/relationship-manager-service + +go 1.23 + +require ( + github.com/emortalmc/proto-specs/gen/go v0.0.0-20240927103241-2584fd28e0f9 + github.com/google/uuid v1.6.0 + github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 + github.com/segmentio/kafka-go v0.4.47 + github.com/spf13/viper v1.19.0 + go.mongodb.org/mongo-driver v1.17.1 + go.uber.org/zap v1.27.0 + google.golang.org/grpc v1.67.1 + google.golang.org/protobuf v1.35.1 +) + +require ( + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/klauspost/compress v1.17.2 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pierrec/lz4/v4 v4.1.18 // indirect + github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect + go.uber.org/multierr v1.10.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/services/relationship-manager-service/go.sum b/services/relationship-manager-service/go.sum new file mode 100644 index 0000000..7271912 --- /dev/null +++ b/services/relationship-manager-service/go.sum @@ -0,0 +1,249 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/emortalmc/proto-specs/gen/go v0.0.0-20240927103241-2584fd28e0f9 h1:6xOnWrTvG2oJR1J6+B+tdZV5GdlbIgdQixdCCyfj4nA= +github.com/emortalmc/proto-specs/gen/go v0.0.0-20240927103241-2584fd28e0f9/go.mod h1:se+tHcK9FWxeadkxLF5uj+SPauEye0X+Iq6cGczXGJY= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +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/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= +github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= +github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUanQQB0= +github.com/segmentio/kafka-go v0.4.47/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +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.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= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +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 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= +go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +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/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/services/relationship-manager-service/internal/app/relationship.go b/services/relationship-manager-service/internal/app/relationship.go new file mode 100644 index 0000000..296385f --- /dev/null +++ b/services/relationship-manager-service/internal/app/relationship.go @@ -0,0 +1,50 @@ +package app + +import ( + "context" + "go.uber.org/zap" + "os/signal" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/clients" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/kafka" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/service" +"sync" +"syscall" +) + +func Run(cfg *config.Config, logger *zap.SugaredLogger) { + ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer cancel() + wg := &sync.WaitGroup{} + + // Mongo and Kafka get a delayed context to make sure they are shut down after requests are finished. + delayedWg := &sync.WaitGroup{} + delayedCtx, delayedCancel := context.WithCancel(ctx) + + repo, err := repository.NewMongoRepository(delayedCtx, logger, delayedWg, cfg.MongoDB) + if err != nil { + logger.Fatalw("failed to create repository", "error", err) + } + + notif := kafka.NewKafkaNotifier(delayedCtx, wg, cfg.Kafka, logger) + if err != nil { + logger.Fatalw("failed to create notifier", "error", err) + } + + service.RunServices(ctx, logger, wg, cfg, repo, notif) + + playerTracker, err := clients.NewPlayerTrackerClient(cfg.PlayerTrackerService) + if err != nil { + logger.Fatalw("failed to create player tracker client", "error", err) + } + + kafka.NewConsumer(ctx, wg, cfg.Kafka, logger, repo, notif, playerTracker) + + wg.Wait() + logger.Info("stopped services") + + logger.Info("shutting down repository and kafka") + delayedCancel() + delayedWg.Wait() +} diff --git a/services/relationship-manager-service/internal/clients/creator.go b/services/relationship-manager-service/internal/clients/creator.go new file mode 100644 index 0000000..95bbf99 --- /dev/null +++ b/services/relationship-manager-service/internal/clients/creator.go @@ -0,0 +1,27 @@ +package clients + +import ( + "fmt" + "github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" + "github.com/emortalmc/proto-specs/gen/go/grpc/mcplayer" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +func NewPlayerTrackerClient(cfg *config.PlayerTrackerServiceConfig) (mcplayer.PlayerTrackerClient, error) { + lis, err := createConnection(cfg.Host, cfg.Port) + if err != nil { + return nil, err + } + + return mcplayer.NewPlayerTrackerClient(lis), nil +} + +func createConnection(addr string, port uint16) (*grpc.ClientConn, error) { + conn, err := grpc.Dial(fmt.Sprintf("%s:%d", addr, port), grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return nil, err + } + + return conn, nil +} diff --git a/services/relationship-manager-service/internal/config/global.go b/services/relationship-manager-service/internal/config/global.go new file mode 100644 index 0000000..86b693a --- /dev/null +++ b/services/relationship-manager-service/internal/config/global.go @@ -0,0 +1,48 @@ +package config + +import ( + "github.com/spf13/viper" + "strings" +) + +type Config struct { + Kafka *KafkaConfig + MongoDB *MongoDBConfig + + PlayerTrackerService *PlayerTrackerServiceConfig + + Development bool + Port uint16 +} + +type KafkaConfig struct { + Host string + Port int +} + +type MongoDBConfig struct { + URI string +} + +type PlayerTrackerServiceConfig struct { + Host string + Port uint16 +} + +func LoadGlobalConfig() (cfg *Config, err error) { + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() + + viper.SetConfigName("config") + viper.AddConfigPath(".") + + if err = viper.ReadInConfig(); err != nil { + return + } + + if err = viper.Unmarshal(&cfg); err != nil { + return + } + + return +} diff --git a/services/relationship-manager-service/internal/kafka/consumer.go b/services/relationship-manager-service/internal/kafka/consumer.go new file mode 100644 index 0000000..4a5a04c --- /dev/null +++ b/services/relationship-manager-service/internal/kafka/consumer.go @@ -0,0 +1,134 @@ +package kafka + +import ( + "context" + "fmt" + "github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" + "github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository" + "github.com/emortalmc/proto-specs/gen/go/grpc/mcplayer" + "github.com/emortalmc/proto-specs/gen/go/message/common" + "github.com/emortalmc/proto-specs/gen/go/nongenerated/kafkautils" + "github.com/google/uuid" + "github.com/segmentio/kafka-go" + "go.uber.org/zap" + "google.golang.org/protobuf/proto" + "sync" + "time" +) + +const connectionsTopic = "mc-connections" + +type consumer struct { + logger *zap.SugaredLogger + + repo repository.Repository + notif Notifier + playerTracker mcplayer.PlayerTrackerClient + + reader *kafka.Reader +} + +func NewConsumer(ctx context.Context, wg *sync.WaitGroup, cfg *config.KafkaConfig, logger *zap.SugaredLogger, repo repository.Repository, + notif Notifier, playerTracker mcplayer.PlayerTrackerClient) { + + reader := kafka.NewReader(kafka.ReaderConfig{ + Brokers: []string{fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)}, + GroupID: "relationship-manager", + GroupTopics: []string{connectionsTopic}, + + Logger: kafka.LoggerFunc(func(format string, args ...interface{}) { + logger.Infow(fmt.Sprintf(format, args...)) + }), + ErrorLogger: kafka.LoggerFunc(func(format string, args ...interface{}) { + logger.Errorw(fmt.Sprintf(format, args...)) + }), + + MaxWait: 5 * time.Second, + }) + + c := &consumer{ + logger: logger, + + repo: repo, + notif: notif, + playerTracker: playerTracker, + + reader: reader, + } + + handler := kafkautils.NewConsumerHandler(logger, reader) + handler.RegisterHandler(&common.PlayerConnectMessage{}, c.handlePlayerConnectMessage) + handler.RegisterHandler(&common.PlayerDisconnectMessage{}, c.handlePlayerDisconnectMessage) + + logger.Infow("starting listening for kafka messages", "topics", reader.Config().GroupTopics) + + wg.Add(1) + go func() { + defer wg.Done() + handler.Run(ctx) // Run is blocking until the context is cancelled + if err := reader.Close(); err != nil { + logger.Errorw("error closing kafka reader", "error", err) + } + }() +} + +func (c *consumer) handlePlayerConnectMessage(ctx context.Context, _ *kafka.Message, uncast proto.Message) { + msg := uncast.(*common.PlayerConnectMessage) + + pId, err := uuid.Parse(msg.PlayerId) + if err != nil { + c.logger.Errorw("failed to parse player id", "error", err) + return + } + + c.handleConnectionMessage(ctx, pId, msg.PlayerUsername, true) +} + +func (c *consumer) handlePlayerDisconnectMessage(ctx context.Context, _ *kafka.Message, uncast proto.Message) { + msg := uncast.(*common.PlayerDisconnectMessage) + + pId, err := uuid.Parse(msg.PlayerId) + if err != nil { + c.logger.Errorw("failed to parse player id", "error", err) + return + } + + c.handleConnectionMessage(ctx, pId, msg.PlayerUsername, false) +} + +func (c *consumer) handleConnectionMessage(ctx context.Context, pId uuid.UUID, username string, joined bool) { + conns, err := c.repo.GetFriendConnections(ctx, pId) + if err != nil { + c.logger.Errorw("failed to get friend connections", "error", err) + return + } + + otherPlayerIds := make([]string, 0, len(conns)) + for _, conn := range conns { + if conn.PlayerOneId != pId { + otherPlayerIds = append(otherPlayerIds, conn.PlayerOneId.String()) + } else { + otherPlayerIds = append(otherPlayerIds, conn.PlayerTwoId.String()) + } + } + + resp, err := c.playerTracker.GetPlayerServers(ctx, &mcplayer.GetPlayerServersRequest{ + PlayerIds: otherPlayerIds, + }) + if err != nil { + c.logger.Errorw("failed to get player servers", "error", err) + return + } + + playerServers := resp.PlayerServers + + notifiablePlayerIds := make([]string, 0) + for playerId := range playerServers { + notifiablePlayerIds = append(notifiablePlayerIds, playerId) + } + + if err := c.notif.FriendConnectStatus(ctx, pId, username, joined, notifiablePlayerIds); err != nil { + c.logger.Errorw("failed to send friend connect status", "error", err) + return + } +} diff --git a/services/relationship-manager-service/internal/kafka/writer.go b/services/relationship-manager-service/internal/kafka/writer.go new file mode 100644 index 0000000..da370ff --- /dev/null +++ b/services/relationship-manager-service/internal/kafka/writer.go @@ -0,0 +1,123 @@ +package kafka + +import ( + "context" + "fmt" + pbmsg "github.com/emortalmc/proto-specs/gen/go/message/relationship" + "github.com/emortalmc/proto-specs/gen/go/model/relationship" + "github.com/google/uuid" + "github.com/segmentio/kafka-go" + "go.uber.org/zap" + "google.golang.org/protobuf/proto" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" +"sync" +"time" +) + +const writeTopic = "relationship-manager" + +// Notifier is an interface for sending Kafka messages into the relationship-manager topic. +// - The context used should be independent of a request as kafka messages are sent lazily. Using a request context +// will result in the context being cancelled before the message is sent. +type Notifier interface { + FriendRequest(ctx context.Context, request *relationship.FriendRequest) error + FriendAdded(ctx context.Context, senderId uuid.UUID, targetId uuid.UUID, senderUsername string) error + FriendRemoved(ctx context.Context, senderId uuid.UUID, targetId uuid.UUID) error + + FriendConnectStatus(ctx context.Context, playerId uuid.UUID, playerUsername string, joined bool, notifyPlayers []string) error +} + +type kafkaNotifier struct { + w *kafka.Writer +} + +func NewKafkaNotifier(ctx context.Context, wg *sync.WaitGroup, cfg *config.KafkaConfig, logger *zap.SugaredLogger) Notifier { + w := &kafka.Writer{ + Addr: kafka.TCP(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)), + Topic: writeTopic, + Balancer: &kafka.LeastBytes{}, + Async: true, + BatchTimeout: 100 * time.Millisecond, + ErrorLogger: kafka.LoggerFunc(logger.Errorw), + } + + wg.Add(1) + go func() { + defer wg.Done() + <-ctx.Done() + if err := w.Close(); err != nil { + logger.Errorw("failed to close kafka writer", "err", err) + return + } + }() + + return &kafkaNotifier{w: w} +} + +func (k *kafkaNotifier) FriendRequest(ctx context.Context, fReq *relationship.FriendRequest) error { + msg := &pbmsg.FriendRequestReceivedMessage{ + Request: fReq, + } + + if err := k.writeMessage(ctx, msg); err != nil { + return fmt.Errorf("failed to write message: %s", err) + } + + return nil +} + +func (k *kafkaNotifier) FriendAdded(ctx context.Context, senderId uuid.UUID, targetId uuid.UUID, senderUsername string) error { + msg := &pbmsg.FriendAddedMessage{ + SenderId: senderId.String(), + SenderUsername: senderUsername, + RecipientId: targetId.String(), + } + + if err := k.writeMessage(ctx, msg); err != nil { + return fmt.Errorf("failed to write message: %s", err) + } + + return nil +} + +func (k *kafkaNotifier) FriendRemoved(ctx context.Context, senderId uuid.UUID, targetId uuid.UUID) error { + msg := &pbmsg.FriendRemovedMessage{ + SenderId: senderId.String(), + RecipientId: targetId.String(), + } + + if err := k.writeMessage(ctx, msg); err != nil { + return fmt.Errorf("failed to write message: %s", err) + } + + return nil +} + +func (k *kafkaNotifier) FriendConnectStatus(ctx context.Context, playerId uuid.UUID, playerUsername string, joined bool, + notifyPlayers []string) error { + + msg := &pbmsg.FriendConnectionMessage{ + MessageTargetIds: notifyPlayers, + PlayerId: playerId.String(), + Username: playerUsername, + Joined: joined, + } + + if err := k.writeMessage(ctx, msg); err != nil { + return fmt.Errorf("failed to write message: %s", err) + } + + return nil +} + +func (k *kafkaNotifier) writeMessage(ctx context.Context, msg proto.Message) error { + bytes, err := proto.Marshal(msg) + if err != nil { + return fmt.Errorf("failed to marshal proto to bytes: %s", err) + } + + return k.w.WriteMessages(ctx, kafka.Message{ + Headers: []kafka.Header{{Key: "X-Proto-Type", Value: []byte(msg.ProtoReflect().Descriptor().FullName())}}, + Value: bytes, + }) +} diff --git a/services/relationship-manager-service/internal/repository/model/model.go b/services/relationship-manager-service/internal/repository/model/model.go new file mode 100644 index 0000000..be5b086 --- /dev/null +++ b/services/relationship-manager-service/internal/repository/model/model.go @@ -0,0 +1,37 @@ +package model + +import ( + pbmodel "github.com/emortalmc/proto-specs/gen/go/model/relationship" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +type FriendConnection struct { + Id primitive.ObjectID `bson:"_id"` + PlayerOneId uuid.UUID `bson:"playerOneId"` + PlayerTwoId uuid.UUID `bson:"playerTwoId"` +} + +// PendingFriendConnection equivalent to a friend request +type PendingFriendConnection struct { + Id primitive.ObjectID `bson:"_id"` + RequesterId uuid.UUID `bson:"requesterId"` + TargetId uuid.UUID `bson:"targetId"` +} + +type PlayerBlock struct { + Id primitive.ObjectID `bson:"_id"` + BlockerId uuid.UUID `bson:"blockerId"` + BlockedId uuid.UUID `bson:"blockedId"` +} + +func (b *PlayerBlock) ContainsPlayer(playerId uuid.UUID) bool { + return b.BlockerId == playerId || b.BlockedId == playerId +} + +func (b *PlayerBlock) ToProto() *pbmodel.PlayerBlock { + return &pbmodel.PlayerBlock{ + BlockerId: b.BlockerId.String(), + BlockedId: b.BlockedId.String(), + } +} diff --git a/services/relationship-manager-service/internal/repository/mongo.go b/services/relationship-manager-service/internal/repository/mongo.go new file mode 100644 index 0000000..8949730 --- /dev/null +++ b/services/relationship-manager-service/internal/repository/mongo.go @@ -0,0 +1,304 @@ +package repository + +import ( + "context" + "errors" + "fmt" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/bsoncodec" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.uber.org/zap" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository/model" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository/registrytypes" +"sync" +"time" +) +type mongoRepository struct { + logger *zap.SugaredLogger + + database *mongo.Database + + friendColl *mongo.Collection + pendingFriendColl *mongo.Collection + blockColl *mongo.Collection +} + +var ( + NotFriendsError = errors.New("players are not friends") + NoFriendRequestError = errors.New("no friend request found") +) + +func NewMongoRepository(ctx context.Context, logger *zap.SugaredLogger, wg *sync.WaitGroup, cfg *config.MongoDBConfig) (Repository, error) { + client, err := mongo.Connect(ctx, options.Client().ApplyURI(cfg.URI).SetRegistry(createCodecRegistry())) + if err != nil { + return nil, err + } + + database := client.Database("relationship-manager") + + repo := &mongoRepository{ + logger: logger, + + database: database, + + friendColl: database.Collection("friend"), + pendingFriendColl: database.Collection("pendingFriend"), + blockColl: database.Collection("block"), + } + + repo.createIndexes(ctx) + + wg.Add(1) + go func() { + defer wg.Done() + <-ctx.Done() + if err := client.Disconnect(ctx); err != nil { + logger.Errorw("failed to disconnect from mongo", err) + } + }() + + return repo, nil +} + +var ( + friendIndexes = []mongo.IndexModel{ + { // Combined friend index + Keys: bson.D{{Key: "playerOneId", Value: 1}, {Key: "playerTwoId", Value: 1}}, + Options: options.Index().SetName("playerOneId_playerTwoId").SetUnique(true), + }, + // Singular friend indexes + { + Keys: bson.M{"playerOneId": 1}, + Options: options.Index().SetName("playerOneId"), + }, + { + Keys: bson.M{"playerTwoId": 1}, + Options: options.Index().SetName("playerTwoId"), + }, + } + + pendingFriendIndexes = []mongo.IndexModel{ + { // Combined pending friend index + Keys: bson.D{{Key: "requesterId", Value: 1}, {Key: "targetId", Value: 1}}, + Options: options.Index().SetName("requesterId_targetId").SetUnique(true), + }, + // Singular pending friend indexes + { + Keys: bson.M{"requesterId": 1}, + Options: options.Index().SetName("requesterId"), + }, + { + Keys: bson.M{"targetId": 1}, + Options: options.Index().SetName("targetId"), + }, + } + + blockIndexes = []mongo.IndexModel{ + { // Combined block index + Keys: bson.D{{Key: "blockerId", Value: 1}, {Key: "blockedId", Value: 1}}, + Options: options.Index().SetName("blockerId_blockedId").SetUnique(true), + }, + // Singular block indexes + { + Keys: bson.M{"blockerId": 1}, + Options: options.Index().SetName("blockerId"), + }, + { + Keys: bson.M{"blockedId": 1}, + Options: options.Index().SetName("blockedId"), + }, + } +) + +func (m *mongoRepository) createIndexes(ctx context.Context) { + collIndexes := map[*mongo.Collection][]mongo.IndexModel{ + m.friendColl: friendIndexes, + m.pendingFriendColl: pendingFriendIndexes, + m.blockColl: blockIndexes, + } + + wg := sync.WaitGroup{} + wg.Add(len(collIndexes)) + + for coll, indexes := range collIndexes { + go func(coll *mongo.Collection, indexes []mongo.IndexModel) { + defer wg.Done() + _, err := m.createCollIndexes(ctx, coll, indexes) + if err != nil { + panic(fmt.Sprintf("failed to create indexes for collection %s: %s", coll.Name(), err)) + } + }(coll, indexes) + } + + wg.Wait() +} + +func (m *mongoRepository) createCollIndexes(ctx context.Context, coll *mongo.Collection, indexes []mongo.IndexModel) (int, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := coll.Indexes().CreateMany(ctx, indexes) + if err != nil { + return 0, err + } + + return len(result), nil +} + +func (m *mongoRepository) CreateFriendConnection(ctx context.Context, conn *model.FriendConnection) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + _, err := m.friendColl.InsertOne(ctx, conn) + return err +} + +func (m *mongoRepository) GetFriendConnections(ctx context.Context, playerId uuid.UUID) ([]*model.FriendConnection, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + cursor, err := m.friendColl.Find(ctx, bson.M{"$or": []interface{}{ + bson.M{"playerOneId": playerId}, + bson.M{"playerTwoId": playerId}, + }}) + if err != nil { + return nil, err + } + + var mongoResult []*model.FriendConnection + err = cursor.All(ctx, &mongoResult) + + return mongoResult, err +} + +func (m *mongoRepository) DeleteFriendConnection(ctx context.Context, playerId uuid.UUID, friendId uuid.UUID) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.friendColl.DeleteOne(ctx, bson.M{"$or": []interface{}{ + bson.M{"playerOneId": playerId, "playerTwoId": friendId}, + bson.M{"playerOneId": friendId, "playerTwoId": playerId}, + }}) + + if err != nil { + return err + } + if result.DeletedCount == 0 { + return NotFriendsError + } + return nil +} + +func (m *mongoRepository) AreFriends(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) (bool, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.friendColl.CountDocuments(ctx, bson.M{"$or": []bson.M{ + {"playerOneId": playerOneId, "playerTwoId": playerTwoId}, + {"playerOneId": playerTwoId, "playerTwoId": playerOneId}, + }}) + if err != nil { + return false, err + } + return result > 0, nil +} + +func (m *mongoRepository) CreatePendingFriendConnection(ctx context.Context, conn *model.PendingFriendConnection) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + _, err := m.pendingFriendColl.InsertOne(ctx, conn) + // todo NOTE: already exists is mongo.IsDuplicateKeyError(err) + return err +} + +func (m *mongoRepository) DoesPendingFriendConnectionExist(ctx context.Context, requesterId uuid.UUID, targetId uuid.UUID) (bool, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.pendingFriendColl.CountDocuments(ctx, bson.M{"requesterId": requesterId, "targetId": targetId}) + if err != nil { + return false, err + } + return result > 0, nil +} + +func (m *mongoRepository) GetPendingFriendConnections(ctx context.Context, playerId uuid.UUID, opts DirectionOpts) ([]*model.PendingFriendConnection, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + var orFilters = make([]bson.M, 0) + if opts.Incoming { + orFilters = append(orFilters, bson.M{"targetId": playerId}) + } + if opts.Outgoing { + orFilters = append(orFilters, bson.M{"requesterId": playerId}) + } + + if len(orFilters) == 0 { + m.logger.Warnw("no direction options provided", "playerId", playerId) + return nil, errors.New("no direction options provided") + } + + cursor, err := m.pendingFriendColl.Find(ctx, bson.M{"$or": orFilters}, options.Find().SetSort(bson.M{"_id": -1})) + if err != nil { + return nil, err + } + + var mongoResult []*model.PendingFriendConnection + err = cursor.All(ctx, &mongoResult) + return mongoResult, err +} + +func (m *mongoRepository) DeletePendingFriendConnection(ctx context.Context, playerId uuid.UUID, friendId uuid.UUID) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.pendingFriendColl.DeleteOne(ctx, bson.M{"$or": []bson.M{ + {"requesterId": playerId, "targetId": friendId}, + {"requesterId": friendId, "targetId": playerId}, + }}) + if err != nil { + return err + } + if result.DeletedCount == 0 { + return NoFriendRequestError + } + return nil +} + +func (m *mongoRepository) DeletePendingFriendConnections(ctx context.Context, playerId uuid.UUID, opts *DirectionOpts) (int64, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + var orFilters = make([]bson.M, 0) + if opts.Incoming { + orFilters = append(orFilters, bson.M{"targetId": playerId}) + } + if opts.Outgoing { + orFilters = append(orFilters, bson.M{"requesterId": playerId}) + } + + if len(orFilters) == 0 { + m.logger.Warnw("no direction options provided", "playerId", playerId) + return 0, nil + } + + result, err := m.pendingFriendColl.DeleteMany(ctx, bson.M{"$or": orFilters}) + if err != nil { + return 0, err + } + return result.DeletedCount, nil +} + +func createCodecRegistry() *bsoncodec.Registry { + r := bson.NewRegistry() + + r.RegisterTypeEncoder(registrytypes.UUIDType, bsoncodec.ValueEncoderFunc(registrytypes.UuidEncodeValue)) + r.RegisterTypeDecoder(registrytypes.UUIDType, bsoncodec.ValueDecoderFunc(registrytypes.UuidDecodeValue)) + + return r +} diff --git a/services/relationship-manager-service/internal/repository/mongo_block.go b/services/relationship-manager-service/internal/repository/mongo_block.go new file mode 100644 index 0000000..25e211b --- /dev/null +++ b/services/relationship-manager-service/internal/repository/mongo_block.go @@ -0,0 +1,86 @@ +package repository + +import ( + "context" + "errors" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository/model" +"time" +) + +var ( + AlreadyBlockedError = errors.New("player already blocked") +) + +func (m *mongoRepository) CreatePlayerBlock(ctx context.Context, block *model.PlayerBlock) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + _, err := m.blockColl.InsertOne(ctx, block) + + if mongo.IsDuplicateKeyError(err) { + return AlreadyBlockedError + } + + return err +} + +func (m *mongoRepository) DeletePlayerBlock(ctx context.Context, blockerId uuid.UUID, blockedId uuid.UUID) error { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.blockColl.DeleteOne(ctx, bson.M{"blockerId": blockerId, "blockedId": blockedId}) + if err != nil { + return err + } + if result.DeletedCount == 0 { + return mongo.ErrNoDocuments + } + return nil +} + +func (m *mongoRepository) IsPlayerBlocked(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) (bool, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + result, err := m.blockColl.CountDocuments(ctx, bson.M{"$or": []bson.M{ + {"blockerId": playerOneId, "blockedId": playerTwoId}, + {"blockerId": playerTwoId, "blockedId": playerOneId}, + }}) + if err != nil { + return false, err + } + return result > 0, nil +} + +func (m *mongoRepository) GetMutualBlocks(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) ([]*model.PlayerBlock, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + cursor, err := m.blockColl.Find(ctx, bson.M{"$or": []bson.M{ + {"blockerId": playerOneId, "blockedId": playerTwoId}, + {"blockerId": playerTwoId, "blockedId": playerOneId}, + }}) + if err != nil { + return nil, err + } + + result := make([]*model.PlayerBlock, 0) + err = cursor.All(ctx, &result) + return result, err +} + +func (m *mongoRepository) GetPlayerBlocks(ctx context.Context, playerId uuid.UUID) ([]*model.PlayerBlock, error) { + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + cursor, err := m.blockColl.Find(ctx, bson.M{"blockerId": playerId}) + if err != nil { + return nil, err + } + result := make([]*model.PlayerBlock, 0) + err = cursor.All(ctx, &result) + return result, err +} diff --git a/services/relationship-manager-service/internal/repository/public.go b/services/relationship-manager-service/internal/repository/public.go new file mode 100644 index 0000000..5621466 --- /dev/null +++ b/services/relationship-manager-service/internal/repository/public.go @@ -0,0 +1,32 @@ +package repository + +import ( + "context" + "github.com/google/uuid" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository/model" +) +type Repository interface { + CreateFriendConnection(ctx context.Context, connection *model.FriendConnection) error + GetFriendConnections(ctx context.Context, playerId uuid.UUID) ([]*model.FriendConnection, error) + DeleteFriendConnection(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) error + AreFriends(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) (bool, error) + + CreatePendingFriendConnection(ctx context.Context, connection *model.PendingFriendConnection) error + DoesPendingFriendConnectionExist(ctx context.Context, requesterId uuid.UUID, targetId uuid.UUID) (bool, error) + GetPendingFriendConnections(ctx context.Context, playerId uuid.UUID, options DirectionOpts) ([]*model.PendingFriendConnection, error) + + DeletePendingFriendConnection(ctx context.Context, requesterId uuid.UUID, targetId uuid.UUID) error + DeletePendingFriendConnections(ctx context.Context, playerId uuid.UUID, opts *DirectionOpts) (int64, error) + + CreatePlayerBlock(ctx context.Context, block *model.PlayerBlock) error + DeletePlayerBlock(ctx context.Context, blockerId uuid.UUID, blockedId uuid.UUID) error + // IsPlayerBlocked returns if either player has blocked the other + IsPlayerBlocked(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) (bool, error) + GetMutualBlocks(ctx context.Context, playerOneId uuid.UUID, playerTwoId uuid.UUID) ([]*model.PlayerBlock, error) + GetPlayerBlocks(ctx context.Context, blockerId uuid.UUID) ([]*model.PlayerBlock, error) +} + +type DirectionOpts struct { + Incoming bool + Outgoing bool +} diff --git a/services/relationship-manager-service/internal/repository/registrytypes/uuid_types.go b/services/relationship-manager-service/internal/repository/registrytypes/uuid_types.go new file mode 100644 index 0000000..f0c4f04 --- /dev/null +++ b/services/relationship-manager-service/internal/repository/registrytypes/uuid_types.go @@ -0,0 +1,58 @@ +// Package registry +// taken from https://gist.github.com/SupaHam/3afe982dc75039356723600ccc91ff77 +package registrytypes + +import ( + "fmt" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/bsoncodec" + "go.mongodb.org/mongo-driver/bson/bsonrw" + "reflect" +) + +var ( + UUIDType = reflect.TypeOf(uuid.UUID{}) + uuidSubtype = byte(0x04) +) + +func UuidEncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error { + if !val.IsValid() || val.Type() != UUIDType { + return bsoncodec.ValueEncoderError{Name: "uuidEncodeValue", Types: []reflect.Type{UUIDType}, Received: val} + } + b := val.Interface().(uuid.UUID) + return vw.WriteBinaryWithSubtype(b[:], uuidSubtype) +} + +func UuidDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { + if !val.CanSet() || val.Type() != UUIDType { + return bsoncodec.ValueDecoderError{Name: "uuidDecodeValue", Types: []reflect.Type{UUIDType}, Received: val} + } + + var data []byte + var subtype byte + var err error + switch vrType := vr.Type(); vrType { + case bson.TypeBinary: + data, subtype, err = vr.ReadBinary() + if subtype != uuidSubtype { + return fmt.Errorf("unsupported binary subtype %v for UUID", subtype) + } + case bson.TypeNull: + err = vr.ReadNull() + case bson.TypeUndefined: + err = vr.ReadUndefined() + default: + return fmt.Errorf("cannot decode %v into a UUID", vrType) + } + + if err != nil { + return err + } + uuid2, err := uuid.FromBytes(data) + if err != nil { + return err + } + val.Set(reflect.ValueOf(uuid2)) + return nil +} diff --git a/services/relationship-manager-service/internal/service/public.go b/services/relationship-manager-service/internal/service/public.go new file mode 100644 index 0000000..cb52b93 --- /dev/null +++ b/services/relationship-manager-service/internal/service/public.go @@ -0,0 +1,58 @@ +package service + +import ( + "context" + "fmt" + "github.com/emortalmc/proto-specs/gen/go/grpc/relationship" + grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/reflection" + "net" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/config" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/kafka" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository" +"sync" +) + +func RunServices(ctx context.Context, logger *zap.SugaredLogger, wg *sync.WaitGroup, cfg *config.Config, + repo repository.Repository, notif kafka.Notifier) { + + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.Port)) + if err != nil { + logger.Fatalw("failed to listen", "error", err) + } + + s := grpc.NewServer(grpc.ChainUnaryInterceptor( + grpczap.UnaryServerInterceptor(logger.Desugar(), grpczap.WithLevels(func(code codes.Code) zapcore.Level { + if code != codes.Internal && code != codes.Unavailable && code != codes.Unknown { + return zapcore.DebugLevel + } else { + return zapcore.ErrorLevel + } + })), + )) + + if cfg.Development { + reflection.Register(s) + } + + relationship.RegisterRelationshipServer(s, newPermissionService(ctx, repo, logger, notif)) + logger.Infow("listening on port", "port", cfg.Port) + + go func() { + if err := s.Serve(lis); err != nil { + logger.Fatalw("failed to serve", "error", err) + return + } + }() + + wg.Add(1) + go func() { + defer wg.Done() + <-ctx.Done() + s.GracefulStop() + }() +} diff --git a/services/relationship-manager-service/internal/service/relationship.go b/services/relationship-manager-service/internal/service/relationship.go new file mode 100644 index 0000000..08a6460 --- /dev/null +++ b/services/relationship-manager-service/internal/service/relationship.go @@ -0,0 +1,403 @@ +package service + +import ( + "context" + "fmt" + "github.com/emortalmc/proto-specs/gen/go/grpc/relationship" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/timestamppb" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/kafka" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository" +"github.com/emortalmc/mono-services/services/relationship-manager-service/internal/repository/model" +) +type relationshipService struct { + relationship.RelationshipServer + + ctx context.Context + + logger *zap.SugaredLogger + + repo repository.Repository + notif kafka.Notifier +} + +// newPermissionService creates a new permission service +// - Takes context as a request's context cannot be used (it will cancel before the kafka message is sent) +func newPermissionService(ctx context.Context, repo repository.Repository, logger *zap.SugaredLogger, + notif kafka.Notifier) relationship.RelationshipServer { + return &relationshipService{ + ctx: ctx, + + logger: logger, + + repo: repo, + notif: notif, + } +} + +func (s *relationshipService) AddFriend(ctx context.Context, req *relationship.AddFriendRequest) (*relationship.AddFriendResponse, error) { + senderId, err := uuid.Parse(req.Request.SenderId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.Request.SenderId)) + } + targetId, err := uuid.Parse(req.Request.TargetId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.Request.TargetId)) + } + + alrFriends, err := s.repo.AreFriends(ctx, senderId, targetId) + if err != nil { + return nil, err + } + if alrFriends { + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_ALREADY_FRIENDS, + }, nil + } + + blocks, err := s.repo.GetMutualBlocks(ctx, senderId, targetId) + if err != nil { + return nil, err + } + if len(blocks) > 0 { + for _, block := range blocks { + if block.ContainsPlayer(senderId) { + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_YOU_BLOCKED, + }, nil + } + } + + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_PRIVACY_BLOCKED, + }, nil + } + + alrRequested, err := s.repo.DoesPendingFriendConnectionExist(ctx, senderId, targetId) + if err != nil { + return nil, err + } + if alrRequested { + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_ALREADY_REQUESTED, + }, nil + } + + // Whether they have sent a friend request to you already + oppositeRequest, err := s.repo.DoesPendingFriendConnectionExist(ctx, targetId, senderId) + if err != nil { + return nil, err + } + + if oppositeRequest { + // create friendship + err = s.repo.CreateFriendConnection(ctx, &model.FriendConnection{ + Id: primitive.NewObjectID(), + PlayerOneId: senderId, + PlayerTwoId: targetId, + }) + if err != nil { + return nil, err + } + + // delete pending friend connection + err = s.repo.DeletePendingFriendConnection(ctx, senderId, targetId) + if err != nil { + return nil, err + } + + go func() { + err := s.notif.FriendAdded(s.ctx, senderId, targetId, req.Request.SenderUsername) + if err != nil { + s.logger.Errorf("failed to send friend added notification to %s: %v", targetId, err) + } + }() + + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_FRIEND_ADDED, + FriendsSince: timestamppb.Now(), + }, nil + } else { + friendConn := model.PendingFriendConnection{ + Id: primitive.NewObjectID(), + RequesterId: senderId, + TargetId: targetId, + } + err = s.repo.CreatePendingFriendConnection(ctx, &friendConn) + if err != nil { + return nil, err + } + + go func() { + err := s.notif.FriendRequest(s.ctx, req.Request) + if err != nil { + s.logger.Errorf("failed to send friend request notification to %s: %v", targetId, err) + } + }() + + return &relationship.AddFriendResponse{ + Result: relationship.AddFriendResponse_REQUEST_SENT, + }, nil + } +} + +func (s *relationshipService) RemoveFriend(ctx context.Context, req *relationship.RemoveFriendRequest) (*relationship.RemoveFriendResponse, error) { + senderId, err := uuid.Parse(req.SenderId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.SenderId)) + } + targetId, err := uuid.Parse(req.TargetId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.TargetId)) + } + + err = s.repo.DeleteFriendConnection(ctx, senderId, targetId) + if err != nil { + if err == repository.NotFriendsError { + return &relationship.RemoveFriendResponse{ + Result: relationship.RemoveFriendResponse_NOT_FRIENDS, + }, nil + } + return nil, err + } + + err = s.notif.FriendRemoved(s.ctx, senderId, targetId) + if err != nil { + return nil, err + } + + return &relationship.RemoveFriendResponse{ + Result: relationship.RemoveFriendResponse_REMOVED, + }, nil +} + +func (s *relationshipService) DenyFriendRequest(ctx context.Context, req *relationship.DenyFriendRequestRequest) (*relationship.DenyFriendRequestResponse, error) { + senderId, err := uuid.Parse(req.IssuerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.IssuerId)) + } + targetId, err := uuid.Parse(req.TargetId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.TargetId)) + } + + err = s.repo.DeletePendingFriendConnection(ctx, senderId, targetId) + if err != nil { + if err == repository.NoFriendRequestError { + return &relationship.DenyFriendRequestResponse{ + Result: relationship.DenyFriendRequestResponse_NO_REQUEST, + }, nil + } + return nil, err + } + + return &relationship.DenyFriendRequestResponse{ + Result: relationship.DenyFriendRequestResponse_DENIED, + }, nil +} + +func (s *relationshipService) MassDenyFriendRequest(ctx context.Context, req *relationship.MassDenyFriendRequestRequest) (*relationship.MassDenyFriendRequestResponse, error) { + senderId, err := uuid.Parse(req.IssuerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.IssuerId)) + } + + var opts repository.DirectionOpts + if req.Incoming { + opts = repository.DirectionOpts{ + Incoming: true, + } + } else { + opts = repository.DirectionOpts{ + Outgoing: true, + } + } + + count, err := s.repo.DeletePendingFriendConnections(ctx, senderId, &opts) + if err != nil { + return nil, err + } + + return &relationship.MassDenyFriendRequestResponse{RequestsDenied: uint32(count)}, nil +} + +func (s *relationshipService) GetFriendList(ctx context.Context, req *relationship.GetFriendListRequest) (*relationship.FriendListResponse, error) { + playerId, err := uuid.Parse(req.PlayerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.PlayerId)) + } + + conns, err := s.repo.GetFriendConnections(ctx, playerId) + if err != nil { + return nil, err + } + + var connProtos = make([]*relationship.FriendListResponse_FriendListPlayer, len(conns)) + + for i, conn := range conns { + var friendId uuid.UUID + if conn.PlayerOneId == playerId { + friendId = conn.PlayerTwoId + } else { + friendId = conn.PlayerOneId + } + + connProtos[i] = &relationship.FriendListResponse_FriendListPlayer{ + Id: friendId.String(), + FriendsSince: timestamppb.New(conn.Id.Timestamp()), + } + } + + return &relationship.FriendListResponse{ + Friends: connProtos, + }, nil +} + +func (s *relationshipService) GetPendingFriendRequestList(ctx context.Context, req *relationship.GetPendingFriendRequestListRequest) (*relationship.PendingFriendListResponse, error) { + playerId, err := uuid.Parse(req.IssuerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.IssuerId)) + } + + conns, err := s.repo.GetPendingFriendConnections(ctx, playerId, repository.DirectionOpts{ + Incoming: req.Incoming, + Outgoing: !req.Incoming, + }) + if err != nil { + return nil, err + } + + var connProtos = make([]*relationship.PendingFriendListResponse_RequestedFriendPlayer, len(conns)) + for i, conn := range conns { + connProtos[i] = &relationship.PendingFriendListResponse_RequestedFriendPlayer{ + RequesterId: conn.RequesterId.String(), + TargetId: conn.TargetId.String(), + RequestTime: timestamppb.New(conn.Id.Timestamp()), + } + } + + return &relationship.PendingFriendListResponse{ + Requests: connProtos, + }, nil +} + +func (s *relationshipService) CreateBlock(ctx context.Context, req *relationship.CreateBlockRequest) (*relationship.CreateBlockResponse, error) { + blockProto := req.GetBlock() + blockerId, err := uuid.Parse(blockProto.BlockerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid blocker id %s", blockProto.BlockerId)) + } + blockedId, err := uuid.Parse(blockProto.BlockedId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid blocked player id %s", blockProto.BlockedId)) + } + + areFriends, err := s.repo.AreFriends(ctx, blockerId, blockedId) + if err != nil { + return nil, err + } + if areFriends { + return &relationship.CreateBlockResponse{ + Result: relationship.CreateBlockResponse_FAILED_FRIENDS, + }, nil + } + + err = s.repo.CreatePlayerBlock(ctx, &model.PlayerBlock{Id: primitive.NewObjectID(), BlockedId: blockedId, BlockerId: blockerId}) + + if err != nil { + if err == repository.AlreadyBlockedError { + return &relationship.CreateBlockResponse{ + Result: relationship.CreateBlockResponse_ALREADY_BLOCKED, + }, nil + } + return nil, err + } + + return &relationship.CreateBlockResponse{ + Result: relationship.CreateBlockResponse_SUCCESS, + }, nil +} + +func (s *relationshipService) DeleteBlock(ctx context.Context, req *relationship.DeleteBlockRequest) (*relationship.DeleteBlockResponse, error) { + issuerId, err := uuid.Parse(req.IssuerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid issuer id %s", req.IssuerId)) + } + targetId, err := uuid.Parse(req.TargetId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid target id %s", req.TargetId)) + } + + err = s.repo.DeletePlayerBlock(ctx, issuerId, targetId) + if err != nil { + if err == mongo.ErrNoDocuments { + return nil, status.Error(codes.NotFound, fmt.Sprintf("block between %s and %s not found", issuerId, targetId)) + } + return nil, err + } + + return &relationship.DeleteBlockResponse{}, nil +} + +func (s *relationshipService) IsBlocked(ctx context.Context, req *relationship.IsBlockedRequest) (*relationship.IsBlockedResponse, error) { + issuerId, err := uuid.Parse(req.IssuerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid issuer id %s", req.IssuerId)) + } + targetId, err := uuid.Parse(req.TargetId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid target id %s", req.TargetId)) + } + + blocks, err := s.repo.GetMutualBlocks(ctx, issuerId, targetId) + if err != nil { + return nil, err + } + + // select the issuer as the block if there is more than 1 + var block *model.PlayerBlock + if len(blocks) > 1 { + for _, b := range blocks { + if b.BlockedId == issuerId { + block = b + break + } + } + } else if len(blocks) == 1 { + block = blocks[0] + } else { + return &relationship.IsBlockedResponse{ + Block: nil, + }, nil + } + + return &relationship.IsBlockedResponse{ + Block: block.ToProto(), + }, nil +} + +func (s *relationshipService) GetBlockedList(ctx context.Context, req *relationship.GetBlockedListRequest) (*relationship.BlockedListResponse, error) { + playerId, err := uuid.Parse(req.PlayerId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid player id %s", req.PlayerId)) + } + + blocks, err := s.repo.GetPlayerBlocks(ctx, playerId) + if err != nil { + return nil, err + } + + var blockedIds = make([]string, len(blocks)) + for i, block := range blocks { + blockedIds[i] = block.BlockedId.String() + } + + return &relationship.BlockedListResponse{ + BlockedPlayerIds: blockedIds, + }, nil +} diff --git a/services/relationship-manager-service/run/config.yaml b/services/relationship-manager-service/run/config.yaml new file mode 100644 index 0000000..54b0bb9 --- /dev/null +++ b/services/relationship-manager-service/run/config.yaml @@ -0,0 +1,14 @@ +development: true + +kafka: + host: localhost + port: 9092 + +playerTrackerService: + host: localhost + port: 10005 + +mongodb: + uri: mongodb://localhost:27017 + +port: 10002