diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f6150ead7..49ffd7173 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,3 +1,17 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: @@ -9,3 +23,37 @@ updates: directory: "/" schedule: interval: "daily" + time: "08:00" + labels: + - "dependencies" + commit-message: + prefix: "feat" + include: "scope" + groups: + gomod-deps: + patterns: + - "*" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + time: "08:00" + labels: + - "dependencies" + commit-message: + prefix: "chore" + include: "scope" + groups: + github-actions: + patterns: + - "*" + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + time: "08:00" + labels: + - "dependencies" + commit-message: + prefix: "feat" + include: "scope" \ No newline at end of file diff --git a/.github/workflows/auto-gh-pr.yml b/.github/workflows/auto-gh-pr.yml index 1d8c90d33..0913655ca 100644 --- a/.github/workflows/auto-gh-pr.yml +++ b/.github/workflows/auto-gh-pr.yml @@ -18,30 +18,21 @@ on: pull_request: # types: # - closed + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] jobs: create-pr: runs-on: ubuntu-latest - if: github.event.pull_request.base.ref == 'main' + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true steps: - name: Check out code uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Setup GitHub CLI - run: | - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 - sudo apt-add-repository https://cli.github.com/packages - sudo apt-get update - sudo apt-get install gh - continue-on-error: true - - # - name: Configure GitHub CLI - # run: | - # git config --global user.email "3293172751ysy@gmail.com" - # git config --global user.name "kubbot" - # echo "${{ secrets.BOT_GITHUB_TOKEN }}" | gh auth login --with-token - name: Create PR to release branch run: | ISSUEID=$(gh pr view ${{ github.event.pull_request.number }} --repo $OWNER/$REPO | grep -oP 'Fixes #\K\d+') @@ -56,10 +47,9 @@ jobs: gh pr edit ${{ github.event.pull_request.number }} --repo $OWNER/$REPO --add-label "$LABELS" --add-assignee "$ASSIGNEES" --milestone "$MILESTONE" - git checkout -b bot/merge-to-release-$ISSUEID - git push origin bot/merge-to-release-$ISSUEID - gh pr create --base release --head bot/merge-to-release-$ISSUEID --title "Merge main to release" --body "" - + # git checkout -b bot/merge-to-release-$ISSUEID + # git push origin bot/merge-to-release-$ISSUEID + # gh pr create --base release --head bot/merge-to-release-$ISSUEID --title "Merge main to release" --body "" # gh pr create --base main --head feat/auto-release-pr-624 --title "The bug is fixed" --body "$x" --repo OpenIMSDK/Open-IM-Server --reviewer "cubxxw" continue-on-error: true env: @@ -67,4 +57,4 @@ jobs: GH_TOKEN: ${{ github.token }} ISSUE: ${{ github.event.issue.html_url }} OWNER: ${{ github.repository_owner }} - REPO: ${{ github.event.repository.name }} \ No newline at end of file + REPO: ${{ github.event.repository.name }} diff --git a/.github/workflows/auto-invite.yml b/.github/workflows/auto-invite.yml index 2bc644bfb..0fd9a4eab 100644 --- a/.github/workflows/auto-invite.yml +++ b/.github/workflows/auto-invite.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Invite user to join our group - uses: peter-evans/create-or-update-comment@v1 + uses: peter-evans/create-or-update-comment@v3 with: token: ${{ secrets.BOT_GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml new file mode 100644 index 000000000..d6dd56139 --- /dev/null +++ b/.github/workflows/auto-tag.yml @@ -0,0 +1,52 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Create Tag + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + +jobs: + create_tag: + runs-on: ubuntu-latest + if: startsWith(github.event.comment.body, '/create tag') + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Validate version number and get comment + id: validate + run: | + COMMENT="${{ github.event.comment.body }}" + VERSION=$(echo $COMMENT | cut -d ' ' -f 3) + TAG_COMMENT=$(echo $COMMENT | cut -d '"' -f 2) + if [[ $VERSION =~ ^v([0-9]+\.){2}[0-9]+$ ]]; then + echo "version=$VERSION" >> $GITHUB_STATE + echo "tag_comment=$TAG_COMMENT" >> $GITHUB_STATE + else + echo "Invalid version number." + exit 1 + fi + + - name: Create a new tag + env: + GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + run: | + source $GITHUB_STATE + git tag -a $VERSION -m "$tag_comment" + git push origin $VERSION + echo "tag_created=$VERSION" >> $GITHUB_OUTPUT diff --git a/.github/workflows/bot-auto-cherry-pick.yml b/.github/workflows/bot-auto-cherry-pick.yml index 0d545813a..6861872e4 100644 --- a/.github/workflows/bot-auto-cherry-pick.yml +++ b/.github/workflows/bot-auto-cherry-pick.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment cherry-pick command - uses: actions/github-script@v5 + uses: actions/github-script@v6 with: script: | const pr = context.payload.pull_request; diff --git a/.github/workflows/bot-cherry-pick.yml b/.github/workflows/bot-cherry-pick.yml index 59a4979cf..2e69e0d0a 100644 --- a/.github/workflows/bot-cherry-pick.yml +++ b/.github/workflows/bot-cherry-pick.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout the latest code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: token: ${{ secrets.BOT_GITHUB_TOKEN }} fetch-depth: 0 # otherwise, you will fail to push refs to dest repo diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 3dd64c930..f9fb42500 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -23,16 +23,20 @@ on: - v* workflow_dispatch: +env: + # Common versions + GO_VERSION: "1.20" + jobs: - build: + build-dockerhub: runs-on: ubuntu-latest steps: - - name: Check out the repo + - name: Checkout uses: actions/checkout@v3 - - - name: Build OpenIM Server - run: | - sudo make build + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 # docker.io/openim/openim-server:latest - name: Extract metadata (tags, labels) for Docker @@ -40,6 +44,15 @@ jobs: uses: docker/metadata-action@v4.6.0 with: images: openim/openim-server + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - name: Log in to Docker Hub uses: docker/login-action@v2 @@ -51,10 +64,21 @@ jobs: uses: docker/build-push-action@v4 with: context: . + # linux/ppc64le,linux/s390x + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-aliyun: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 # registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:latest - name: Extract metadata (tags, labels) for Docker id: meta2 @@ -73,10 +97,21 @@ jobs: uses: docker/build-push-action@v4 with: context: . + # linux/ppc64le,linux/s390x + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta2.outputs.tags }} labels: ${{ steps.meta2.outputs.labels }} + build-ghcr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 # ghcr.io/openimsdk/openim-server:latest - name: Extract metadata (tags, labels) for Docker id: meta3 @@ -88,13 +123,15 @@ jobs: uses: docker/login-action@v2 with: registry: ghcr.io - username: ${{ github.actor }} + username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . + # linux/ppc64le,linux/s390x + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta3.outputs.tags }} labels: ${{ steps.meta3.outputs.labels }} diff --git a/.github/workflows/check-coverage.yml b/.github/workflows/check-coverage.yml index 937af89d6..7080ef7be 100644 --- a/.github/workflows/check-coverage.yml +++ b/.github/workflows/check-coverage.yml @@ -44,7 +44,7 @@ jobs: uses: actions/checkout@v3 - name: Setup Golang with cache - uses: magnetikonline/action-golang-cache@v3 + uses: magnetikonline/action-golang-cache@v4 with: go-version: ${{ env.GO_VERSION }} diff --git a/.github/workflows/create_branch_on_tag.yml b/.github/workflows/create_branch_on_tag.yml index bdb53e80a..67ab11173 100644 --- a/.github/workflows/create_branch_on_tag.yml +++ b/.github/workflows/create_branch_on_tag.yml @@ -1,3 +1,17 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Create Branch on Tag on: diff --git a/.github/workflows/docker-buildx.yml b/.github/workflows/docker-buildx.yml new file mode 100644 index 000000000..3d1b3015f --- /dev/null +++ b/.github/workflows/docker-buildx.yml @@ -0,0 +1,320 @@ +# Copyright © 2023 OpenIM open source community. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Docker Buildx Images CI + +on: + schedule: + - cron: '30 1 * * *' + push: + branches: + - release-* + tags: + - v* + workflow_dispatch: + +jobs: + build-ghcr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + +################################################ +# build/ +# └── docker +# ├── openim-api +# │ └── Dockerfile +# ├── openim-cmdutils +# │ └── Dockerfile +# ├── openim-crontask +# │ └── Dockerfile +# ├── openim-msggateway +# │ └── Dockerfile +# ├── openim-msgtransfer +# │ └── Dockerfile +# ├── openim-push +# │ └── Dockerfile +# ├── openim-rpc-auth +# │ └── Dockerfile +# ├── openim-rpc-conversation +# │ └── Dockerfile +# ├── openim-rpc-friend +# │ └── Dockerfile +# ├── openim-rpc-group +# │ └── Dockerfile +# ├── openim-rpc-msg +# │ └── Dockerfile +# ├── openim-rpc-third +# │ └── Dockerfile +# └── openim-rpc-user +# └── Dockerfile +############################################# + + - name: Extract metadata (tags, labels) for Docker openim-api + id: meta1 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-api + + - name: Build and push Docker image for openim-api + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-api/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta1.outputs.tags }} + labels: ${{ steps.meta1.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-cmdutils + id: meta2 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-cmdutils + + - name: Build and push Docker image for openim-cmdutils + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-cmdutils/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta2.outputs.tags }} + labels: ${{ steps.meta2.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-crontask + id: meta3 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-crontask + + - name: Build and push Docker image for openim-crontask + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-crontask/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta3.outputs.tags }} + labels: ${{ steps.meta3.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-msggateway + id: meta4 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-msggateway + + - name: Build and push Docker image for openim-msggateway + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-msggateway/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta4.outputs.tags }} + labels: ${{ steps.meta4.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-msgtransfer + id: meta5 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-msgtransfer + + - name: Build and push Docker image for openim-msgtransfer + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-msgtransfer/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta5.outputs.tags }} + labels: ${{ steps.meta5.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-push + id: meta6 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-push + + - name: Build and push Docker image for openim-push + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-push/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta6.outputs.tags }} + labels: ${{ steps.meta6.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-auth + id: meta7 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-auth + + - name: Build and push Docker image for openim-rpc-auth + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-auth/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta7.outputs.tags }} + labels: ${{ steps.meta7.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-conversation + id: meta8 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-conversation + + - name: Build and push Docker image for openim-rpc-conversation + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-conversation/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta8.outputs.tags }} + labels: ${{ steps.meta8.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-friend + id: meta9 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-friend + + - name: Build and push Docker image for openim-rpc-friend + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-friend/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta9.outputs.tags }} + labels: ${{ steps.meta9.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-group + id: meta10 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-group + + - name: Build and push Docker image for openim-rpc-group + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-group/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta10.outputs.tags }} + labels: ${{ steps.meta10.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-msg + id: meta11 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-msg + + - name: Build and push Docker image for openim-rpc-msg + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-msg/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta11.outputs.tags }} + labels: ${{ steps.meta11.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-third + id: meta12 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-third + + - name: Build and push Docker image for openim-rpc-third + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-third/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta12.outputs.tags }} + labels: ${{ steps.meta12.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Extract metadata (tags, labels) for Docker openim-rpc-user + id: meta13 + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/openimsdk/openim-rpc-user + + - name: Build and push Docker image for openim-rpc-user + uses: docker/build-push-action@v4 + with: + context: . + file: ./build/docker/openim-rpc-user/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta13.outputs.tags }} + labels: ${{ steps.meta13.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache \ No newline at end of file diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml deleted file mode 100644 index 2ecfad6ea..000000000 --- a/.github/workflows/image.yml +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright © 2023 OpenIM open source community. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: Build Image - -on: - push: - branches: - - main - paths: - - "**.go" - - "!**_test.go" - - "build/**" - tags: - - v* - -jobs: - release: - strategy: - matrix: - components: [core, swagger] - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 20 - - uses: dorny/paths-filter@v2 - if: ${{ !startsWith(github.ref_name, 'v') }} - id: changes - with: - filters: | - go: - - '**.go' - - 'build/core/Dockerfile' - api: - - 'openapi/**' - - 'build/swagger/build.sh' - - 'build/swagger/Dockerfile' - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - flavor: | - latest=false - images: | - ${{ secrets.DOCKERHUB_USERNAME }}/openimsdk-${{ matrix.components }} - registry.cn-hangzhou.aliyuncs.com/${{ secrets.ALIREGISTRY_NAMESPACE }}/openimsdk-${{ matrix.components }} - tags: | - type=ref,event=branch - type=sha,prefix={{branch}}-,enable=${{ github.ref_type == 'branch' }} - type=ref,event=tag - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to Ali Container Registry - uses: docker/login-action@v2 - with: - registry: registry.cn-hangzhou.aliyuncs.com - username: ${{ secrets.ALIREGISTRY_USERNAME }} - password: ${{ secrets.ALIREGISTRY_TOKEN }} - - - name: Condition - id: condition - run: | - echo "run=${{ startsWith(github.ref_name, 'v') || ((steps.changes.outputs.go == 'true' && (matrix.components == 'core' || matrix.components == 'job')) || (steps.changes.outputs.api == 'true' && matrix.components == 'swagger')) }}" >> $GITHUB_OUTPUT - - - name: Set up QEMU - if: ${{ steps.condition.outputs.run == 'true' }} - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - if: ${{ steps.condition.outputs.run == 'true' }} - uses: docker/setup-buildx-action@v2 - - name: Build and push - if: ${{ steps.condition.outputs.run == 'true' }} - uses: docker/build-push-action@v3 - with: - context: . - file: ./build/${{ matrix.components }}/Dockerfile - platforms: linux/amd64 - push: true - tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/link-pr.yml b/.github/workflows/link-pr.yml index 07b9d46a9..356394f94 100644 --- a/.github/workflows/link-pr.yml +++ b/.github/workflows/link-pr.yml @@ -27,7 +27,7 @@ jobs: - name: Link Checker id: lychee - uses: lycheeverse/lychee-action@v1.7.0 + uses: lycheeverse/lychee-action@v1.8.0 with: # For parameter description, see https://github.com/lycheeverse/lychee#commandline-parameters # Actions Link address -> https://github.com/lycheeverse/lychee-action diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml new file mode 100644 index 000000000..e0731b25f --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,72 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# shamelessly copied from https://github.com/sigstore/cosign/blob/main/.github/workflows/milestone.yaml + +name: milestone + +on: + pull_request_target: + types: [closed] + branches: + - main + +jobs: + milestone: + runs-on: ubuntu-latest + + permissions: + actions: none + checks: none + contents: read + deployments: none + issues: write + packages: none + pull-requests: write + repository-projects: none + security-events: none + statuses: none + + steps: + - uses: actions/github-script@v6 # v6 + with: + script: | + if (!context.payload.pull_request.merged) { + console.log('PR was not merged, skipping.'); + return; + } + + if (!!context.payload.pull_request.milestone) { + console.log('PR has existing milestone, skipping.'); + return; + } + + milestones = await github.rest.issues.listMilestones({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + sort: 'due_on', + direction: 'asc' + }) + if (milestones.data.length === 0) { + console.log('There are no milestones, skipping.'); + return; + } + + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + milestone: milestones.data[0].number + }); diff --git a/.github/workflows/opencommit.yml b/.github/workflows/opencommit.yml index 36307c00f..a07b5b8b2 100644 --- a/.github/workflows/opencommit.yml +++ b/.github/workflows/opencommit.yml @@ -27,7 +27,7 @@ jobs: permissions: write-all steps: - name: Setup Node.js Environment - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: '16' - uses: actions/checkout@v3 diff --git a/.github/workflows/openimci.yml b/.github/workflows/openimci.yml index 07133126b..d172eb251 100644 --- a/.github/workflows/openimci.yml +++ b/.github/workflows/openimci.yml @@ -53,7 +53,7 @@ jobs: steps: - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go_version }} id: go @@ -90,19 +90,11 @@ jobs: echo "Run unit test and get test coverage successfully" continue-on-error: true - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: go - - name: Build source code for host platform run: | sudo make build echo "Build source code for host platform successfully" - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - name: OpenIM verify copyright run: | sudo make verify-copyright @@ -157,7 +149,7 @@ jobs: continue-on-error: true - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 continue-on-error: true openim-start: @@ -171,13 +163,13 @@ jobs: os: ["ubuntu-latest"] steps: - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go_version }} id: go - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Run OpenIM make install start run: | diff --git a/.github/workflows/project-progress.yml b/.github/workflows/project-progress.yml index 247404aa0..d0cc10604 100644 --- a/.github/workflows/project-progress.yml +++ b/.github/workflows/project-progress.yml @@ -33,4 +33,4 @@ jobs: with: project: OpenIM-V3.1 column: In Progress - repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + repo-token: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3405e479e..ac8904450 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -47,7 +47,7 @@ jobs: git checkout -b cicd/patch-${{ github.event.number }} - uses: actions/setup-node@v3 - name: Setup Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 - name: Run go modules tidy run: | sudo make tidy diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45ed79df2..fd019c4df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,7 +60,7 @@ jobs: matrix: format: [ deb, rpm, apk ] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 + - uses: actions/checkout@v3 # v3 with: fetch-depth: 0 - uses: arduino/setup-task@e26d8975574116b0097a1161e0fe16ba75d84c1c # v1 diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.yml index e59e696f8..44b217c59 100644 --- a/.github/workflows/scripts-test.yml +++ b/.github/workflows/scripts-test.yml @@ -38,12 +38,15 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 + + - name: Download Docker Compose + run: | + curl -o docker-compose.yaml https://gist.githubusercontent.com/cubxxw/b1d5cbd2edfa23fee911118aa3e8249e/raw/openim-server.sh + shell: bash - name: Start Docker Compose run: | - sudo docker compose stop - sudo sleep 30 sudo docker compose up -d sudo sleep 60 continue-on-error: true diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 7790aa944..ba767f167 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -32,7 +32,7 @@ jobs: pull-requests: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v8 with: repo-token: ${{ secrets.BOT_GITHUB_TOKEN }} days-before-stale: 60 diff --git a/.gitignore b/.gitignore index e6808d57e..bb9e8e8c0 100644 --- a/.gitignore +++ b/.gitignore @@ -156,7 +156,7 @@ flycheck_*.el # vendor/ # Go workspace file -go.work +# go.work ### JetBrains ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider diff --git a/.golangci.yml b/.golangci.yml index 296bd0dc0..8bafbbe5c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -114,7 +114,7 @@ linters-settings: max-blank-identifiers: 2 dupl: # tokens count to trigger issue, 150 by default - threshold: 100 + threshold: 200 errcheck: # report about not checking of errors in type assertions: `a := b.(MyStruct)`; # default is false: such cases aren't reported by default. diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 31cdbd085..184949283 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -447,8 +447,8 @@ milestones: # Repository for the milestone # Default is extracted from the origin remote URL repo: - owner: user - name: repo + owner: OpenIMSDK + name: Open-IM-Server # Whether to close the milestone close: true @@ -479,6 +479,9 @@ checksum: algorithm: sha256 release: + + prerelease: auto + footer: | ## Welcome to the {{ .Tag }} release of [chat](https://github.com/OpenIMSDK/chat)!🎉🎉! @@ -487,18 +490,14 @@ release: ## Helping out - We release logs are recorded on [✨ CHANGELOG](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CHANGELOG/CHANGELOG.md)--config_folder_path + + We release logs are recorded on [✨CHANGELOG](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CHANGELOG/CHANGELOG.md) - For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) + + For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) - This release is only possible thanks to **all** the support of some **awesome people**! - - https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md + + If you wish to use mirroring, read OpenIM's [image management policy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) **Want to be one of them 😘?** - Contributions to this project are welcome! Please see [CONTRIBUTING.md](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md) for details. -

@@ -511,6 +510,11 @@ release:

+ > **Note** + > @openimbot and @kubbot have made great contributions to the community as community 🤖robots(@openimsdk/bot), respectively. + > Thanks to the @openimsdk/openim team for all their hard work on this release. + > Thank you to all the [💕developers and contributors](https://github.com/OpenIMSDK/Open-IM-Server/graphs/contributors), people from all over the world, OpenIM brings us together + > Contributions to this project are welcome! Please see [CONTRIBUTING.md](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md) for details. ## Get Involved with OpenIM! diff --git a/Dockerfile b/Dockerfile index 85afdf98b..733849fd9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,5 @@ # Build Stage -FROM golang:1.20 AS builder - -LABEL org.opencontainers.image.source=https://github.com/OpenIMSDK/Open-IM-Server -LABEL org.opencontainers.image.description="OpenIM Server image" -LABEL org.opencontainers.image.licenses="Apache 2.0" +FROM golang:1.21 AS builder # Set go mod installation source and proxy ARG GO111MODULE=on @@ -12,26 +8,24 @@ ENV GO111MODULE=$GO111MODULE ENV GOPROXY=$GOPROXY # Set up the working directory -WORKDIR /Open-IM-Server +WORKDIR /openim/openim-server + +COPY go.mod go.sum ./ +RUN go mod download # Copy all files to the container ADD . . -RUN /bin/sh -c "make build" +RUN make clean +RUN make build -# Production Stage -FROM alpine +FROM ghcr.io/openim-sigs/openim-bash-image:latest -RUN echo "https://mirrors.aliyun.com/alpine/v3.4/main" > /etc/apk/repositories && \ - apk --no-cache add tzdata ca-certificates bash - -# Set directory to map logs, config files, scripts, and SDK -VOLUME ["/Open-IM-Server/logs", "/Open-IM-Server/config", "/Open-IM-Server/scripts", "/Open-IM-Server/db/sdk"] +WORKDIR ${SERVER_WORKDIR} # Copy scripts and binary files to the production image -COPY --from=builder /Open-IM-Server/scripts /Open-IM-Server/scripts -COPY --from=builder /Open-IM-Server/_output/bin/platforms/linux/amd64 /Open-IM-Server/_output/bin/platforms/linux/amd64 - -WORKDIR /Open-IM-Server/scripts +COPY --from=builder ${OPENIM_SERVER_CMDDIR} /openim/openim-server/scripts +COPY --from=builder ${SERVER_WORKDIR}/config /openim/openim-server/config +COPY --from=builder ${SERVER_WORKDIR}/_output/bin/platforms /openim/openim-server/_output/bin/platforms -CMD ["./docker_start_all.sh"] \ No newline at end of file +CMD ["bash","-c","${OPENIM_SERVER_CMDDIR}/docker_start_all.sh"] diff --git a/README.md b/README.md index 3c52475f3..ecb39213b 100644 --- a/README.md +++ b/README.md @@ -22,42 +22,109 @@

English • - 中文 + 简体中文 • + Docs

+

-## What is Open-IM-Server +## ✨ About OpenIM + +Open-IM-Server, crafted meticulously using pure Golang, stands as a robust instant messaging server. Its unique approach to communication, via JSON over WebSocket, treats every interaction as a message. This simplifies customization and eliminates the need for tinkering with server code. Harnessing the power of microservice architecture, the server can be deployed via clusters, promising impressive performance and scalability. + +Open-IM-Server is more than an instant messaging server; it's a powerful tool for incorporating real-time networking into your applications, positioning itself as your premier choice for integration! 🚀 + +Please be aware that Open-IM-Server does not function as a standalone product and does not offer built-in account registration or login services. To ease your implementation process, we've open-sourced the [chat repository](https://github.com/OpenIMSDK/chat), which comprises these features. Deploying this chat business server in conjunction with Open-IM-Server expedites the setup of a comprehensive chat product. 👥 + +Further enhancing your experience, we also provide an SDK client, wherein most complex logics are implemented. The [SDK repository](https://github.com/OpenIMSDK/openim-sdk-core) can be found at [this link](https://github.com/OpenIMSDK/openim-sdk-core). The [chat repository](https://github.com/OpenIMSDK/chat) is our business server while the 'core' represents the high-level encapsulation of the SDK, synergistically working together to deliver superior results. ✨ + +## :star2: Why OpenIM + +**🔍 Function screenshot display** + +
+ +| 💻🔄📱 Multi Terminal Synchronization 🔄🖥️ | 📅⚡ Efficient Meetings 🚀💼 | +| :----------------------------------------------------------: | :---------------------------------------------------------: | +| ![multiple-message](./assets/demo/multi-terminal-synchronization.png) | ![efficient-meetings](./assets/demo/efficient-meetings.png) | +| 📲🔄 **One-to-one and Group Chats** 👥🗣️ | 🎁💻 **Special Features - Custom Messages** ✉️🎨| +| ![group-chat](./assets/demo/group-chat.png) | ![special-function](./assets/demo/special-function.png) | + +
+ +1. **Comprehensive Message Type Support :speech_balloon:** + + ✅ Supports almost all types of messages, including text, images, emojis, voice, video, geographical location, files, quotes, business cards, system notifications, custom messages and more + + ✅ Supports one-on-one and multi-person audio and video calls + + ✅ Provides terminal support for multiple platforms such as iOS, Android, Flutter, uni-app, ReactNative, Electron, Web, H5 + +2. **Efficient Meetings Anytime, Anywhere :earth_americas:** + + ✅ Based on IM (Instant Messaging) with 100% reliable forced signaling capabilities, it paves the way for IM systems, deeply integrated with chat applications + + ✅ Supports hundreds of people in a single meeting, with subscription numbers reaching thousands, and server-side audio and video recording + +3. **One-on-one and Group Chats for Various Social Scenarios :busts_in_silhouette:** + + ✅ OpenIM has four roles: application administrator, group owner, group administrator, and regular member + + ✅ Powerful group features such as muting, group announcements, group validation, unlimited group members, and loading group messages as needed + +4. **Unique Features :star2:** + + ✅ Supports read-and-burn private chats, customizable duration + + ✅ Message editing function broadens social scenarios, making instant communication more diverse and interesting + +5. **Open Source :open_hands:** + + ✅ The code of OpenIM is open source, self-controlled data, aimed at building a globally leading IM open source community, including client SDK and server + + ✅ Based on open source Server, many excellent open source projects have been developed, such as [OpenKF](https://github.com/OpenIMSDK/OpenKF) (Open source AI customer service system) + +6. **Easy to Expand :wrench:** + + ✅ The OpenIM server is implemented in Golang, introducing an innovative "everything is a message" communication model, simplifying the implementation of custom messages and extended features + +7. **High Performance :racing_car:** + + ✅ OpenIM supports a hierarchical governance architecture in the cluster, tested by a large number of users, and abstracts the storage model of online messages, offline messages, and historical messages -Open-IM-Server is an instant messaging server developed using pure Golang, adopting JSON over WebSocket as the communication protocol. In Open-IM-Server, everything is a message, so you can easily extend custom messages without modifying the server code. With a microservice architecture, Open-IM-Server can be deployed using clusters. By deploying Open-IM-Server on a server, developers can quickly integrate instant messaging and real-time networking features into their applications, ensuring the security and privacy of business data. +8. **Full Platform Support :tv:** -Open-IM-Server is not a standalone product and does not include account registration and login services. For your convenience, we have open-sourced the [chat repository](https://github.com/OpenIMSDK/chat) which includes login and registration functionality. By deploying the chat business server alongside Open-IM-Server, a chat product can be set up. + ✅ Supports native iOS, Android; cross-platform Flutter, uni-app, ReactNative; major web front-end frameworks such as React, Vue; applets; and PC platforms supported by Electron -## Features +9. **The ultimate deployment experience 🤖** -- Open source -- Easy to integrate -- Excellent scalability -- High performance -- Lightweight -- Supports multiple protocols + ✅ Supports [cluster deployment](https://github.com/OpenIMSDK/Open-IM-Server/edit/main/deployments/README.md) -## Community -- Visit the official website: [OpenIM Developer Documentation](https://www.openim.online/) + ✅ Supports multi-architecture mirroring, our Docker images are hosted not only on GitHub but also on Alibaba Cloud and Docker Hub supporting multiple architectures. Visit [our GitHub packages](https://github.com/orgs/OpenIMSDK/packages?repo_name=Open-IM-Server) and read our [version management document](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) for more information. -## Quick Start +11. **A large ecosystem of open source communities 🤲** -### Deploying with docker-compose + ✅ We have tens of thousands of users and many solutions to problems. + + ✅ We have a large open source community called [OpenIMSDK](https://github.com/OpenIMSDK) that runs the core modules, we have an open source community called [openim-sigs](https://github.com/openim-sigs) to explore more IM-based infrastructure products. + +## :rocket: Quick Start + +
Deploying with Docker Compose 1. Clone the project ```bash # choose what you need -BRANCH=release-v3.0 +BRANCH=release-v3.1 git clone -b $BRANCH https://github.com/OpenIMSDK/Open-IM-Server openim && export openim=$(pwd)/openim && cd $openim && make build ``` -2. Modify .env +> **Note** +> Read our release policy: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md + +2. Modify `.env` ```bash USER=root #no need to modify @@ -70,9 +137,9 @@ DATA_DIR=./ #designate large disk directory 3. Deploy and start > **Note** -> This command can only be executed once. It will modify the component passwords in docker-compose based on the PASSWORD variable in .env, and modify the component passwords in config/config.yaml. If the password in .env changes, you need to first execute docker-compose down; rm components -rf and then execute this command. +> This command can only be executed once. It will modify the component passwords in docker-compose based on the `PASSWORD` variable in `.env`, and modify the component passwords in `config/config.yaml`. If the password in `.env` changes, you need to first execute `docker-compose down`; `rm components -rf` and then execute this command. -``` +```bash make install ``` @@ -84,16 +151,20 @@ make check ![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/docker_build.png) +
- -### Compile from source +
Compile from Source Ur need `Go 1.18` or higher version, and `make`. + +Version Details: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md + ```bash # choose what you need -BRANCH=release-v3.0 +BRANCH=release-v3.1 git clone -b $BRANCH https://github.com/OpenIMSDK/Open-IM-Server openim && export openim=$(pwd)/openim && cd $openim && make build ``` + Read about the [OpenIM Version Policy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) `make help` to help you see the instructions supported by OpenIM. @@ -102,7 +173,9 @@ All services have been successfully built as shown in the figure ![Successful Compilation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/build.png) -### Component Configuration Instructions +
+ +
Component Configuration Instructions The config/config.yaml file has detailed configuration instructions for the storage components. @@ -110,7 +183,7 @@ The config/config.yaml file has detailed configuration instructions for the stor - Used for RPC service discovery and registration, cluster support. - ``` + ```bash zookeeper: schema: openim #Not recommended to modify address: [ 127.0.0.1:2181 ] #address @@ -122,7 +195,7 @@ The config/config.yaml file has detailed configuration instructions for the stor - Used for storing users, relationships, and groups, supports master-slave database. - ``` + ```bash mysql: address: [ 127.0.0.1:13306 ] #address username: root #username @@ -139,7 +212,7 @@ The config/config.yaml file has detailed configuration instructions for the stor - Used for storing offline messages, supports mongo sharded clusters. - ``` + ```bash mongo: uri: #Use this value directly if not empty address: [ 127.0.0.1:37017 ] #address @@ -153,7 +226,7 @@ The config/config.yaml file has detailed configuration instructions for the stor - Used for storing message sequence numbers, latest messages, user tokens, and mysql cache, supports cluster deployment. - ``` + ```bash redis: address: [ 127.0.0.1:16379 ] #address username: #username @@ -164,7 +237,7 @@ The config/config.yaml file has detailed configuration instructions for the stor - Used for message queues, for message decoupling, supports cluster deployment. - ``` + ```bash kafka: username: #username password: #password @@ -185,27 +258,31 @@ The config/config.yaml file has detailed configuration instructions for the stor msgToModify: modify ``` -### Start and Stop Services +
+ +
Start and Stop Services Start services ``` -./start_all.sh; +./scripts/start_all.sh; ``` Check services ``` -./check_all.sh +./scripts/check_all.sh ``` Stop services ``` -./stop_all.sh +./scripts/stop_all.sh ``` -### Open IM Ports +
+ +
Open IM Ports | TCP Port | Description | Operation | | --------- | ------------------------------------------------------------ | ----------------------------------------------------- | @@ -213,42 +290,75 @@ Stop services | TCP:10002 | api port, such as user, friend, group, message interfaces. | Port release or nginx reverse proxy, and firewall off | | TCP:10005 | Required when choosing minio storage (openIM uses minio storage by default) | Port release or nginx reverse proxy, and firewall off | -### Open Chat Ports +
+ +
Open Chat Ports + ++ chat warehouse: https://github.com/OpenIMSDK/chat | TCP Port | Description | Operation | | --------- | --------------------------------------------------- | ----------------------------------------------------- | | TCP:10008 | Business system, such as registration, login etc | Port release or nginx reverse proxy, and firewall off | | TCP:10009 | Management backend, such as statistics, banning etc | Port release or nginx reverse proxy, and firewall off | -## Relationship Between APP and OpenIM +
+ +## :link: Relationship Between APP and OpenIM + +OpenIM isn't just an open-source instant messaging component, it's an integral part of your application ecosystem. Check out this diagram to understand how AppServer, AppClient, Open-IM-Server, and Open-IM-SDK interact. + +![App-OpenIM Relationship](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/open-im-server.png) + +## :building_construction: Overall Architecture + +Delve into the heart of Open-IM-Server's functionality with our architecture diagram. + +![Overall Architecture](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Architecture.jpg) + +## :hammer_and_wrench: To start developing OpenIM + +OpenIM Our goal is to build a top-level open source community. We have a set of standards, in the [Community repository](https://github.com/OpenIMSDK/community). + +If you'd like to contribute to this Open-IM-Server repository, please read our [contributor documentation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md). -OpenIM is an open source instant messaging component, it is not an independent product. This image shows the relationship between AppServer, AppClient, Open-IM-Server and Open-IM-SDK. +Before you start, please make sure your changes are in demand. The best for that is to create a [new discussion](https://github.com/OpenIMSDK/Open-IM-Server/discussions/new/choose) OR [Slack Communication](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg), or if you find an issue, [report it](https://github.com/OpenIMSDK/Open-IM-Server/issues/new/choose) first. -![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/open-im-server.png](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/open-im-server.png) +- [Code Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/go_code.md) +- [Docker Images Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) +- [Directory Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/directory.md) +- [Commit Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/commit.md) +- [Versioning Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) +- [Interface Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/api.md) +- [Log Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/log.md) +- [Error Code Standards](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/error_code.md) -## Overall Architecture +## :busts_in_silhouette: Community -![https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Architecture.jpg](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/images/Architecture.jpg) ++ 📚 [OpenIM Community](https://github.com/OpenIMSDK/community) ++ 💕 [OpenIM Interest Group](https://github.com/Openim-sigs) ++ 🚀 [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) ++ :eyes: [Join our wechat (微信群)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg) -## To start developing OpenIM -The [community repository](https://github.com/OpenIMSDK/community) hosts all information about building Kubernetes from source, how to contribute code and documentation, who to contact about what, etc. +## :calendar: Community Meetings +We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night. -## Contributing +Our conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) 🎯, then you can search the Open-IM-Server pipeline to join -Contributions to this project are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details. +We take notes of each [biweekly meeting](https://github.com/orgs/OpenIMSDK/discussions/categories/meeting) in [GitHub discussions](https://github.com/OpenIMSDK/Open-IM-Server/discussions/categories/meeting), Our historical meeting notes, as well as replays of the meetings are available at [Google Docs :bookmark_tabs:](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing). -## Community Meetings -We want anyone to get involved in our community, we offer gifts and rewards, and we welcome you to join us every Thursday night. +## :eyes: Who are using OpenIM -We take notes of each [biweekly meeting](https://github.com/OpenIMSDK/Open-IM-Server/issues/381) in [GitHub discussions](https://github.com/OpenIMSDK/Open-IM-Server/discussions/categories/meeting), and our minutes are written in [Google Docs](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing). +Check out our [user case studies](https://github.com/OpenIMSDK/community/blob/main/ADOPTERS.md) page for a list of the project users. Don't hesitate to leave a [📝comment](https://github.com/OpenIMSDK/Open-IM-Server/issues/379) and share your use case. +## :page_facing_up: License -## Who are using Open-IM-Server -The [user case studies](https://github.com/OpenIMSDK/community/blob/main/ADOPTERS.md) page includes the user list of the project. You can leave a [📝comment](https://github.com/OpenIMSDK/Open-IM-Server/issues/379) to let us know your use case. +OpenIM is licensed under the Apache 2.0 license. See [LICENSE](https://github.com/OpenIMSDK/Open-IM-Server/tree/main/LICENSE) for the full license text. -![avatar](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg) +The OpenIM logo, including its variations and animated versions, displayed in this repository [OpenIM](https://github.com/OpenIMSDK/Open-IM-Server) under the [assets/logo](./assets/logo) and [assets/logo-gif](assets/logo-gif) directories, are protected by copyright laws. -## License +## 🔮 Thanks to our contributors! -Open-IM-Server is under the Apache 2.0 license. See the [LICENSE](./LICENSE) file for details + + + diff --git a/assets/demo/README.md b/assets/demo/README.md new file mode 100644 index 000000000..ce4cc0fd9 --- /dev/null +++ b/assets/demo/README.md @@ -0,0 +1,14 @@ +## :star2: Why OpenIM + +**🔍 Function screenshot display** + +
+ + +| multiple message | Efficient meetings | +| :---------------------------------------: | :---------------------------------------------: | +| ![multiple-message](./multiple-message.png) | ![efficient-meetings](./efficient-meetings.png) | +| **One-to-one and group chats** | **Special features - Custom messages** | +| ![group-chat](./group-chat.png) | ![special-function](./special-function.png) | + +
diff --git a/assets/demo/efficient-meetings.png b/assets/demo/efficient-meetings.png new file mode 100644 index 000000000..46b009dc3 Binary files /dev/null and b/assets/demo/efficient-meetings.png differ diff --git a/assets/demo/group-chat.png b/assets/demo/group-chat.png new file mode 100644 index 000000000..1e9f7b624 Binary files /dev/null and b/assets/demo/group-chat.png differ diff --git a/assets/demo/multi-terminal-synchronization.png b/assets/demo/multi-terminal-synchronization.png new file mode 100644 index 000000000..62549aa70 Binary files /dev/null and b/assets/demo/multi-terminal-synchronization.png differ diff --git a/assets/demo/multiple-message.png b/assets/demo/multiple-message.png new file mode 100644 index 000000000..b02fef45f Binary files /dev/null and b/assets/demo/multiple-message.png differ diff --git a/assets/demo/special-function.png b/assets/demo/special-function.png new file mode 100644 index 000000000..c6943ec70 Binary files /dev/null and b/assets/demo/special-function.png differ diff --git a/build/docker/openim-api/Dockerfile b/build/docker/openim-api/Dockerfile index 1bf965ea4..7b2a4bd8e 100644 --- a/build/docker/openim-api/Dockerfile +++ b/build/docker/openim-api/Dockerfile @@ -1,12 +1,46 @@ -FROM golang:1.20.0 as build +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -WORKDIR /openim +# OpenIM base image: https://github.com/openim-sigs/openim-base-image -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo "Asia/Shanghai" > /etc/timezone && \ - mkdir -p /var/log/miniblog +# Set go mod installation source and proxy -COPY miniblog /openim +FROM golang:1.20 AS builder -EXPOSE 10002 -CMD ["./bin/openim-api","--port", "10002"] \ No newline at end of file +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-api + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE ${10002} + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-api --port 10002 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-cmdutils/Dockerfile b/build/docker/openim-cmdutils/Dockerfile index e69de29bb..eab064dc3 100644 --- a/build/docker/openim-cmdutils/Dockerfile +++ b/build/docker/openim-cmdutils/Dockerfile @@ -0,0 +1,45 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN go mod download +RUN make clean +RUN make build BINS=openim-cmdutils + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder ${SERVER_WORKDIR}/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder ${SERVER_WORKDIR}/config /openim/openim-server/config + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-cmdutils"] diff --git a/build/docker/openim-crontask/Dockerfile b/build/docker/openim-crontask/Dockerfile index e69de29bb..00c9a5244 100644 --- a/build/docker/openim-crontask/Dockerfile +++ b/build/docker/openim-crontask/Dockerfile @@ -0,0 +1,44 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-crontask + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-crontask"] diff --git a/build/docker/openim-msggateway/Dockerfile b/build/docker/openim-msggateway/Dockerfile index e69de29bb..1c353b9e5 100644 --- a/build/docker/openim-msggateway/Dockerfile +++ b/build/docker/openim-msggateway/Dockerfile @@ -0,0 +1,50 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-msggateway + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +ENV OS ${OS} +ENV ARCH ${ARCH} + +EXPOSE 10140 +EXPOSE 10001 + +CMD ${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-msggateway --port 10140 --ws_port 10001 \ No newline at end of file diff --git a/build/docker/openim-msgtransfer/Dockerfile b/build/docker/openim-msgtransfer/Dockerfile index e69de29bb..0db1377c1 100644 --- a/build/docker/openim-msgtransfer/Dockerfile +++ b/build/docker/openim-msgtransfer/Dockerfile @@ -0,0 +1,47 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-msgtransfer + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +ENV OS ${OS} +ENV ARCH ${ARCH} + +WORKDIR /openim/openim-server + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +CMD ${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-msgtransfer \ No newline at end of file diff --git a/build/docker/openim-push/Dockerfile b/build/docker/openim-push/Dockerfile index e69de29bb..c1824b185 100644 --- a/build/docker/openim-push/Dockerfile +++ b/build/docker/openim-push/Dockerfile @@ -0,0 +1,49 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean +RUN make build BINS=openim-push + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10170 + +CMD ${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-push --port 10170 \ No newline at end of file diff --git a/build/docker/openim-rpc-auth/Dockerfile b/build/docker/openim-rpc-auth/Dockerfile index e69de29bb..87c30e559 100644 --- a/build/docker/openim-rpc-auth/Dockerfile +++ b/build/docker/openim-rpc-auth/Dockerfile @@ -0,0 +1,52 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +# RUN make build BINS=openim-rpc + +RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth ./cmd/openim-rpc/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10160 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-auth --port 10160 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-conversation/Dockerfile b/build/docker/openim-rpc-conversation/Dockerfile index e69de29bb..2e6b76996 100644 --- a/build/docker/openim-rpc-conversation/Dockerfile +++ b/build/docker/openim-rpc-conversation/Dockerfile @@ -0,0 +1,59 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation ./cmd/openim-rpc/openim-rpc-conversation + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10230 +EXPOSE 20230 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-conversation --port 10230 --prometheus_port 20230 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-friend/Dockerfile b/build/docker/openim-rpc-friend/Dockerfile index e69de29bb..47e44b104 100644 --- a/build/docker/openim-rpc-friend/Dockerfile +++ b/build/docker/openim-rpc-friend/Dockerfile @@ -0,0 +1,59 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend ./cmd/openim-rpc/openim-rpc-friend + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10120 +EXPOSE 20120 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-friend --port 10120 --prometheus_port 20120 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-group/Dockerfile b/build/docker/openim-rpc-group/Dockerfile index e69de29bb..70facaae2 100644 --- a/build/docker/openim-rpc-group/Dockerfile +++ b/build/docker/openim-rpc-group/Dockerfile @@ -0,0 +1,59 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group ./cmd/openim-rpc/openim-rpc-group + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10150 +EXPOSE 20150 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-group --port 10150 --prometheus_port 20150 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-msg/Dockerfile b/build/docker/openim-rpc-msg/Dockerfile index e69de29bb..664d0cdce 100644 --- a/build/docker/openim-rpc-msg/Dockerfile +++ b/build/docker/openim-rpc-msg/Dockerfile @@ -0,0 +1,59 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg ./cmd/openim-rpc/openim-rpc-msg + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10130 +EXPOSE 20130 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-msg --port 10130 --prometheus_port 20130 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-third/Dockerfile b/build/docker/openim-rpc-third/Dockerfile index e69de29bb..20e9102eb 100644 --- a/build/docker/openim-rpc-third/Dockerfile +++ b/build/docker/openim-rpc-third/Dockerfile @@ -0,0 +1,58 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third ./cmd/openim-rpc/openim-rpc-third + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10200 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-third --port 10200 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/build/docker/openim-rpc-user/Dockerfile b/build/docker/openim-rpc-user/Dockerfile index e69de29bb..86e53b1b6 100644 --- a/build/docker/openim-rpc-user/Dockerfile +++ b/build/docker/openim-rpc-user/Dockerfile @@ -0,0 +1,58 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# OpenIM base image: https://github.com/openim-sigs/openim-base-image + +# Set go mod installation source and proxy + +FROM golang:1.20 AS builder + +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct + +WORKDIR /openim/openim-server + +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make clean + +RUN make build BINS=openim-rpc +# RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-user ./cmd/openim-rpc/openim-rpc-user + +RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-friend && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-group && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-msg && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-third && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-conversation && \ + rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-rpc-auth + +FROM ghcr.io/openim-sigs/openim-bash-image:latest + +WORKDIR /openim/openim-server + +ENV OS ${OS} +ENV ARCH ${ARCH} + +COPY --from=builder /openim/openim-server/_output/bin/platforms /openim/openim-server/_output/bin/platforms/ +COPY --from=builder /openim/openim-server/config /openim/openim-server/config + +EXPOSE 10110 + +CMD ["bash", "-c","${OPENIM_SERVER_BINDIR}/platforms/${OS}/${ARCH}/openim-rpc-user --port 10110 -c ${SERVER_WORKDIR}/config"] \ No newline at end of file diff --git a/cmd/openim-api/Makefile b/cmd/openim-api/Makefile deleted file mode 100644 index b72c6c717..000000000 --- a/cmd/openim-api/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-api -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-api/deploy.Dockerfile b/cmd/openim-api/deploy.Dockerfile index 3479e0cd3..56dd4a106 100644 --- a/cmd/openim-api/deploy.Dockerfile +++ b/cmd/openim-api/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-api ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-api","--port", "10002"] diff --git a/cmd/openim-api/main.go b/cmd/openim-api/main.go index 8350f4d05..d3b70af90 100644 --- a/cmd/openim-api/main.go +++ b/cmd/openim-api/main.go @@ -26,14 +26,15 @@ import ( _ "net/http/pprof" - "github.com/OpenIMSDK/Open-IM-Server/internal/api" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/cmd" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/discoveryregistry" openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/internal/api" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/cmd" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" ) func main() { diff --git a/cmd/openim-cmdutils/Makefile b/cmd/openim-cmdutils/Makefile deleted file mode 100644 index e78ac33f6..000000000 --- a/cmd/openim-cmdutils/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-cmdutils -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-crontask/Makefile b/cmd/openim-crontask/Makefile deleted file mode 100644 index 58528ccb5..000000000 --- a/cmd/openim-crontask/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-crontask -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-crontask/deploy.Dockerfile b/cmd/openim-crontask/deploy.Dockerfile index ba5230c42..9ada56d26 100644 --- a/cmd/openim-crontask/deploy.Dockerfile +++ b/cmd/openim-crontask/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-crontask ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-crontask"] diff --git a/cmd/openim-crontask/main.go b/cmd/openim-crontask/main.go index 73deb8c66..6fbb0558a 100644 --- a/cmd/openim-crontask/main.go +++ b/cmd/openim-crontask/main.go @@ -21,7 +21,7 @@ import ( func main() { cronTaskCmd := cmd.NewCronTaskCmd() - if err := cronTaskCmd.Exec(tools.StartCronTask); err != nil { + if err := cronTaskCmd.Exec(tools.StartTask); err != nil { panic(err.Error()) } } diff --git a/cmd/openim-msggateway/Makefile b/cmd/openim-msggateway/Makefile deleted file mode 100644 index d5238beae..000000000 --- a/cmd/openim-msggateway/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-msg_gateway -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-msggateway/deploy.Dockerfile b/cmd/openim-msggateway/deploy.Dockerfile index 7ba0d2235..31a30ff4b 100644 --- a/cmd/openim-msggateway/deploy.Dockerfile +++ b/cmd/openim-msggateway/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-msg_gateway ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-msg_gateway","--port", "10140" "--ws_port", "10001", "--prometheus_port", "20240"] diff --git a/cmd/openim-msgtransfer/Makefile b/cmd/openim-msgtransfer/Makefile deleted file mode 100644 index e2d058f6d..000000000 --- a/cmd/openim-msgtransfer/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-msgtransfer -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-msgtransfer/deploy.Dockerfile b/cmd/openim-msgtransfer/deploy.Dockerfile index 78f1f955c..7eedcbdbc 100644 --- a/cmd/openim-msgtransfer/deploy.Dockerfile +++ b/cmd/openim-msgtransfer/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-msgtransfer ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-msgtransfer","--prometheus_port", "21400"] diff --git a/cmd/openim-push/Makefile b/cmd/openim-push/Makefile deleted file mode 100644 index b417faecf..000000000 --- a/cmd/openim-push/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-push -BIN_DIR=../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-push/deploy.Dockerfile b/cmd/openim-push/deploy.Dockerfile index 67774a6f7..6e4e44525 100644 --- a/cmd/openim-push/deploy.Dockerfile +++ b/cmd/openim-push/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-push ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-push", "--port", "10170", "--prometheus_port", "20170"] diff --git a/cmd/openim-rpc/openim-rpc-auth/Makefile b/cmd/openim-rpc/openim-rpc-auth/Makefile deleted file mode 100644 index 068d50fd8..000000000 --- a/cmd/openim-rpc/openim-rpc-auth/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-auth -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile index b529860f9..6d034303c 100644 --- a/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-auth/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-auth ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-auth", "--port", "10160"] diff --git a/cmd/openim-rpc/openim-rpc-conversation/Makefile b/cmd/openim-rpc/openim-rpc-conversation/Makefile deleted file mode 100644 index 4c9726011..000000000 --- a/cmd/openim-rpc/openim-rpc-conversation/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-conversation -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile index 33e5c93c1..8245e3ca1 100644 --- a/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-conversation/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-conversation ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-conversation", "--port", "10230", "--prometheus_port","20230"] diff --git a/cmd/openim-rpc/openim-rpc-friend/Makefile b/cmd/openim-rpc/openim-rpc-friend/Makefile deleted file mode 100644 index e0068e97d..000000000 --- a/cmd/openim-rpc/openim-rpc-friend/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-friend -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile index f306a7938..5f842a631 100644 --- a/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-friend/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-friend ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-friend", "--port", "10120", "--prometheus_port","20120"] diff --git a/cmd/openim-rpc/openim-rpc-group/Makefile b/cmd/openim-rpc/openim-rpc-group/Makefile deleted file mode 100644 index 8ba79043d..000000000 --- a/cmd/openim-rpc/openim-rpc-group/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-group -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile index ed46edcf7..42fe164df 100644 --- a/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-group/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-group ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-group", "--port", "10150", "--prometheus_port","20150"] diff --git a/cmd/openim-rpc/openim-rpc-msg/Makefile b/cmd/openim-rpc/openim-rpc-msg/Makefile deleted file mode 100644 index 872fbfbba..000000000 --- a/cmd/openim-rpc/openim-rpc-msg/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-msg -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile index 61737417e..754d782a0 100644 --- a/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-msg/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-msg ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-msg", "--port", "10130", "--prometheus_port","20130"] diff --git a/cmd/openim-rpc/openim-rpc-third/Makefile b/cmd/openim-rpc/openim-rpc-third/Makefile deleted file mode 100644 index 28059b2c4..000000000 --- a/cmd/openim-rpc/openim-rpc-third/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-third -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile index 29bc2d068..664ad452c 100644 --- a/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-third/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-third ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-third", "--port", "10200"] diff --git a/cmd/openim-rpc/openim-rpc-user/Makefile b/cmd/openim-rpc/openim-rpc-user/Makefile deleted file mode 100644 index 1a7eed913..000000000 --- a/cmd/openim-rpc/openim-rpc-user/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.PHONY: all build run gotool install clean help - -NAME=openim-rpc-user -BIN_DIR=../../../bin/ - -OS:= $(or $(os),linux) -ARCH:=$(or $(arch),amd64) -all: gotool build - -ifeq ($(OS),windows) - -BINARY_NAME=${NAME}.exe - -else - -BINARY_NAME=${NAME} - -endif - -build: - CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH}; go build -ldflags="-w -s" -o ${BINARY_NAME} - -run: - @go run ./ - -gotool: - go fmt ./ - go vet ./ - -install:build - mv ${BINARY_NAME} ${BIN_DIR} - -clean: - @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi diff --git a/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile b/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile index 8ab7df1e7..f9663c9ba 100644 --- a/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile +++ b/cmd/openim-rpc/openim-rpc-user/deploy.Dockerfile @@ -14,7 +14,7 @@ FROM ubuntu -WORKDIR /Open-IM-Server/bin +WORKDIR /openim/openim-server/bin RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ &&apt-get install net-tools @@ -27,6 +27,6 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl COPY ./openim-rpc-user ./ -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config"] +VOLUME ["/openim/openim-server/logs","/openim/openim-server/config"] CMD ["./openim-rpc-user", "--port", "10110"] diff --git a/config/config.yaml b/config/config.yaml index 348aa2e93..035577b3d 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -24,10 +24,10 @@ # Zookeeper username # Zookeeper password zookeeper: - schema: openim - address: [ 127.0.0.1:2181 ] - username: - password: + schema: openim + address: [ 127.0.0.1:2181 ] + username: + password: ###################### Mysql ###################### # MySQL configuration @@ -42,12 +42,12 @@ mysql: address: [ 127.0.0.1:13306 ] username: root password: openIM123 - database: openIM_v3 - maxOpenConn: 1000 - maxIdleConn: 100 - maxLifeTime: 60 - logLevel: 4 - slowThreshold: 500 + database: openIM_v3 + maxOpenConn: 1000 + maxIdleConn: 100 + maxLifeTime: 60 + logLevel: 4 + slowThreshold: 500 ###################### Mongo ###################### # MongoDB configuration @@ -62,7 +62,7 @@ mongo: database: openIM_v3 username: root password: openIM123 - maxPoolSize: 100 + maxPoolSize: 100 ###################### Redis ###################### # Redis configuration @@ -70,7 +70,7 @@ mongo: # Username is required only for Redis version 6.0+ redis: address: [ 127.0.0.1:16379 ] - username: + username: password: openIM123 ###################### Kafka ###################### @@ -81,13 +81,13 @@ redis: # It's not recommended to modify this topic name # Consumer group ID, it's not recommended to modify kafka: - username: - password: + username: + password: addr: [ 127.0.0.1:9092 ] latestMsgToRedis: - topic: "latestMsgToRedis" + topic: "latestMsgToRedis" offlineMsgToMongo: - topic: "offlineMsgToMongoMysql" + topic: "offlineMsgToMongoMysql" msgToPush: topic: "msgToPush" consumerGroupID: @@ -111,8 +111,8 @@ rpc: # API service port # Default listen IP is 0.0.0.0 api: - openImApiPort: [ 10002 ] - listenIP: 0.0.0.0 + openImApiPort: [ 10002 ] + listenIP: 0.0.0.0 ###################### Gateway ###################### # Object storage configuration @@ -124,25 +124,29 @@ api: # Session token # Configuration for Tencent COS # Configuration for Aliyun OSS +# apiURL is the address of the api, the access address of the app, use s3 must be configured +# minio.endpoint can be configured as an intranet address, +# minio.signEndpoint is minio public network address object: - enable: "minio" - apiURL: http://127.0.0.1:10002/object/ + enable: "minio" + apiURL: "http://127.0.0.1:10002" minio: - bucket: "openim" - endpoint: http://127.0.0.1:10005 - accessKeyID: root - secretAccessKey: openIM123 - sessionToken: "" - cos: + bucket: "openim" + endpoint: "http://127.0.0.1:10005" + accessKeyID: "root" + secretAccessKey: "openIM123" + sessionToken: "" + signEndpoint: "http://127.0.0.1:10005" + cos: bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" secretID: "" secretKey: "" sessionToken: "" - oss: + oss: endpoint: "https://oss-cn-chengdu.aliyuncs.com" bucket: "demo-9999999" bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" - accessKeyID: root + accessKeyID: "" accessKeySecret: "" sessionToken: "" @@ -150,7 +154,7 @@ object: # These ports are passed into the program by the script and are not recommended to modify # For launching multiple programs, just fill in multiple ports separated by commas # For example, [10110, 10111] -rpcPort: +rpcPort: openImUserPort: [ 10110 ] openImFriendPort: [ 10120 ] openImMessagePort: [ 10130 ] @@ -183,12 +187,12 @@ rpcRegisterName: # Whether to output in json format # Whether to include stack trace in logs log: - storageLocation: ../../../../../logs/ - rotationTime: 24 - remainRotationCount: 2 - remainLogLevel: 6 - isStdout: false - isJson: false + storageLocation: ../../../../../logs/ + rotationTime: 24 + remainRotationCount: 2 + remainLogLevel: 6 + isStdout: false + isJson: false withStack: false # Long connection server configuration @@ -198,10 +202,10 @@ log: # Maximum length of websocket request package # Websocket connection handshake timeout longConnSvr: - openImWsPort: [ 10001 ] - websocketMaxConnNum: 100000 - websocketMaxMsgLen: 4096 - websocketTimeout: 10 + openImWsPort: [ 10001 ] + websocketMaxConnNum: 100000 + websocketMaxMsgLen: 4096 + websocketTimeout: 10 # Push notification service configuration # diff --git a/config/open-im-ng-example.conf b/config/open-im-ng-example.conf index a817f7357..10a2ecb52 100644 --- a/config/open-im-ng-example.conf +++ b/config/open-im-ng-example.conf @@ -1,41 +1,37 @@ upstream im_msg_gateway{ - server 127.0.0.1:10001; #IM消息服务器地址 根据部署情况可指定多台 + server 127.0.0.1:10001; #IM Message server address Multiple can be specified according to the deployment } upstream im_api{ - server 127.0.0.1:10002; #IM群组用户api服务器地址 根据部署情况可指定多台 - } -upstream im_jssdk_gateway{ - server 127.0.0.1:10003; #IM jssdk服务器地址 根据部署情况可指定多台 - } -upstream storage { - server 127.0.0.1:10005; #MinIO服务器地址 暂时支持1台 - } -upstream im_admin{ - server 127.0.0.1:10006; #IM admin服务器地址 根据部署情况可指定多台 + server 127.0.0.1:10002; #IM Group user api server address Multiple can be specified according to the deployment } upstream im_grafana{ - server 127.0.0.1:10007; #IM 统计服务器地址 docker-compose启动所在机器 - } -upstream im_chat{ - server 127.0.0.1:10008; #IM 商业版登录注册服务器地址 根据部署情况可指定多台 + server 127.0.0.1:10007; #IM Statistical server address The machine where docker-compose starts } -upstream im_complete_admin{ - server 127.0.0.1:10009; #IM 商业版admin地址 根据部署情况可指定多台 +upstream im_chat_api{ + server 127.0.0.1:10008; #IM Business version login registration server address Multiple can be specified according to the deployment } -upstream im_organization{ - server 127.0.0.1:10010; #IM 商业版组织架构服务器地址 根据部署情况可指定多台 +upstream im_admin_api{ + server 127.0.0.1:10009; #IM The admin address of the commercial version can specify multiple units according to the deployment situation } upstream im_open_rtc{ - server 127.0.0.1:7880; #rtc 音视频通话 服务器地址 根据部署情况可指定多台 + server 127.0.0.1:7880; #rtc Audio and video call server address Multiple devices can be specified according to the deployment } +upstream minio_s3_2 { + least_conn; + server 127.0.0.1:10005; +} +upstream minio_console_2 { + least_conn; + server 127.0.0.1:9090; +} server { listen 443; - server_name web.rentsoft.cn; #1 web im 端 域名 + server_name your-domain.com; #your-domain.com ssl on; - ssl_certificate /etc/nginx/conf.d/ssl/web.rentsoft.cn.crt; #2 证书 - ssl_certificate_key /etc/nginx/conf.d/ssl/web.rentsoft.cn.key; #3 证书 + ssl_certificate /etc/nginx/conf.d/ssl/your-domain.com.crt; #2 Certificate + ssl_certificate_key /etc/nginx/conf.d/ssl/your-domain.com.key; #3 Certificate ssl_session_timeout 5m; gzip on; gzip_min_length 1k; @@ -52,7 +48,7 @@ server { proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-NginX-Proxy true; - root /data1/online/Pc-Web-Demo/build/; # web im静态资源存放路径 + root /data1/online/Pc-Web-Demo/build/; # web im static resource storage path index index.html; try_files $uri $uri/ /index.html; } @@ -72,22 +68,6 @@ server { proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://im_api/; } - location /jssdk_gateway { #10003 jssdk - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-real-ip $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass http://im_jssdk_gateway/; - } - location ^~/admin/ { #10006 admin - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-real-ip $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass http://im_admin/; - } location ^~/grafana/ { #10007 prometheus proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; @@ -96,29 +76,21 @@ server { proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://im_grafana/; } - location ^~/chat/ { #10008 chat login - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-real-ip $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass http://im_chat/; - } + location ^~/chat/ { #10008 im_chat_api + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header X-real-ip $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass http://im_chat_api/; + } location ^~/complete_admin/ { #10009 admin proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass http://im_complete_admin/; - } - location ^~/organization/ { #10010 organization - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-real-ip $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_pass http://im_organization/; + proxy_pass http://im_admin_api/; } location ^~/open_rtc/ { #7880 rtc proxy_http_version 1.1; @@ -132,63 +104,69 @@ server { server { listen 80; - server_name web.rentsoft.cn ; #1 web im 端 域名 + server_name test-web.rentsoft.cn ; #1 web im end domain name rewrite ^(.*)$ https://${server_name}$1 permanent; } + server { - ssl_session_timeout 5m; - listen 443; - server_name storage.rentsoft.cn; #1 MinIO存储域名 - ssl on; - ssl_certificate /etc/nginx/conf.d/ssl/storage.rentsoft.cn.crt; #证书 - ssl_certificate_key /etc/nginx/conf.d/ssl/storage.rentsoft.cn.key; #证书 - gzip on; - gzip_min_length 1k; - gzip_buffers 4 16k; - gzip_comp_level 2; - gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; - gzip_vary off; - gzip_disable "MSIE [1-6]\."; + listen 443; + + server_name your-domain.com; #your-domain.com + ssl on; + ssl_certificate /etc/nginx/conf.d/ssl/your-domain.com.crt; #Certificate + ssl_certificate_key /etc/nginx/conf.d/ssl/your-domain.com.key; #Certificate + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_comp_level 2; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm; + gzip_vary off; + gzip_disable "MSIE [1-6]\."; + # Allow special characters in headers + ignore_invalid_headers off; + # Allow any size file to be uploaded. + # Set to a value such as 1000m; to restrict file size to a specific value + client_max_body_size 0; + # Disable buffering + proxy_buffering off; + proxy_request_buffering off; + location / { - proxy_pass http://storage; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header Host $http_host; - proxy_http_version 1.1; - client_max_body_size 8000M; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_connect_timeout 300; + # Default is HTTP/1, keepalive is only enabled in HTTP/1.1 + proxy_http_version 1.1; + proxy_set_header Connection ""; + chunked_transfer_encoding off; + + proxy_pass http://minio_s3_2; # This uses the upstream directive definition to load balance } -} + location /minio/ui { + rewrite ^/minio/ui/(.*) /$1 break; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-NginX-Proxy true; -server { - listen 443; - server_name admin.rentsoft.cn; #后台管理域名 - ssl on; - ssl_certificate /etc/nginx/conf.d/ssl/admin.rentsoft.cn.crt; # 证书 - ssl_certificate_key /etc/nginx/conf.d/ssl/admin.rentsoft.cn.key; #证书 - ssl_session_timeout 5m; - gzip on; - gzip_min_length 1k; - gzip_buffers 4 16k; - gzip_comp_level 2; - gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; - gzip_vary off; - gzip_disable "MSIE [1-6]\."; - location / { - proxy_set_header Host $host; - proxy_set_header X-Real-Ip $remote_addr; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-NginX-Proxy true; - root /data1/online/Open-IM-Admin/dist/; #管理后台web静态资源存放路径 - index index.html; - try_files $uri $uri/ /index.html; - } -} + # This is necessary to pass the correct IP to be hashed + real_ip_header X-Real-IP; -server { - listen 80; - server_name admin.rentsoft.cn; #管理后台 域名 - rewrite ^(.*)$ https://${server_name}$1 permanent; + proxy_connect_timeout 300; + + # To support websockets in MinIO versions released after January 2023 + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + chunked_transfer_encoding off; + + proxy_pass http://minio_console_2; # This uses the upstream directive definition to load balance + } } diff --git a/deployments/README.md b/deployments/README.md index 9c3cff05e..602371fb0 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -2,6 +2,17 @@ OpenIM 支持很多种集群化部署方式,包括但不限于 helm, sealos, kubeam, kubesphere, kubeflow, kuboard, kubespray, k3s, k3d, k3c, k3sup, k3v, k3x +**目前还在开发这个模块,预计 v3.2.0 之前会有一个集群方案。** + +目前各个贡献者,以及之前的官方有出过一些可以参考的方案: + +- https://github.com/OpenIMSDK/k8s-jenkins +- https://github.com/OpenIMSDK/Open-IM-Server-k8s-deploy +- https://github.com/OpenIMSDK/openim-charts +- https://github.com/showurl/deploy-openim + + + ### 依赖检查 ```bash @@ -23,4 +34,4 @@ $ cd ${OpenIM_ROOT} -### Helm安装 \ No newline at end of file +### Helm安装 diff --git a/docker-compose.yaml b/docker-compose.yaml index dd391b828..d71d4c932 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -52,7 +52,6 @@ services: net.core.somaxconn: 1024 command: redis-server --requirepass ${PASSWORD} --appendonly yes - zookeeper: image: wurstmeister/zookeeper ports: @@ -65,7 +64,6 @@ services: restart: always network_mode: "host" - kafka: image: wurstmeister/kafka container_name: kafka @@ -100,16 +98,13 @@ services: restart: always command: minio server /data --console-address ':9090' - - openim_server: + openim-server: image: ghcr.io/openimsdk/openim-server:latest container_name: openim-server volumes: - - ./logs:/Open-IM-Server/logs - - ./config/config.yaml:/Open-IM-Server/config/config.yaml - - ./config/notification.yaml:/Open-IM-Server/config/notification.yaml - - ${DATA_DIR}/db/sdk:/Open-IM-Server/db/sdk - - ./scripts:/Open-IM-Server/scripts + - ./logs:/openim/openim-server/logs + - ./config:/openim/openim-server/config + - ./scripts:/openim/openim-server/scripts restart: always depends_on: - zookeeper @@ -125,16 +120,20 @@ services: max-size: "1g" max-file: "2" - openim_chat: + openim-chat: image: ghcr.io/openimsdk/openim-chat:latest - container_name: openim_chat + container_name: openim-chat + volumes: + - ./_output/openim/openim-chat/logs:/openim/openim-chat/logs + - ./_output/openim/openim-chat/config:/openim/openim-chat/config + - ./_output/openim/openim-chat/scripts:/openim/openim-chat/scripts restart: always depends_on: - mysql - mongodb - redis - minio - - openim_server + - openim-server network_mode: "host" logging: driver: json-file @@ -150,7 +149,7 @@ services: # ports: # - 9091:9091 depends_on: - - openim_server + - openim-server command: --web.listen-address=:9091 --config.file="/etc/prometheus/prometheus.yml" network_mode: "host" diff --git a/docs/.generated_docs b/docs/.generated_docs index 4145ed52c..9e26979b4 100644 --- a/docs/.generated_docs +++ b/docs/.generated_docs @@ -1,8 +1,5 @@ docs/.generated_docs -docs/guide/en-US/cmd/iam-apiserver.md -docs/guide/en-US/cmd/iam-authz-server.md -docs/guide/en-US/cmd/iam-pump.md -docs/guide/en-US/cmd/iam-watcher.md + docs/guide/en-US/cmd/openim/openim.md docs/guide/en-US/cmd/openim/openim_color.md docs/guide/en-US/cmd/openim/openim_completion.md diff --git a/docs/conversions/go_code.md b/docs/conversions/go_code.md index 85d099f9c..6e1adf06d 100644 --- a/docs/conversions/go_code.md +++ b/docs/conversions/go_code.md @@ -1,66 +1,62 @@ -## Go 代码开发规范 -在Go 项目开发中,一个好的编码规范可以极大的提高代码质量。为了帮你节省时间和精力,这里我整理了一份清晰、可直接套用的 Go 编码规范,供你参考。 +## OpenIM development specification +We have very high standards for code style and specification, and we want our products to be polished and perfect -这份规范,是我参考了 Go 官方提供的编码规范,以及 Go 社区沉淀的一些比较合理的规范之后,加入自己的理解总结出的,它比很多公司内部的规范更全面,你掌握了,以后在面试大厂的时候,或者在大厂里写代码的时候,都会让人高看你一眼,觉得你code很专业。 +## 1. Code style -这份编码规范中包含代码风格、命名规范、注释规范、类型、控制结构、函数、GOPATH 设置规范、依赖管理和最佳实践九类规范。如果你觉得这些规范内容太多了,看完一遍也记不住,这完全没关系。你可以多看几遍,也可以在用到时把它翻出来,在实际应用中掌握。这篇特别放送的内容,更多是作为写代码时候的一个参考手册。 +### 1.1 Code format -## 1. 代码风格 - -### 1.1 代码格式 - -- 代码都必须用 `gofmt` 进行格式化。 -- 运算符和操作数之间要留空格。 -- 建议一行代码不超过120个字符,超过部分,请采用合适的换行方式换行。但也有些例外场景,例如import行、工具自动生成的代码、带tag的struct字段。 -- 文件长度不能超过800行。 -- 函数长度不能超过80行。 -- import规范 - - 代码都必须用`goimports`进行格式化(建议将代码Go代码编辑器设置为:保存时运行 `goimports`)。 - - 不要使用相对路径引入包,例如 `import ../util/net` 。 - - 包名称与导入路径的最后一个目录名不匹配时,或者多个相同包名冲突时,则必须使用导入别名。 +- Code must be formatted with `gofmt`. +- Leave spaces between operators and operands. +- It is recommended that a line of code does not exceed 120 characters. If the part exceeds, please use an appropriate line break method. But there are also some exception scenarios, such as import lines, code automatically generated by tools, and struct fields with tags. +- The file length cannot exceed 800 lines. +- Function length cannot exceed 80 lines. +- import specification +- All code must be formatted with `goimports` (it is recommended to set the code Go code editor to: run `goimports` on save). +- Do not use relative paths to import packages, such as `import ../util/net`. +- Import aliases must be used when the package name does not match the last directory name of the import path, or when multiple identical package names conflict. ```go - // bad - "github.com/dgrijalva/jwt-go/v4" +// bad +"github.com/dgrijalva/jwt-go/v4" - //good - jwt "github.com/dgrijalva/jwt-go/v4" +//good +jwt "github.com/dgrijalva/jwt-go/v4" ``` - - 导入的包建议进行分组,匿名包的引用使用一个新的分组,并对匿名包引用进行说明。 +- Imported packages are suggested to be grouped, and anonymous package references use a new group, and anonymous package references are explained. ```go - import ( - // go 标准包 - "fmt" - - // 第三方包 - "github.com/jinzhu/gorm" - "github.com/spf13/cobra" - "github.com/spf13/viper" - - // 匿名包单独分组,并对匿名包引用进行说明 - // import mysql driver - _ "github.com/jinzhu/gorm/dialects/mysql" - - // 内部包 - v1 "github.com/marmotedu/api/apiserver/v1" - metav1 "github.com/marmotedu/apimachinery/pkg/meta/v1" - "github.com/marmotedu/iam/pkg/cli/genericclioptions" - ) +import ( +// go standard package +"fmt" + +// third party package +"github.com/jinzhu/gorm" +"github.com/spf13/cobra" +"github.com/spf13/viper" + +// Anonymous packages are grouped separately, and anonymous package references are explained +// import mysql driver +_ "github.com/jinzhu/gorm/dialects/mysql" + +// inner package +v1 "github.com/marmotedu/api/apiserver/v1" +metav1 "github.com/marmotedu/apimachinery/pkg/meta/v1" +"github.com/marmotedu/iam/pkg/cli/genericclioptions" +) ``` -### 1.2 声明、初始化和定义 +### 1.2 Declaration, initialization and definition -当函数中需要使用到多个变量时,可以在函数开始处使用`var`声明。在函数外部声明必须使用 `var` ,不要采用 `:=` ,容易踩到变量的作用域的问题。 +When multiple variables need to be used in a function, the `var` declaration can be used at the beginning of the function. Declaration outside the function must use `var`, do not use `:=`, it is easy to step on the scope of the variable. ```go var ( - Width int - Height int +Width int +Height int ) ``` -- 在初始化结构引用时,请使用`&T{}`代替`new(T)`,以使其与结构体初始化一致。 +- When initializing a structure reference, please use `&T{}` instead of `new(T)` to make it consistent with structure initialization. ```go // bad @@ -71,371 +67,371 @@ sptr.Name = "bar" sptr := &T{Name: "bar"} ``` -- struct 声明和初始化格式采用多行,定义如下。 +- The struct declaration and initialization format takes multiple lines and is defined as follows. ```go type User struct{ - Username string - Email string + Username string + Email string } user := User{ - Username: "belm", - Email: "nosbelm@qq.com", +Username: "belm", +Email: "nosbelm@qq.com", } ``` -- 相似的声明放在一组,同样适用于常量、变量和类型声明。 +- Similar declarations are grouped together, and the same applies to constant, variable, and type declarations. ```go // bad import "a" import "b" -// good +//good import ( - "a" - "b" + "a" + "b" ) ``` -- 尽可能指定容器容量,以便为容器预先分配内存,例如: +- Specify container capacity where possible to pre-allocate memory for the container, for example: ```go v := make(map[int]string, 4) v := make([]string, 0, 4) ``` -- 在顶层,使用标准var关键字。请勿指定类型,除非它与表达式的类型不同。 +- At the top level, use the standard var keyword. Do not specify a type unless it is different from the type of the expression. ```go // bad -var _s string = F() +var_s string = F() func F() string { return "A" } // good -var _s = F() -// 由于 F 已经明确了返回一个字符串类型,因此我们没有必要显式指定_s 的类型 -// 还是那种类型 +var_s = F() +// Since F already explicitly returns a string type, we don't need to explicitly specify the type of _s +// still of that type func F() string { return "A" } ``` -- 对于未导出的顶层常量和变量,使用`_`作为前缀。 +- Use `_` as a prefix for unexported top-level constants and variables. ```go // bad const ( - defaultHost = "127.0.0.1" - defaultPort = 8080 + defaultHost = "127.0.0.1" + defaultPort = 8080 ) // good const ( - _defaultHost = "127.0.0.1" - _defaultPort = 8080 + _defaultHost = "127.0.0.1" + _defaultPort = 8080 ) ``` -- 嵌入式类型(例如 mutex)应位于结构体内的字段列表的顶部,并且必须有一个空行将嵌入式字段与常规字段分隔开。 +- Embedded types (such as mutexes) should be at the top of the field list within the struct, and there must be a blank line separating embedded fields from regular fields. ```go // bad type Client struct { - version int - http.Client + version int + http.Client } -// good +//good type Client struct { - http.Client + http.Client - version int + version int } ``` -### 1.3 错误处理 +### 1.3 Error Handling -- `error`作为函数的值返回,必须对`error`进行处理,或将返回值赋值给明确忽略。对于`defer xx.Close()`可以不用显式处理。 +- `error` is returned as the value of the function, `error` must be handled, or the return value assigned to explicitly ignore. For `defer xx.Close()`, there is no need to explicitly handle it. ```go func load() error { - // normal code +// normal code } // bad load() -// good - _ = load() +//good + _ = load() ``` -- `error`作为函数的值返回且有多个返回值的时候,`error`必须是最后一个参数。 +- When `error` is returned as the value of a function and there are multiple return values, `error` must be the last parameter. ```go // bad func load() (error, int) { - // normal code +// normal code } -// good +//good func load() (int, error) { - // normal code +// normal code } ``` -- 尽早进行错误处理,并尽早返回,减少嵌套。 +- Perform error handling as early as possible and return as early as possible to reduce nesting. ```go // bad if err != nil { - // error code +// error code } else { - // normal code +// normal code } -// good +//good if err != nil { - // error handling - return err +// error handling +return err } // normal code ``` -- 如果需要在 if 之外使用函数调用的结果,则应采用下面的方式。 +- If you need to use the result of the function call outside if, you should use the following method. ```go // bad if v, err := foo(); err != nil { - // error handling +// error handling } // good v, err := foo() if err != nil { - // error handling +// error handling } ``` -- 错误要单独判断,不与其他逻辑组合判断。 +- Errors should be judged independently, not combined with other logic. ```go // bad v, err := foo() -if err != nil || v == nil { - // error handling - return err +if err != nil || v == nil { +// error handling +return err } -// good +//good v, err := foo() if err != nil { - // error handling - return err +// error handling +return err } if v == nil { - // error handling - return errors.New("invalid value v") +// error handling +return errors. New("invalid value v") } ``` -- 如果返回值需要初始化,则采用下面的方式。 +- If the return value needs to be initialized, use the following method. ```go v, err := f() if err != nil { - // error handling - return // or continue. + // error handling + return // or continue. } ``` -- 错误描述建议 - - 错误描述用小写字母开头,结尾不要加标点符号,例如: +- Bug description suggestions +- Error descriptions start with a lowercase letter and do not end with punctuation, for example: ```go - // bad - errors.New("Redis connection failed") - errors.New("redis connection failed.") +// bad +errors.New("Redis connection failed") +errors.New("redis connection failed.") - // good - errors.New("redis connection failed") +// good +errors.New("redis connection failed") ``` - - 告诉用户他们可以做什么,而不是告诉他们不能做什么。 - - 当声明一个需求时,用must 而不是should。例如,`must be greater than 0、must match regex '[a-z]+'`。 - - 当声明一个格式不对时,用must not。例如,`must not contain`。 - - 当声明一个动作时用may not。例如,`may not be specified when otherField is empty、only name may be specified`。 - - 引用文字字符串值时,请在单引号中指示文字。例如,`ust not contain '..'`。 - - 当引用另一个字段名称时,请在反引号中指定该名称。例如,must be greater than `request`。 - - 指定不等时,请使用单词而不是符号。例如,`must be less than 256、must be greater than or equal to 0 (不要用 larger than、bigger than、more than、higher than)`。 - - 指定数字范围时,请尽可能使用包含范围。 - - 建议 Go 1.13 以上,error 生成方式为 `fmt.Errorf("module xxx: %w", err)`。 +- Tell users what they can do, not what they can't. +- When declaring a requirement, use must instead of should. For example, `must be greater than 0, must match regex '[a-z]+'`. +- When declaring that a format is incorrect, use must not. For example, `must not contain`. +- Use may not when declaring an action. For example, `may not be specified when otherField is empty, only name may be specified`. +- When quoting a literal string value, indicate the literal in single quotes. For example, `ust not contain '..'`. +- When referencing another field name, specify that name in backticks. For example, must be greater than `request`. +- When specifying unequal, use words instead of symbols. For example, `must be less than 256, must be greater than or equal to 0 (do not use larger than, bigger than, more than, higher than)`. +- When specifying ranges of numbers, use inclusive ranges whenever possible. +- Go 1.13 or above is recommended, and the error generation method is `fmt.Errorf("module xxx: %w", err)`. -### 1.4 panic处理 +### 1.4 panic processing -- 在业务逻辑处理中禁止使用panic。 -- 在main包中,只有当程序完全不可运行时使用panic,例如无法打开文件、无法连接数据库导致程序无法正常运行。 -- 在main包中,使用 `log.Fatal` 来记录错误,这样就可以由log来结束程序,或者将panic抛出的异常记录到日志文件中,方便排查问题。 -- 可导出的接口一定不能有panic。 -- 包内建议采用error而不是panic来传递错误。 +- Panic is prohibited in business logic processing. +- In the main package, panic is only used when the program is completely inoperable, for example, the file cannot be opened, the database cannot be connected, and the program cannot run normally. +- In the main package, use `log.Fatal` to record errors, so that the program can be terminated by the log, or the exception thrown by the panic can be recorded in the log file, which is convenient for troubleshooting. +- An exportable interface must not panic. +- It is recommended to use error instead of panic to convey errors in the package. -### 1.5 单元测试 +### 1.5 Unit Tests -- 单元测试文件名命名规范为 `example_test.go`。 -- 每个重要的可导出函数都要编写测试用例。 -- 因为单元测试文件内的函数都是不对外的,所以可导出的结构体、函数等可以不带注释。 -- 如果存在 `func (b *Bar) Foo` ,单测函数可以为 `func TestBar_Foo`。 +- The unit test filename naming convention is `example_test.go`. +- Write a test case for every important exportable function. +- Because the functions in the unit test file are not external, the exportable structures, functions, etc. can be uncommented. +- If `func (b *Bar) Foo` exists, the single test function can be `func TestBar_Foo`. -### 1.6 类型断言失败处理 +### 1.6 Type assertion failure handling -- type assertion 的单个返回值针对不正确的类型将产生 panic。请始终使用 “comma ok”的惯用法。 +- A single return value from a type assertion will panic for an incorrect type. Always use the "comma ok" idiom. ```go // bad t := n.(int) -// good +//good t, ok := n.(int) if !ok { - // error handling +// error handling } ``` -## 2. 命名规范 +## 2. Naming convention -命名规范是代码规范中非常重要的一部分,一个统一的、短小的、精确的命名规范可以大大提高代码的可读性,也可以借此规避一些不必要的Bug。 +The naming convention is a very important part of the code specification. A uniform, short, and precise naming convention can greatly improve the readability of the code and avoid unnecessary bugs. -### 2.1 包命名 +### 2.1 Package Naming -- 包名必须和目录名一致,尽量采取有意义、简短的包名,不要和标准库冲突。 -- 包名全部小写,没有大写或下划线,使用多级目录来划分层级。 -- 项目名可以通过中划线来连接多个单词。 -- 包名以及包所在的目录名,不要使用复数,例如,是`net/url`,而不是`net/urls`。 -- 不要用 common、util、shared 或者 lib 这类宽泛的、无意义的包名。 -- 包名要简单明了,例如 net、time、log。 +- The package name must be consistent with the directory name, try to use a meaningful and short package name, and do not conflict with the standard library. +- Package names are all lowercase, without uppercase or underscores, and use multi-level directories to divide the hierarchy. +- Item names can connect multiple words with dashes. +- Do not use plurals for the package name and the directory name where the package is located, for example, `net/url` instead of `net/urls`. +- Don't use broad, meaningless package names like common, util, shared or lib. +- The package name should be simple and clear, such as net, time, log. -### 2.2 函数命名 +### 2.2 Function Naming -- 函数名采用驼峰式,首字母根据访问控制决定使用大写或小写,例如:`MixedCaps`或者`mixedCaps`。 -- 代码生成工具自动生成的代码(如`xxxx.pb.go`)和为了对相关测试用例进行分组,而采用的下划线(如`TestMyFunction_WhatIsBeingTested`)排除此规则。 +- The function name is in camel case, and the first letter is uppercase or lowercase according to the access control decision,For example: `MixedCaps` or `mixedCaps`. +- Code automatically generated by code generation tools (such as `xxxx.pb.go`) and underscores used to group related test cases (such as `TestMyFunction_WhatIsBeingTested`) exclude this rule. -### 2.3 文件命名 +### 2.3 File Naming -- 文件名要简短有意义。 -- 文件名应小写,并使用下划线分割单词。 +- Keep the filename short and meaningful. +- Filenames should be lowercase and use underscores to separate words. -### 2.4 结构体命名 +### 2.4 Structure Naming -- 采用驼峰命名方式,首字母根据访问控制决定使用大写或小写,例如`MixedCaps`或者`mixedCaps`。 -- 结构体名不应该是动词,应该是名词,比如 `Node`、`NodeSpec`。 -- 避免使用Data、Info这类无意义的结构体名。 -- 结构体的声明和初始化应采用多行,例如: +- The camel case is adopted, and the first letter is uppercase or lowercase according to the access control, such as `MixedCaps` or `mixedCaps`. +- Struct names should not be verbs, but should be nouns, such as `Node`, `NodeSpec`. +- Avoid using meaningless structure names such as Data and Info. +- The declaration and initialization of the structure should take multiple lines, for example: ```go -// User 多行声明 +// User multi-line declaration type User struct { - Name string - Email string + name string + Email string } -// 多行初始化 +// multi-line initialization u := User{ - UserName: "belm", - Email: "nosbelm@qq.com", + UserName: "belm", + Email: "nosbelm@qq.com", } ``` -### 2.5 接口命名 +### 2.5 Interface Naming -- 接口命名的规则,基本和结构体命名规则保持一致: - - 单个函数的接口名以 “er"”作为后缀(例如Reader,Writer),有时候可能导致蹩脚的英文,但是没关系。 - - 两个函数的接口名以两个函数名命名,例如ReadWriter。 - - 三个以上函数的接口名,类似于结构体名。 +- The interface naming rules are basically consistent with the structure naming rules: +- Interface names of individual functions suffixed with "er"" (e.g. Reader, Writer) can sometimes lead to broken English, but that's okay. +- The interface name of the two functions is named after the two function names, eg ReadWriter. +- An interface name for more than three functions, similar to a structure name. -例如: +For example: ``` - // Seeking to an offset before the start of the file is an error. - // Seeking to any positive offset is legal, but the behavior of subsequent - // I/O operations on the underlying object is implementation-dependent. - type Seeker interface { - Seek(offset int64, whence int) (int64, error) - } +// Seeking to an offset before the start of the file is an error. +// Seeking to any positive offset is legal, but the behavior of subsequent +// I/O operations on the underlying object are implementation-dependent. +type Seeker interface { +Seek(offset int64, whence int) (int64, error) +} - // ReadWriter is the interface that groups the basic Read and Write methods. - type ReadWriter interface { - Reader - Writer - } +// ReadWriter is the interface that groups the basic Read and Write methods. +type ReadWriter interface { +reader +Writer +} ``` -### 2.6 变量命名 +### 2.6 Variable Naming -- 变量名必须遵循驼峰式,首字母根据访问控制决定使用大写或小写。 -- 在相对简单(对象数量少、针对性强)的环境中,可以将一些名称由完整单词简写为单个字母,例如: - - user 可以简写为 u; - - userID 可以简写 uid。 -- 特有名词时,需要遵循以下规则: - - 如果变量为私有,且特有名词为首个单词,则使用小写,如 apiClient。 - - 其他情况都应当使用该名词原有的写法,如 APIClient、repoID、UserID。 +- Variable names must follow camel case, and the initial letter is uppercase or lowercase according to the access control decision. +- In relatively simple (few objects, highly targeted) environments, some names can be abbreviated from full words to single letters, for example: +- user can be abbreviated as u; +- userID can be abbreviated as uid. +- When using proper nouns, the following rules need to be followed: +- If the variable is private and the proper noun is the first word, use lowercase, such as apiClient. +- In other cases, the original wording of the noun should be used, such as APIClient, repoID, UserID. -下面列举了一些常见的特有名词。 +Some common nouns are listed below. ``` // A GonicMapper that contains a list of common initialisms taken from golang/lint var LintGonicMapper = GonicMapper{ - "API": true, - "ASCII": true, - "CPU": true, - "CSS": true, - "DNS": true, - "EOF": true, - "GUID": true, - "HTML": true, - "HTTP": true, - "HTTPS": true, - "ID": true, - "IP": true, - "JSON": true, - "LHS": true, - "QPS": true, - "RAM": true, - "RHS": true, - "RPC": true, - "SLA": true, - "SMTP": true, - "SSH": true, - "TLS": true, - "TTL": true, - "UI": true, - "UID": true, - "UUID": true, - "URI": true, - "URL": true, - "UTF8": true, - "VM": true, - "XML": true, - "XSRF": true, - "XSS": true, -} -``` - -- 若变量类型为bool类型,则名称应以Has,Is,Can或Allow开头,例如: - -```go -var hasConflict bool + "API": true, + "ASCII": true, + "CPU": true, + "CSS": true, + "DNS": true, + "EOF": true, + "GUID": true, + "HTML": true, + "HTTP": true, + "HTTPS": true, + "ID": true, + "IP": true, + "JSON": true, + "LHS": true, + "QPS": true, + "RAM": true, + "RHS": true, + "RPC": true, + "SLA": true, + "SMTP": true, + "SSH": true, + "TLS": true, + "TTL": true, + "UI": true, + "UID": true, + "UUID": true, + "URI": true, + "URL": true, + "UTF8": true, + "VM": true, + "XML": true, + "XSRF": true, + "XSS": true, +} +``` + +- If the variable type is bool, the name should start with Has, Is, Can or Allow, for example: + +```go +var has Conflict bool var isExist bool -var canManage bool +var can Manage bool var allowGitHook bool ``` -- 局部变量应当尽可能短小,比如使用buf指代buffer,使用i指代index。 -- 代码生成工具自动生成的代码可排除此规则(如`xxx.pb.go`里面的Id) +- Local variables should be as short as possible, for example, use buf to refer to buffer, and use i to refer to index. +- The code automatically generated by the code generation tool can exclude this rule (such as the Id in `xxx.pb.go`) -### 2.7 常量命名 +### 2.7 Constant naming -- 常量名必须遵循驼峰式,首字母根据访问控制决定使用大写或小写。 -- 如果是枚举类型的常量,需要先创建相应类型: +- The constant name must follow the camel case, and the initial letter is uppercase or lowercase according to the access control decision. +- If it is a constant of enumeration type, you need to create the corresponding type first: ```go // Code defines an error code type. @@ -443,53 +439,53 @@ type Code int // Internal errors. const ( - // ErrUnknown - 0: An unknown error occurred. - ErrUnknown Code = iota - // ErrFatal - 1: An fatal error occurred. - ErrFatal + // ErrUnknown - 0: An unknown error occurred. + ErrUnknown Code = iota + // ErrFatal - 1: An fatal error occurred. + Err Fatal ) ``` -### 2.8 Error的命名 +### 2.8 Error naming -- Error类型应该写成FooError的形式。 +- The Error type should be written in the form of FooError. ```go type ExitError struct { - // .... +// .... } ``` -- Error变量写成ErrFoo的形式。 +- The Error variable is written in the form of ErrFoo. ```go -var ErrFormat = errors.New("unknown format") +var ErrFormat = errors. New("unknown format") ``` -## 3. 注释规范 +## 3. Comment specification -- 每个可导出的名字都要有注释,该注释对导出的变量、函数、结构体、接口等进行简要介绍。 -- 全部使用单行注释,禁止使用多行注释。 -- 和代码的规范一样,单行注释不要过长,禁止超过 120 字符,超过的请使用换行展示,尽量保持格式优雅。 -- 注释必须是完整的句子,以需要注释的内容作为开头,句点作为结尾,`格式为 // 名称 描述.`。例如: +- Each exportable name must have a comment, which briefly introduces the exported variables, functions, structures, interfaces, etc. +- All single-line comments are used, and multi-line comments are prohibited. +- Same as the code specification, single-line comments should not be too long, and no more than 120 characters are allowed. If it exceeds, please use a new line to display, and try to keep the format elegant. +- A comment must be a complete sentence, starting with the content to be commented and ending with a period, `the format is // name description.`. For example: ```go // bad // logs the flags in the flagset. -func PrintFlags(flags *pflag.FlagSet) { - // normal code +func PrintFlags(flags *pflag. FlagSet) { +// normal code } -// good +//good // PrintFlags logs the flags in the flagset. -func PrintFlags(flags *pflag.FlagSet) { - // normal code +func PrintFlags(flags *pflag. FlagSet) { +// normal code } ``` -- 所有注释掉的代码在提交code review前都应该被删除,否则应该说明为什么不删除,并给出后续处理建议。 +- All commented out code should be deleted before submitting code review, otherwise, it should explain why it is not deleted, and give follow-up processing suggestions. -- 在多段注释之间可以使用空行分隔加以区分,如下所示: +- Multiple comments can be separated by blank lines, as follows: ```go // Package superman implements methods for saving the world. @@ -499,10 +495,10 @@ func PrintFlags(flags *pflag.FlagSet) { package superman ``` -### 3.1 包注释 +### 3.1 Package Notes -- 每个包都有且仅有一个包级别的注释。 -- 包注释统一用 // 进行注释,格式为 `// Package 包名 包描述`,例如: +- Each package has one and only one package-level annotation. +- Package comments are uniformly commented with // in the format of `// Package package name package description`, for example: ```go // Package genericclioptions contains flags which can be added to you command, bound, completed, and produce @@ -510,90 +506,90 @@ package superman package genericclioptions ``` -### 3.2 变量/常量注释 +### 3.2 Variable/Constant Comments -- 每个可导出的变量/常量都必须有注释说明,`格式为// 变量名 变量描述`,例如: +- Each variable/constant that can be exported must have a comment description, `the format is // variable name variable description`, for example: ```go // ErrSigningMethod defines invalid signing method error. -var ErrSigningMethod = errors.New("Invalid signing method") +var ErrSigningMethod = errors. New("Invalid signing method") ``` -- 出现大块常量或变量定义时,可在前面注释一个总的说明,然后在每一行常量的前一行或末尾详细注释该常量的定义,例如: +- When there is a large block of constant or variable definition, you can comment a general description in front, and then comment the definition of the constant in detail before or at the end of each line of constant, for example: ```go // Code must start with 1xxxxx. const ( - // ErrSuccess - 200: OK. - ErrSuccess int = iota + 100001 + // ErrSuccess - 200: OK. + ErrSuccess int = iota + 100001 - // ErrUnknown - 500: Internal server error. - ErrUnknown + // ErrUnknown - 500: Internal server error. + ErrUnknown - // ErrBind - 400: Error occurred while binding the request body to the struct. - ErrBind + // ErrBind - 400: Error occurred while binding the request body to the struct. + ErrBind - // ErrValidation - 400: Validation failed. - ErrValidation + // ErrValidation - 400: Validation failed. + ErrValidation ) ``` -### 3.3 结构体注释 +### 3.3 Structure Annotation -- 每个需要导出的结构体或者接口都必须有注释说明,格式为 `// 结构体名 结构体描述.`。 -- 结构体内的可导出成员变量名,如果意义不明确,必须要给出注释,放在成员变量的前一行或同一行的末尾。例如: +- Each structure or interface that needs to be exported must have a comment description, the format is `// structure name structure description.`. +- The name of the exportable member variable in the structure, if the meaning is not clear, a comment must be given and placed before the member variable or at the end of the same line. For example: ```go // User represents a user restful resource. It is also used as gorm model. type User struct { - // Standard object's metadata. - metav1.ObjectMeta `json:"metadata,omitempty"` + // Standard object's metadata. + metav1.ObjectMeta `json:"metadata,omitempty"` - Nickname string `json:"nickname" gorm:"column:nickname"` - Password string `json:"password" gorm:"column:password"` - Email string `json:"email" gorm:"column:email"` - Phone string `json:"phone" gorm:"column:phone"` - IsAdmin int `json:"isAdmin,omitempty" gorm:"column:isAdmin"` + Nickname string `json:"nickname" gorm:"column:nickname"` + Password string `json:"password" gorm:"column:password"` + Email string `json:"email" gorm:"column:email"` + Phone string `json:"phone" gorm:"column:phone"` + IsAdmin int `json:"isAdmin,omitempty" gorm:"column:isAdmin"` } ``` -### 3.4 方法注释 +### 3.4 Method Notes -每个需要导出的函数或者方法都必须有注释,格式为// 函数名 函数描述.,例如: +Each function or method that needs to be exported must have a comment, the format is // function name function description., for examplelike: ```go // BeforeUpdate run before update database record. func (p *Policy) BeforeUpdate() (err error) { - // normal code - return nil +// normal code +return nil } ``` -### 3.5 类型注释 +### 3.5 Type annotations -- 每个需要导出的类型定义和类型别名都必须有注释说明,格式为 `// 类型名 类型描述.`,例如: +- Each type definition and type alias that needs to be exported must have a comment description, the format is `// type name type description.`, for example: ```go // Code defines an error code type. type Code int ``` -## 4. 类型 +## 4. Type -### 4.1 字符串 +### 4.1 Strings -- 空字符串判断。 +- Empty string judgment. ```go // bad if s == "" { - // normal code + // normal code } -// good +//good if len(s) == 0 { - // normal code + // normal code } ``` -- `[]byte`/`string`相等比较。 +- `[]byte`/`string` equality comparison. ```go // bad @@ -603,165 +599,165 @@ var s2 []byte bytes.Equal(s1, s2) == 0 bytes.Equal(s1, s2) != 0 -// good +//good var s1 []byte var s2 []byte ... -bytes.Compare(s1, s2) == 0 -bytes.Compare(s1, s2) != 0 +bytes. Compare(s1, s2) == 0 +bytes. Compare(s1, s2) != 0 ``` -- 复杂字符串使用raw字符串避免字符转义。 +- Complex strings use raw strings to avoid character escaping. ```go // bad regexp.MustCompile("\\.") -// good +//good regexp.MustCompile(`\.`) ``` -### 4.2 切片 +### 4.2 Slicing -- 空slice判断。 +- Empty slice judgment. ```go // bad if len(slice) = 0 { - // normal code + // normal code } -// good +//good if slice != nil && len(slice) == 0 { - // normal code + // normal code } ``` -上面判断同样适用于map、channel。 +The above judgment also applies to map and channel. -- 声明slice。 +- Declare a slice. ```go // bad s := []string{} s := make([]string, 0) -// good -var s []string +//good +var s[]string ``` -- slice复制。 +- slice copy. ```go // bad var b1, b2 []byte for i, v := range b1 { - b2[i] = v + b2[i] = v } for i := range b1 { - b2[i] = b1[i] + b2[i] = b1[i] } -// good +//good copy(b2, b1) ``` -- slice新增。 +- slice added. ```go // bad var a, b []int for _, v := range a { - b = append(b, v) + b = append(b, v) } -// good +//good var a, b []int b = append(b, a...) ``` -### 4.3 结构体 +### 4.3 Structure -- struct初始化。 +- struct initialization. -struct以多行格式初始化。 +The struct is initialized in multi-line format. ```go type user struct { - Id int64 - Name string +Id int64 +name string } u1 := user{100, "Colin"} u2 := user{ - Id: 200, - Name: "Lex", + Id: 200, + Name: "Lex", } ``` -## 5. 控制结构 +## 5. Control Structure ### 5.1 if -- if 接受初始化语句,约定如下方式建立局部变量。 +- if accepts the initialization statement, the convention is to create local variables in the following way. ```go if err := loadConfig(); err != nil { - // error handling - return err +// error handling +return err } ``` -- if 对于bool类型的变量,应直接进行真假判断。 +- if For variables of bool type, true and false judgments should be made directly. ```go var isAllow bool if isAllow { - // normal code +// normal code } ``` ### 5.2 for -- 采用短声明建立局部变量。 +- Create local variables using short declarations. ```go sum := 0 for i := 0; i < 10; i++ { - sum += 1 + sum += 1 } ``` -- 不要在 for 循环里面使用 defer,defer只有在函数退出时才会执行。 +- Don't use defer in for loop, defer will only be executed when the function exits. ```go // bad for file := range files { - fd, err := os.Open(file) - if err != nil { - return err - } - defer fd.Close() - // normal code +fd, err := os. Open(file) +if err != nil { +return err +} +defer fd. Close() +// normal code } -// good +//good for file := range files { - func() { - fd, err := os.Open(file) - if err != nil { - return err - } - defer fd.Close() - // normal code - }() +func() { +fd, err := os. Open(file) +if err != nil { +return err +} +defer fd. Close() +// normal code +}() } ``` ### 5.3 range -- 如果只需要第一项(key),就丢弃第二个。 +- If only the first item (key) is needed, discard the second. ```go for key := range keys { @@ -769,133 +765,129 @@ for key := range keys { } ``` -- 如果只需要第二项,则把第一项置为下划线。 +- If only the second item is required, underline the first item. ```go sum := 0 for _, value := range array { - sum += value + sum += value } ``` ### 5.4 switch -- 必须要有default。 +- must have default. ```go switch os := runtime.GOOS; os { - case "linux": - fmt.Println("Linux.") - case "darwin": - fmt.Println("OS X.") - default: - fmt.Printf("%s.\n", os) + case "linux": + fmt.Println("Linux.") + case "darwin": + fmt.Println("OS X.") + default: + fmt.Printf("%s.\n", os) } ``` ### 5.5 goto -- 业务代码禁止使用 goto 。 -- 框架或其他底层源码尽量不用。 +- Business code prohibits the use of goto. +- Try not to use frameworks or other low-level source code. -## 6. 函数 +## 6. Functions -- 传入变量和返回变量以小写字母开头。 -- 函数参数个数不能超过5个。 -- 函数分组与顺序 -- 函数应按粗略的调用顺序排序。 -- 同一文件中的函数应按接收者分组。 -- 尽量采用值传递,而非指针传递。 -- 传入参数是 map、slice、chan、interface ,不要传递指针。 +- Incoming variables and return variables start with a lowercase letter. +- The number of function parameters cannot exceed 5. +- Function grouping and ordering +- Functions should be sorted in rough calling order. +- Functions in the same file should be grouped by receiver. +- Try to use value transfer instead of pointer transfer. +- The incoming parameters are map, slice, chan, interface, do not pass pointers. -### 6.1 函数参数 +### 6.1 Function parameters -- 如果函数返回相同类型的两个或三个参数,或者如果从上下文中不清楚结果的含义,使用命名返回,其他情况不建议使用命名返回,例如: +- If the function returns two or three arguments of the same type, or if the meaning of the result is not clear from the context, use named returns, otherwise it is not recommended to use named returns, for example: ```go func coordinate() (x, y float64, err error) { - // normal code +// normal code } ``` -- 传入变量和返回变量都以小写字母开头。 -- 尽量用值传递,非指针传递。 -- 参数数量均不能超过5个。 -- 多返回值最多返回三个,超过三个请使用 struct。 +- Both incoming and returned variables start with a lowercase letter. +- Try to pass by value instead of pointer. +- The number of parameters cannot exceed 5. +- Multiple return values can return up to three, and if there are more than three, please use struct. ### 6.2 defer -- 当存在资源创建时,应紧跟defer释放资源(可以大胆使用defer,defer在Go1.14版本中,性能大幅提升,defer的性能损耗即使在性能敏感型的业务中,也可以忽略)。 -- 先判断是否错误,再defer释放资源,例如: +- When resources are created, resources should be released immediately after defer (defer can be used boldly, the performance of defer is greatly improved in Go1.14 version, and the performance loss of defer can be ignored even in performance-sensitive businesses). +- First judge whether there is an error, and then defer to release resources, for example: ```go -rep, err := http.Get(url) +rep, err := http. Get(url) if err != nil { - return err + return err } defer resp.Body.Close() ``` -### 6.3 方法的接收器 +### 6.3 Method Receiver -- 推荐以类名第一个英文首字母的小写作为接收器的命名。 -- 接收器的命名在函数超过20行的时候不要用单字符。 -- 接收器的命名不能采用me、this、self这类易混淆名称。 +- It is recommended to use the lowercase of the first English letter of the class name as the name of the receiver. +- Don't use a single character in the name of the receiver when the function exceeds 20 lines. +- The name of the receiver cannot use confusing names such as me, this, and self. -### 6.4 嵌套 -- 嵌套深度不能超过4层。 +### 6.4 Nesting +- The nesting depth cannot exceed 4 levels. -### 6.5 变量命名 -- 变量声明尽量放在变量第一次使用的前面,遵循就近原则。 -- 如果魔法数字出现超过两次,则禁止使用,改用一个常量代替,例如: +### 6.5 Variable Naming +- The variable declaration should be placed before the first use of the variable as far as possible, following the principle of proximity. +- If the magic number appears more than twice, it is forbidden to use it and use a constant instead, for example: ```go -// PI ... -const Prise = 3.14 +// PI... +const Price = 3.14 func getAppleCost(n float64) float64 { - return Prise * n +return Price * n } func getOrangeCost(n float64) float64 { - return Prise * n +return Price * n } ``` -## 7. GOPATH 设置规范 -- Go 1.11 之后,弱化了 GOPATH 规则,已有代码(很多库肯定是在1.11之前建立的)肯定符合这个规则,建议保留 GOPATH 规则,便于维护代码。 -- 建议只使用一个 GOPATH,不建议使用多个 GOPATH。如果使用多个GOPATH,编译生效的 bin 目录是在第一个 GOPATH 下。 +## 7. GOPATH setting specification +- After Go 1.11, the GOPATH rule has been weakened. Existing code (many libraries must have been created before 1.11) must conform to this rule. It is recommended to keep the GOPATH rule to facilitate code maintenance. +- Only one GOPATH is recommended, multiple GOPATHs are not recommended. If multiple GOPATHs are used, the bin directory where compilation takes effect is under the first GOPATH. -## 8. 依赖管理 +## 8. Dependency Management -- Go 1.11 以上必须使用 Go Modules。 -- 使用Go Modules作为依赖管理的项目时,不建议提交vendor目录。 -- 使用Go Modules作为依赖管理的项目时,必须提交go.sum文件。 +- Go 1.11 and above must use Go Modules. +- When using Go Modules as a dependency management project, it is not recommended to submit the vendor directory. +- When using Go Modules as a dependency management project, the go.sum file must be submitted. -### 9. 最佳实践 +### 9. Best Practices -- 尽量少用全局变量,而是通过参数传递,使每个函数都是“无状态”的。这样可以减少耦合,也方便分工和单元测试。 -- 在编译时验证接口的符合性,例如: +- Minimize the use of global variables, but pass parameters, so that each function is "stateless". This reduces coupling and facilitates division of labor and unit testing. +- Verify interface compliance at compile time, for example: ```go type LogHandler struct { - h http.Handler - log *zap.Logger + h http.Handler + log *zap. Logger } -var _ http.Handler = LogHandler{} +var_http.Handler = LogHandler{} ``` -- 服务器处理请求时,应该创建一个context,保存该请求的相关信息(如requestID),并在函数调用链中传递。 - -### 9.1 性能 -- string 表示的是不可变的字符串变量,对 string 的修改是比较重的操作,基本上都需要重新申请内存。所以,如果没有特殊需要,需要修改时多使用 []byte。 -- 优先使用 strconv 而不是 fmt。 - -### 9.2 注意事项 +- When the server processes a request, it should create a context, save the relevant information of the request (such as requestID), and pass it in the function call chain. -- append 要小心自动分配内存,append 返回的可能是新分配的地址。 -- 如果要直接修改 map 的 value 值,则 value 只能是指针,否则要覆盖原来的值。 -- map 在并发中需要加锁。 -- 编译过程无法检查 interface{} 的转换,只能在运行时检查,小心引起 panic。 +### 9.1 Performance +- string represents an immutable string variable, modifying string is a relatively heavy operation, and basically needs to re-apply for memory. Therefore, if there is no special need, use []byte more when you need to modify. +- Prefer strconv over fmt. -## 总结 +### 9.2 Precautions -这里向你介绍了九类常用的编码规范。但今天的最后,我要在这里提醒你一句:规范是人定的,你也可以根据需要,制定符合你项目的规范,但同时我也建议你采纳这些业界沉淀下来的规范,并通过工具来确保规范的执行。 +- append Be careful about automatically allocating memory, append may return a newly allocated address. +- If you want to directly modify the value of the map, the value can only be a pointer, otherwise the original value must be overwritten. +- map needs to be locked during concurrency. +- The conversion of interface{} cannot be checked during compilation, it can only be checked at runtime, be careful to cause panic. diff --git a/docs/conversions/images.md b/docs/conversions/images.md index f2072dea2..44bd7b5bf 100644 --- a/docs/conversions/images.md +++ b/docs/conversions/images.md @@ -11,6 +11,9 @@ OpenIM's versions correspond to GitHub's tag versions. Each time we release a ne 2. **Alibaba Cloud (registry.cn-hangzhou.aliyuncs.com):** For users in Mainland China, we also host OpenIM's Docker images on Alibaba Cloud to provide faster pull speeds. You can view all Alibaba Cloud images on this [page](https://cr.console.aliyun.com/cn-hangzhou/instances/repositories) of Alibaba Cloud Image Service (note that you need to log in to your Alibaba Cloud account first). 3. **Docker Hub (docker.io):** Docker Hub is the most commonly used Docker image hosting platform, and we also host OpenIM's images there to facilitate developers worldwide. You can view all Docker Hub images on the [OpenIM's Docker Hub page](https://hub.docker.com/r/openim). +## Base images design + ++ [https://github.com/openim-sigs/openim-base-image](https://github.com/openim-sigs/openim-base-image) ## OpenIM Image Design and Usage Guide @@ -54,22 +57,19 @@ When pulling OpenIM's Docker images, you can choose the most suitable source bas - Pull from GitHub: - ``` - bashCopy code + ```bash docker pull ghcr.io/openimsdk/openim-server:latest ``` - Pull from Alibaba Cloud: - ``` - bashCopy code + ```bash docker pull registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:latest ``` - Pull from Docker Hub: - ``` - bashCopy code + ```bash docker pull docker.io/openim/openim-server:latest ``` @@ -77,22 +77,19 @@ When pulling OpenIM's Docker images, you can choose the most suitable source bas - Pull from GitHub: - ``` - bashCopy code + ```bash docker pull ghcr.io/openimsdk/openim-chat:latest ``` - Pull from Alibaba Cloud: - ``` - bashCopy code + ```bash docker pull registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:latest ``` - Pull from Docker Hub: - ``` - bashCopy code + ```bash docker pull docker.io/openim/openim-chat:latest ``` diff --git a/docs/conversions/version.md b/docs/conversions/version.md index 06e34543b..06b2e17cb 100644 --- a/docs/conversions/version.md +++ b/docs/conversions/version.md @@ -1,61 +1,88 @@ -# OpenIM Branch Management and Versioning +# OpenIM Branch Management and Versioning: A Blueprint for High-Grade Software Development -Our project, OpenIM, follows the [Semantic Versioning 2.0.0](https://semver.org/lang/zh-CN/) standards. +[📚 **OpenIM TOC**](#openim-branch-management-and-versioning-a-blueprint-for-high-grade-software-development) + - [Unfolding the Mechanism of OpenIM Version Maintenance](#unfolding-the-mechanism-of-openim-version-maintenance) + - [Main Branch: The Heart of OpenIM Development](#main-branch-the-heart-of-openim-development) + - [Release Branch: The Beacon of Stability](#release-branch-the-beacon-of-stability) + - [Tag Management: The Cornerstone of Version Control](#tag-management-the-cornerstone-of-version-control) + - [Release Management: A Guided Tour](#release-management-a-guided-tour) + - [Milestones, Branching, and Addressing Major Bugs](#milestones-branching-and-addressing-major-bugs) + - [Applying Principles: A Git Workflow Example](#applying-principles-a-git-workflow-example) + - [Docker Images Version Management](#docker-images-version-management) -OpenIM, the open source project, employs a comprehensive version management system to ensure the reliability and traceability of our software. Our version management consists of three main components: the `main` branch, the `release` branch, and `tag` management. -## Main Branch +At OpenIM, we acknowledge the profound impact of implementing a robust and efficient version management system, hence we abide by the established standards of [Semantic Versioning 2.0.0](https://semver.org/lang/zh-CN/). -The `main` branch is where all the latest code resides. It's the hub of activity, embodying all the cutting-edge features that are currently being developed or updated. However, since it's subject to frequent changes and updates, it may not always represent the most stable version of the software. Access the `main` branch [here](https://github.com/openimsdk/openim-server/tree/main). +Our software blueprint orchestrates a tripartite version management system that integrates the `main` branch, the `release` branch, and `tag` management. These constituents operate in synchrony to preserve the reliability and traceability of our software across various stages of development. -## Release Branch +## Unfolding the Mechanism of OpenIM Version Maintenance -On the other hand, we have the `release` branch. For instance, in the context of version 3.1, we maintain a `release-v3.1` branch. Unlike the `main` branch, the release branch is designed to be a continuously stable and updated version of the software. This provides a reliable option for users who prefer stability over the latest, but potentially unstable, features. Access the `release-v3.1` branch [here](https://github.com/openimsdk/openim-server/tree/release-v3.1). +Our version maintenance protocol revolves around two primary branches, namely: `main` and `release`. We resort to Semantic Versioning 2.0.0 for marking distinctive versions of our software, representing substantial milestones in its evolution. -## Tag Management +In the OpenIM repository, version identification strictly complies with the `MAJOR.MINOR.PATCH` protocol. Herein: -Finally, there's `tag` management. Despite having both `main` and `release` branches, `tag` serves a crucial role. Tags are immutable, i.e., they remain unchanged once created. Therefore, if you need a specific version of the software, you can use the corresponding tag. Check out the available tags [here](https://github.com/openimsdk/openim-server/tags). +- The `MAJOR` version indicates a shift arising from incompatible changes to the API. +- The `MINOR` version suggests the addition of features in a backward-compatible manner. +- The `PATCH` version flags backward-compatible bug fixes. -Moreover, our Docker image versions are closely tied with these three components. For instance, a tag might correspond to the Docker image `ghcr.io/openimsdk/openim-server:v3.1.0`, a release would be `ghcr.io/openimsdk/openim-server:release-v3.0`, and the main branch might be represented as `ghcr.io/openimsdk/openim-server:main` or `ghcr.io/openimsdk/openim-server:latest`. +## Main Branch: The Heart of OpenIM Development -To find out more, or to contribute to our project, please visit our GitHub repository at [OpenIM Server](https://github.com/openimsdk/openim-server). +The `main` branch is the operational heart of our development process. Housing the most recent and advanced features, this branch serves as the nerve center for all enhancements and updates. It encapsulates the freshest, though possibly unstable, facets of the software. Visit our `main` branch [here](https://github.com/OpenIMSDK/Open-IM-Server/tree/main). -We believe that this approach offers a balanced blend of innovation and stability, enabling us to provide the best possible software to our users. +## Release Branch: The Beacon of Stability -## OpenIM version +For every major release, we curate a corresponding `release` branch, e.g., `release-v3.1`. This branch symbolizes an embodiment of stability and ensures an updated version of the software, providing a dependable option for users favoring stability over nascent, yet possibly unstable, features. Visit the `release-v3.1` branch [here](https://github.com/OpenIMSDK/Open-IM-Server/tree/release-v3.1). -OpenIM manages two primary branches: `main` and `release`. The project uses Semantic Versioning 2.0.0 to tag different versions of the software, each indicating a significant milestone in the software's development. +## Tag Management: The Cornerstone of Version Control -In the OpenIM repository, the versioning adheres to the `MAJOR.MINOR.PATCH` format, where: +In OpenIM's version control system, the role of `tags` stands paramount. Owing to their immutable nature, tags can be effectively utilized to retrieve a specific version of the software. Explore our library of tags [here](https://github.com/OpenIMSDK/Open-IM-Server/tags). -- `MAJOR` version changes when there are incompatible changes to the API, -- `MINOR` version changes when features are added in a backward-compatible manner, and -- `PATCH` version changes when backward-compatible bugs are fixed. +Our Docker image versions are intimately entwined with these tripartite components. For instance, a Docker image tag may correspond to `ghcr.io/openimsdk/openim-server:v3.1.0`, a release to `ghcr.io/openimsdk/openim-server:release-v3.0`, and the main branch to `ghcr.io/openimsdk/openim-server:main` or `ghcr.io/openimsdk/openim-server:latest`. -## Milestones and Branching +To further clarify, the semantics of our version numbers are as follows: + +- **Revision version number**: This represents bug fixes or code optimizations. Typically, it entails no new feature additions and ensures backward compatibility. +- **Build version number**: Auto-generated by the system, each code submission prompts an automatic increment by 1. +- **Version modifiers**: These hint at the software's development stage and stability. Some commonly used modifiers are `alpha`, `beta`, `rc`, `ga`, `r/release/or nothing`, and `lts`. + - `alpha`: An internal testing version with numerous bugs, typically used for communication among developers. + - `beta`: A test version with numerous bugs, generally used for testing by eager community members, who provide feedback to the developers. + - `rc`: Release candidate, which is to be released as the official version. It's the last test version before the official version. + - `ga`: General Availability, the first stable release. + - `r/release/or nothing`: The final release version, intended for general users. + - `lts`: Long Term Support, the official will specify the maintenance year for this version and will fix all bugs discovered in this version. + +Whenever a project undergoes a partial functional addition, the minor version number increments by 1, resetting the revision version number to 0. In contrast, any major project overhaul results in an increment by 1 in the major version number. The build number, typically auto-generated during the compilation process, only requires format definition, thereby eliminating manual control. + +## Release Management: A Guided Tour + +Our GitHub repository at https://github.com/OpenIMSDK/Open-IM-Server/releases associates a release with each tag, with a distinction between Pre-release and Latest, determined by the branch source. Every significant feature launch prompts the issue of a `release` branch, such as `release-v3.2`, as a beacon of stability and Latest release. + +Pre-releases correspond to releases from the `main` branch, denoting tags with Version modifiers such as `v3.2.1-beta.0`, `v3.2.1-rc.1`, etc. If you are seeking the most recent, albeit possibly unstable, release with new features, these tags, originating from the latest `main` branch code, are your go-to. + +Conversely, if stability is your primary concern, you should opt for the release tagged Latest, denoted by tags without Version modifiers, such as `v3.2.1`, `v3.2.2` etc. These tags are linked to the latest stable maintenance branch, like `release-v3.2`. + +## Milestones, Branching, and Addressing Major Bugs + +**About:** + [OpenIM Milestones](https://github.com/OpenIMSDK/Open-IM-Server/milestones) + [OpenIM Tags](https://github.com/OpenIMSDK/Open-IM-Server/tags) + [OpenIM Branches](https://github.com/OpenIMSDK/Open-IM-Server/branches) -When a significant milestone like v3.1.0 is achieved, a new branch `release-v3.1` is created. This branch contains all the code pertaining to this stable release. All bug fixes and features intended for the next version, v3.2.0, are merged into this branch. - -The release of `PATCH` versions (Z in `X.Y.Z`) are driven by bug fixes, and these can be rolled out depending on the bug's priority or over a scheduled time. On the other hand, `MINOR` versions (Y in `X.Y.Z`) are released based on the project's roadmap, milestone completion, or on a scheduled timeline. Importantly, the API of minor versions is always backward-compatible. +We create a new branch, such as `release-v3.1`, for each significant milestone (e.g., v3.1.0), housing all relevant code for that release. All enhancements and bug fixes targeting the subsequent version (e.g., v3.2.0) are integrated into this branch. -## Dealing with Major Bugs +`PATCH` versions (represented by Z in `X.Y.Z`) are primarily propelled by bug fixes, and their release may be either priority-driven or scheduled. In contrast, `MINOR` versions (represented by Y in `X.Y.Z`) are contingent upon the project's roadmap, milestone completion, or a pre-established timeline, always maintaining backward-compatible APIs. -In the event of a major bug discovery, the fix would selectively be merged into the previous version (e.g., v3.1 or the `release-v3.1` branch), as well as into the `main` branch. This is to ensure that users relying on the older version can still receive important bug fixes, while also keeping the main branch updated. +When dealing with major bugs, we selectively merge the fix into the affected version (e.g., v3.1 or the `release-v3.1` branch), as well as the `main` branch. This dual pronged strategy ensures that users on older versions receive crucial bug fixes, while also keeping the `main` branch updated. -It's worth noting that a robust testing regime should be in place to ensure the integrity of all branches at any given time. Automated tests and code review sessions are crucial components of maintaining a healthy codebase. +We reinforce our approach to branch management and versioning with stringent testing protocols. Automated tests and code review sessions form vital components of maintaining a robust and reliable codebase. -To summarize, OpenIM's approach to branch management and versioning ensures a balance between introducing new features, fixing bugs, and maintaining backward compatibility. This strategy is vital for managing user expectations, supporting older versions, and paving the way for the project's continuous growth. +## Applying Principles: A Git Workflow Example -## Git Workflow Example +The workflow to address a bug fix might follow these steps: -To put the above principles into practice, here's a Git workflow example that you might follow when working on a bug fix: - -``` -bashCopy code# Checkout the branch for the version that needs the bug fix +```bash +bashCopy codebashCopy code# Checkout the branch for the version that needs the bug fix git checkout release-v3.1 # Create a new branch for the bug fix @@ -78,9 +105,8 @@ git merge release-v3.1 git push origin main ``` -Remember, communication with your team is key throughout this process, keeping everyone up-to-date with the changes being made. - +Throughout this process, active communication within the team is pivotal to maintaining transparency and consensus on changes. -## Docker images version management +## Docker Images Version Management -+ [OpenIM Docker Images Administration](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) +For more details on managing Docker image versions, visit [OpenIM Docker Images Administration](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md). diff --git a/go.mod b/go.mod index e016ff06f..643ba06a7 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ require ( github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/dtm-labs/rockscache v0.1.1 github.com/gin-gonic/gin v1.9.1 - github.com/go-playground/validator/v10 v10.14.0 + github.com/go-playground/validator/v10 v10.15.0 github.com/gogo/protobuf v1.3.2 github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang/protobuf v1.5.3 - github.com/gorilla/websocket v1.4.2 + github.com/gorilla/websocket v1.5.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/jinzhu/copier v0.3.5 github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect @@ -23,23 +23,23 @@ require ( github.com/prometheus/client_golang v1.16.0 github.com/robfig/cron/v3 v3.0.1 github.com/sirupsen/logrus v1.9.3 // indirect - github.com/stretchr/testify v1.8.3 - go.mongodb.org/mongo-driver v1.12.0 - golang.org/x/image v0.9.0 // indirect - google.golang.org/api v0.134.0 - google.golang.org/grpc v1.56.2 + github.com/stretchr/testify v1.8.4 + go.mongodb.org/mongo-driver v1.12.1 + golang.org/x/image v0.11.0 + google.golang.org/api v0.136.0 + google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/mysql v1.5.1 - gorm.io/gorm v1.25.2 + gorm.io/gorm v1.25.3 ) require github.com/google/uuid v1.3.0 require ( - github.com/OpenIMSDK/protocol v0.0.3 - github.com/OpenIMSDK/tools v0.0.5 - github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible + github.com/OpenIMSDK/protocol v0.0.6 + github.com/OpenIMSDK/tools v0.0.13 + github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.7.1 github.com/redis/go-redis/v9 v9.0.5 @@ -47,11 +47,11 @@ require ( ) require ( - cloud.google.com/go v0.110.4 // indirect - cloud.google.com/go/compute v1.20.1 // indirect + cloud.google.com/go v0.110.6 // indirect + cloud.google.com/go/compute v1.23.0 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/firestore v1.11.0 // indirect - cloud.google.com/go/iam v1.1.0 // indirect + cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/longrunning v0.5.1 // indirect cloud.google.com/go/storage v1.30.1 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -77,7 +77,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jcmturner/aescts/v2 v2.0.0 // indirect github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect github.com/jcmturner/gofork v1.0.0 // indirect @@ -117,16 +117,17 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/oauth2 v0.10.0 // indirect + golang.org/x/net v0.14.0 // indirect + golang.org/x/oauth2 v0.11.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect + golang.org/x/sys v0.11.0 // indirect + golang.org/x/text v0.12.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect + google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect ) require ( @@ -134,10 +135,9 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/spf13/cobra v1.6.1 + github.com/spf13/cobra v1.7.0 github.com/ugorji/go/codec v1.2.11 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.11.0 // indirect - google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect + golang.org/x/crypto v0.12.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) diff --git a/go.sum b/go.sum index 067ef5301..1c900be1e 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,15 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.4 h1:1JYyxKMN9hd5dR2MYTPWkGUgcoxVVhg0LKNKEo0qvmk= -cloud.google.com/go v0.110.4/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= -cloud.google.com/go/compute v1.20.1 h1:6aKEtlUiwEpJzM001l0yFkpXmUVXaN8W+fbkb2AZNbg= -cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= +cloud.google.com/go v0.110.6 h1:8uYAkj3YHTP/1iwReuHPxLSbdcyc+dSBbzFMrVwDR6Q= +cloud.google.com/go v0.110.6/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= +cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY= +cloud.google.com/go/compute v1.23.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= cloud.google.com/go/firestore v1.11.0 h1:PPgtwcYUOXV2jFe1bV3nda3RCrOa8cvBjTOn2MQVfW8= cloud.google.com/go/firestore v1.11.0/go.mod h1:b38dKhgzlmNNGTNZZwe7ZRFEuRab1Hay3/DBsIGKKy4= -cloud.google.com/go/iam v1.1.0 h1:67gSqaPukx7O8WLLHMa0PNs3EBGd2eE4d+psbO/CO94= -cloud.google.com/go/iam v1.1.0/go.mod h1:nxdHjaKfCr7fNYx/HJMM8LgiMugmveWlkatear5gVyk= +cloud.google.com/go/iam v1.1.1 h1:lW7fzj15aVIXYHREOqjRBV9PsH0Z6u8Y46a1YGvQP4Y= +cloud.google.com/go/iam v1.1.1/go.mod h1:A5avdyVL2tCppe4unb0951eI9jreack+RJ0/d+KUZOU= cloud.google.com/go/longrunning v0.5.1 h1:Fr7TXftcqTudoyRJa113hyaqlGdiBQkp0Gq7tErFDWI= cloud.google.com/go/longrunning v0.5.1/go.mod h1:spvimkwdz6SPWKEt/XBij79E9fiTkHSQl/fRUUQJYJc= cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/oNM= @@ -17,17 +17,17 @@ cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7Biccwk firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OpenIMSDK/protocol v0.0.3 h1:CFQtmnyW+1dYKVFaVaHcJ6oYuMiMdNfU2gC1xz3K/9I= -github.com/OpenIMSDK/protocol v0.0.3/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= -github.com/OpenIMSDK/tools v0.0.5 h1:yBVHJ3EpIDcp8VFKPjuGr6MQvFa3t4JByZ+vmeC06/Q= -github.com/OpenIMSDK/tools v0.0.5/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= +github.com/OpenIMSDK/protocol v0.0.6 h1:KjaItOEww7vjrhwyxHnVzhw80pnjcNukpskadqW6gnA= +github.com/OpenIMSDK/protocol v0.0.6/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/tools v0.0.13 h1:rcw4HS8S2DPZR9UOBxD8/ol9UBMzXBypzOVEytDRIMo= +github.com/OpenIMSDK/tools v0.0.13/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= github.com/Shopify/sarama v1.29.0 h1:ARid8o8oieau9XrHI55f/L3EoRAhm9px6sonbD7yuUE= github.com/Shopify/sarama v1.29.0/go.mod h1:2QpgD79wpdAESqNQMxNc0KYMkycd4slxGdV3TWSVqrU= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= -github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible h1:6JF1bjhT0WN2srEmijfOFtVWwV91KZ6dJY1/JbdtGrI= +github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -100,8 +100,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.15.0 h1:nDU5XeOKtB3GEa+uB7GNYwhVKsgjAR7VgKoNB6ryXfw= +github.com/go-playground/validator/v10 v10.15.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= @@ -171,8 +171,8 @@ github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56 github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= @@ -180,8 +180,8 @@ github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2I github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= @@ -298,8 +298,8 @@ github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= 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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -314,8 +314,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0= github.com/tencentyun/cos-go-sdk-v5 v0.7.42 h1:Up1704BJjI5orycXKjpVpvuOInt9GC5pqY4knyE9Uds= @@ -337,8 +338,8 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul 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.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE= -go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0= +go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= +go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= @@ -360,11 +361,11 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g= -golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0= +golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo= +golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8= 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= @@ -393,12 +394,12 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8= -golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= +golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= +golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= 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-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -429,8 +430,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc 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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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= @@ -441,8 +442,8 @@ golang.org/x/text v0.3.6/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.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -462,8 +463,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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= -google.golang.org/api v0.134.0 h1:ktL4Goua+UBgoP1eL1/60LwZJqa1sIzkLmvoR3hR6Gw= -google.golang.org/api v0.134.0/go.mod h1:sjRL3UnjTx5UqNQS9EWr9N8p7xbHpy1k0XGRLCf3Spk= +google.golang.org/api v0.136.0 h1:e/6enzUE1s4tGPa6Q3ZYShKTtvRc+1Jq0rrafhppmOs= +google.golang.org/api v0.136.0/go.mod h1:XtJfF+V2zgUxelOn5Zs3kECtluMxneJG8ZxUTlLNTPA= 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/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= @@ -472,12 +473,12 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 h1:Au6te5hbKUV8pIYWHqOUZ1pva5qK/rwbIhoXEUB9Lu8= -google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:O9kGHb51iE/nOGvQaDUuadVYqovW56s5emA88lQnj6Y= -google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 h1:XVeBY8d/FaK4848myy41HBqnDwvxeV3zMZhwN1TvAMU= -google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:mPBs5jNgx2GuQGvFwUvVKqtn6HsUw9nP64BedgvqEsQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 h1:Z8qdAF9GFsmcUuWQ5KVYIpP3PCKydn/YKORnghIalu4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= +google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= +google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= +google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 h1:nIgk/EEq3/YlnmVVXVnm14rC2oxgs1o0ong4sD/rd44= +google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5/go.mod h1:5DZzOUPCLYL3mNkQ0ms0F3EuUNZ7py1Bqeq6sxzI7/Q= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 h1:wukfNtZmZUurLN/atp2hiIeTKn7QJWIQdHzqmsOnAOk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= 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= @@ -486,8 +487,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= -google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= 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= @@ -522,8 +523,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= -gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.3 h1:zi4rHZj1anhZS2EuEODMhDisGy+Daq9jtPrNGgbQYD8= +gorm.io/gorm v1.25.3/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= 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= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/go.work b/go.work new file mode 100644 index 000000000..09e86f032 --- /dev/null +++ b/go.work @@ -0,0 +1,7 @@ +go 1.20 + +use ( + . + ./tools/infra + ./tools/ncpu +) diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 000000000..49bef9646 --- /dev/null +++ b/go.work.sum @@ -0,0 +1,6 @@ +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= +go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/init_docker.sh b/init_docker.sh deleted file mode 100755 index b06eda469..000000000 --- a/init_docker.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -mark='' -for ((ratio=0;${ratio}<=100;ratio+=5)) -do - sleep 0.2 - printf "progress:[%-40s]%d%%\r" "${mark}" "${ratio}" - mark="##${mark}" -done -echo - -set -e - -# Change directory to the 'scripts' folder -cd scripts - -# Grant execute permissions to all shell scripts in the 'scripts' folder -chmod +x *.sh - -# Run the 'env_check.sh' script for environment checks -./env_check.sh - -# Move back to the parent directory -cd .. - -# Check if Docker is installed -if ! command -v docker >/dev/null 2>&1; then - echo "Error: Docker is not installed. Please install Docker before running this script." - exit 1 -fi - -# Start Docker services using docker-compose -if command -v docker-compose &> /dev/null -then - docker-compose up -d -else - docker compose up -d -fi - -# Move back to the 'scripts' folder -cd scripts - -# Run the 'docker_check_service.sh' script for Docker service checks -./docker_check_service.sh diff --git a/install.sh b/install.sh index f9b9b7ec4..38db46ed4 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +21,7 @@ set -e set -o pipefail -############### OpenIM Github ############### +############################## OpenIM Github ############################## # ... rest of the script ... # TODO @@ -78,7 +79,7 @@ GITHUB_TOKEN= # Default data directory. If you want to specify a different directory, uncomment and replace "./". # DATA_DIR=./ -############### OpenIM Functions ############### +############################## OpenIM Functions ############################## # Install horizon of the script # # Pre-requisites: @@ -290,7 +291,7 @@ function install_openim() { success "OpenIM installation completed successfully. Happy chatting!" } -############### OpenIM Help ############### +############################## OpenIM Help ############################## # Function to display help message function cmd_help() { @@ -406,7 +407,7 @@ function parseinput() { done } -############### OpenIM LOGO ############### +############################## OpenIM LOG ############################## # Set text color to cyan for header and URL print_with_delay() { text="$1" diff --git a/install_guide.sh b/install_guide.sh index 1c5f06fb9..a32bd24f4 100755 --- a/install_guide.sh +++ b/install_guide.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash echo "Welcome to the Open-IM-Server installation scripts." echo "Please select an deploy option:" diff --git a/internal/api/auth.go b/internal/api/auth.go index 11debbea9..9dcc8f7c7 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -17,9 +17,10 @@ package api import ( "github.com/gin-gonic/gin" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/auth" "github.com/OpenIMSDK/tools/a2r" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type AuthApi rpcclient.Auth diff --git a/internal/api/conversation.go b/internal/api/conversation.go index 0d8b41e37..9f25b5427 100644 --- a/internal/api/conversation.go +++ b/internal/api/conversation.go @@ -17,9 +17,10 @@ package api import ( "github.com/gin-gonic/gin" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/tools/a2r" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type ConversationApi rpcclient.Conversation diff --git a/internal/api/friend.go b/internal/api/friend.go index f64a99ef3..9542a61f9 100644 --- a/internal/api/friend.go +++ b/internal/api/friend.go @@ -15,10 +15,11 @@ package api import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/friend" "github.com/OpenIMSDK/tools/a2r" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/gin-gonic/gin" ) @@ -83,3 +84,7 @@ func (o *FriendApi) ImportFriends(c *gin.Context) { func (o *FriendApi) IsFriend(c *gin.Context) { a2r.Call(friend.FriendClient.IsFriend, o.Client, c) } + +func (o *FriendApi) GetFriendIDs(c *gin.Context) { + a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c) +} diff --git a/internal/api/group.go b/internal/api/group.go index ab397a8ac..1dbca3126 100644 --- a/internal/api/group.go +++ b/internal/api/group.go @@ -15,10 +15,11 @@ package api import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/tools/a2r" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/gin-gonic/gin" ) @@ -139,3 +140,7 @@ func (o *GroupApi) GroupCreateCount(c *gin.Context) { func (o *GroupApi) GetGroups(c *gin.Context) { a2r.Call(group.GroupClient.GetGroups, o.Client, c) } + +func (o *GroupApi) GetGroupMemberUserIDs(c *gin.Context) { + a2r.Call(group.GroupClient.GetGroupMemberUserIDs, o.Client, c) +} diff --git a/internal/api/msg.go b/internal/api/msg.go index e4a8fda17..da749b0ae 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -15,14 +15,15 @@ package api import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/tools/mcontext" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "github.com/mitchellh/mapstructure" "google.golang.org/protobuf/proto" - "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" @@ -31,6 +32,9 @@ import ( "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type MessageApi struct { @@ -234,6 +238,51 @@ func (m *MessageApi) SendMessage(c *gin.Context) { apiresp.GinSuccess(c, respPb) } +func (m *MessageApi) SendBusinessNotification(c *gin.Context) { + req := struct { + Key string `json:"key"` + Data string `json:"data"` + SendUserID string `json:"sendUserID"` + RecvUserID string `json:"recvUserID"` + }{} + if err := c.BindJSON(&req); err != nil { + apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) + return + } + if !authverify.IsAppManagerUid(c) { + apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message")) + return + } + sendMsgReq := msg.SendMsgReq{ + MsgData: &sdkws.MsgData{ + SendID: req.SendUserID, + RecvID: req.RecvUserID, + Content: []byte(utils.StructToJsonString(&sdkws.NotificationElem{ + Detail: utils.StructToJsonString(&struct { + Key string `json:"key"` + Data string `json:"data"` + }{Key: req.Key, Data: req.Data}), + })), + MsgFrom: constant.SysMsgType, + ContentType: constant.BusinessNotification, + SessionType: constant.SingleChatType, + CreateTime: utils.GetCurrentTimestampByMill(), + ClientMsgID: utils.GetMsgID(mcontext.GetOpUserID(c)), + Options: config.GetOptionsByNotification(config.NotificationConf{ + IsSendMsg: false, + ReliabilityLevel: 1, + UnreadCount: false, + }), + }, + } + respPb, err := m.Client.SendMsg(c, &sendMsgReq) + if err != nil { + apiresp.GinError(c, err) + return + } + apiresp.GinSuccess(c, respPb) +} + func (m *MessageApi) BatchSendMsg(c *gin.Context) { var ( req apistruct.BatchSendMsgReq diff --git a/internal/api/route.go b/internal/api/route.go index 1926b55f1..2dd5d030e 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -16,14 +16,16 @@ package api import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "net/http" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/apiresp" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/tokenverify" - "net/http" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" @@ -32,12 +34,13 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mw" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine { @@ -82,7 +85,6 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive userRouterGroup.POST("/subscribe_users_status", ParseToken, u.UnSubscriberStatus) userRouterGroup.POST("/unsubscribe_users_status", ParseToken, u.UnSubscriberStatus) userRouterGroup.POST("/get_users_status", ParseToken, u.GetUserStatus) - } // friend routing group friendRouterGroup := r.Group("/friend", ParseToken) @@ -102,6 +104,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive friendRouterGroup.POST("/remove_black", f.RemoveBlack) friendRouterGroup.POST("/import_friend", f.ImportFriends) friendRouterGroup.POST("/is_friend", f.IsFriend) + friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs) } g := NewGroupApi(*groupRpc) groupRouterGroup := r.Group("/group", ParseToken) @@ -129,6 +132,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo) groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo) groupRouterGroup.POST("/get_groups", g.GetGroups) + groupRouterGroup.POST("/get_group_member_user_id", g.GetGroupMemberUserIDs) } superGroupRouterGroup := r.Group("/super_group", ParseToken) { @@ -166,6 +170,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive msgGroup.POST("/newest_seq", m.GetSeq) msgGroup.POST("/search_msg", m.SearchMsg) msgGroup.POST("/send_msg", m.SendMessage) + msgGroup.POST("/send_business_notification", m.SendBusinessNotification) msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs) msgGroup.POST("/revoke_msg", m.RevokeMsg) msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead) diff --git a/internal/api/statistics.go b/internal/api/statistics.go index f267a0ec1..9db38af4a 100644 --- a/internal/api/statistics.go +++ b/internal/api/statistics.go @@ -17,9 +17,10 @@ package api import ( "github.com/gin-gonic/gin" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/user" "github.com/OpenIMSDK/tools/a2r" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type StatisticsApi rpcclient.User diff --git a/internal/api/third.go b/internal/api/third.go index e480d4c11..44a492fc4 100644 --- a/internal/api/third.go +++ b/internal/api/third.go @@ -15,16 +15,18 @@ package api import ( - "github.com/gin-gonic/gin" "math/rand" "net/http" "strconv" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/gin-gonic/gin" + "github.com/OpenIMSDK/protocol/third" "github.com/OpenIMSDK/tools/a2r" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type ThirdApi rpcclient.Third @@ -81,7 +83,14 @@ func (o *ThirdApi) ObjectRedirect(c *gin.Context) { operationID = strconv.Itoa(rand.Int()) } ctx := mcontext.SetOperationID(c, operationID) - resp, err := o.Client.AccessURL(ctx, &third.AccessURLReq{Name: name}) + query := make(map[string]string) + for key, values := range c.Request.URL.Query() { + if len(values) == 0 { + continue + } + query[key] = values[0] + } + resp, err := o.Client.AccessURL(ctx, &third.AccessURLReq{Name: name, Query: query}) if err != nil { if errs.ErrArgs.Is(err) { c.String(http.StatusBadRequest, err.Error()) diff --git a/internal/api/user.go b/internal/api/user.go index 41f6fd4c9..9392eb423 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -17,8 +17,6 @@ package api import ( "github.com/gin-gonic/gin" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msggateway" "github.com/OpenIMSDK/protocol/user" @@ -26,6 +24,9 @@ import ( "github.com/OpenIMSDK/tools/apiresp" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type UserApi rpcclient.User diff --git a/internal/msggateway/callback.go b/internal/msggateway/callback.go index 5ede3c854..11fdd0298 100644 --- a/internal/msggateway/callback.go +++ b/internal/msggateway/callback.go @@ -18,11 +18,12 @@ import ( "context" "time" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/tools/mcontext" + cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/tools/mcontext" ) func url() string { diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index 096fd1463..9f612e021 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -18,10 +18,11 @@ import ( "context" "errors" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "runtime/debug" "sync" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "google.golang.org/protobuf/proto" "github.com/OpenIMSDK/protocol/constant" diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index e9a53cbf7..d57d41aec 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -16,20 +16,23 @@ package msggateway import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/tools/errs" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/startrpc" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msggateway" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/startrpc" ) func (s *Server) InitServer(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { diff --git a/internal/msggateway/message_handler.go b/internal/msggateway/message_handler.go index f81a88cb7..6c26e5906 100644 --- a/internal/msggateway/message_handler.go +++ b/internal/msggateway/message_handler.go @@ -23,10 +23,11 @@ import ( "github.com/go-playground/validator/v10" "google.golang.org/protobuf/proto" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type Req struct { diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 67c8132ca..ee8853af6 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -17,17 +17,19 @@ package msggateway import ( "context" "errors" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "net/http" "strconv" "sync" "sync/atomic" "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/protocol/constant" "github.com/redis/go-redis/v9" @@ -91,6 +93,7 @@ func (ws *WsServer) SetDiscoveryRegistry(client discoveryregistry.SvcDiscoveryRe u := rpcclient.NewUserRpcClient(client) ws.userClient = &u } + func (ws *WsServer) SetUserOnlineStatus(ctx context.Context, client *Client, status int32) { err := ws.userClient.SetUserStatus(ctx, client.UserID, status, client.PlatformID) if err != nil { @@ -107,9 +110,7 @@ func (ws *WsServer) SetUserOnlineStatus(ctx context.Context, client *Client, sta if err != nil { log.ZWarn(ctx, "CallbackUserOffline err", err) } - } - } func (ws *WsServer) SetCacheHandler(cache cache.MsgModel) { diff --git a/internal/msgtransfer/init.go b/internal/msgtransfer/init.go index d54e81240..f996399b5 100644 --- a/internal/msgtransfer/init.go +++ b/internal/msgtransfer/init.go @@ -22,6 +22,10 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/tools/mw" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" @@ -30,9 +34,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" - "github.com/OpenIMSDK/tools/log" - "github.com/OpenIMSDK/tools/mw" ) type MsgTransfer struct { diff --git a/internal/msgtransfer/online_history_msg_handler.go b/internal/msgtransfer/online_history_msg_handler.go index 282f50119..efaf28cc3 100644 --- a/internal/msgtransfer/online_history_msg_handler.go +++ b/internal/msgtransfer/online_history_msg_handler.go @@ -16,27 +16,29 @@ package msgtransfer import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "strconv" "strings" "sync" "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "github.com/OpenIMSDK/tools/errs" "github.com/Shopify/sarama" "github.com/go-redis/redis" "google.golang.org/protobuf/proto" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) const ( @@ -143,7 +145,7 @@ func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) { len(modifyMsgList), ) conversationIDMsg := msgprocessor.GetChatConversationIDByMsg(ctxMsgList[0].message) - conversationIDNotification := msgprocessor.GetNotificationConversationID(ctxMsgList[0].message) + conversationIDNotification := msgprocessor.GetNotificationConversationIDByMsg(ctxMsgList[0].message) och.handleMsg(ctx, msgChannelValue.uniqueKey, conversationIDMsg, storageMsgList, notStorageMsgList) och.handleNotification( ctx, diff --git a/internal/msgtransfer/online_msg_to_mongo_handler.go b/internal/msgtransfer/online_msg_to_mongo_handler.go index 4a8b5e63e..e0dfc59fb 100644 --- a/internal/msgtransfer/online_msg_to_mongo_handler.go +++ b/internal/msgtransfer/online_msg_to_mongo_handler.go @@ -20,11 +20,12 @@ import ( "github.com/Shopify/sarama" "google.golang.org/protobuf/proto" + pbMsg "github.com/OpenIMSDK/protocol/msg" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" kfk "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" - pbMsg "github.com/OpenIMSDK/protocol/msg" - "github.com/OpenIMSDK/tools/log" ) type OnlineHistoryMongoConsumerHandler struct { diff --git a/internal/msgtransfer/persistent_msg_handler.go b/internal/msgtransfer/persistent_msg_handler.go index b67e07cc0..6fcb7d187 100644 --- a/internal/msgtransfer/persistent_msg_handler.go +++ b/internal/msgtransfer/persistent_msg_handler.go @@ -17,14 +17,15 @@ package msgtransfer import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - kfk "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" "github.com/OpenIMSDK/protocol/constant" pbMsg "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + kfk "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" + "github.com/Shopify/sarama" "google.golang.org/protobuf/proto" ) diff --git a/internal/push/callback.go b/internal/push/callback.go index d5e678301..996341ac1 100644 --- a/internal/push/callback.go +++ b/internal/push/callback.go @@ -17,14 +17,15 @@ package push import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" ) func url() string { diff --git a/internal/push/offlinepush/fcm/push.go b/internal/push/offlinepush/fcm/push.go index cea90f865..ffa5db428 100644 --- a/internal/push/offlinepush/fcm/push.go +++ b/internal/push/offlinepush/fcm/push.go @@ -16,18 +16,20 @@ package fcm import ( "context" - config2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "path/filepath" + config2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + firebase "firebase.google.com/go" "firebase.google.com/go/messaging" "github.com/redis/go-redis/v9" "google.golang.org/api/option" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/protocol/constant" ) const SinglePushCountLimit = 400 diff --git a/internal/push/offlinepush/getui/push.go b/internal/push/offlinepush/getui/push.go index a2f887a41..1098dacae 100644 --- a/internal/push/offlinepush/getui/push.go +++ b/internal/push/offlinepush/getui/push.go @@ -25,15 +25,16 @@ import ( "github.com/go-redis/redis" - "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils/splitter" + "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" + "github.com/OpenIMSDK/tools/utils" ) diff --git a/internal/push/push_handler.go b/internal/push/push_handler.go index 8e307c360..8a1a2680c 100644 --- a/internal/push/push_handler.go +++ b/internal/push/push_handler.go @@ -20,13 +20,14 @@ import ( "github.com/Shopify/sarama" "google.golang.org/protobuf/proto" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - kfk "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" "github.com/OpenIMSDK/protocol/constant" pbChat "github.com/OpenIMSDK/protocol/msg" pbPush "github.com/OpenIMSDK/protocol/push" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + kfk "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" ) type ConsumerHandler struct { diff --git a/internal/push/push_rpc_server.go b/internal/push/push_rpc_server.go index 965f890a5..c579deb45 100644 --- a/internal/push/push_rpc_server.go +++ b/internal/push/push_rpc_server.go @@ -20,14 +20,15 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" pbPush "github.com/OpenIMSDK/protocol/push" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type pushServer struct { diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index b787268d0..50010ca84 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -18,8 +18,17 @@ import ( "context" "encoding/json" "errors" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/protocol/msggateway" + "github.com/OpenIMSDK/protocol/sdkws" + "github.com/OpenIMSDK/tools/discoveryregistry" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/tools/mcontext" + "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/fcm" "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/getui" @@ -30,13 +39,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/protocol/msggateway" - "github.com/OpenIMSDK/protocol/sdkws" - "github.com/OpenIMSDK/tools/discoveryregistry" - "github.com/OpenIMSDK/tools/log" - "github.com/OpenIMSDK/tools/mcontext" - "github.com/OpenIMSDK/tools/utils" ) type Pusher struct { diff --git a/internal/push/tools.go b/internal/push/tools.go index 2135c901e..3242767b1 100644 --- a/internal/push/tools.go +++ b/internal/push/tools.go @@ -1,3 +1,17 @@ +// Copyright © 2023 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package push import ( diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go index 1abfc9771..4d3aee88a 100644 --- a/internal/rpc/auth/auth.go +++ b/internal/rpc/auth/auth.go @@ -16,14 +16,11 @@ package auth import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" pbAuth "github.com/OpenIMSDK/protocol/auth" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msggateway" @@ -33,6 +30,11 @@ import ( "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/tokenverify" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type authServer struct { diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 6030bfa55..e880cb6c4 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -16,17 +16,11 @@ package conversation import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" - tableRelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/protocol/constant" pbConversation "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/tools/discoveryregistry" @@ -34,6 +28,14 @@ import ( "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" + tableRelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" ) type conversationServer struct { diff --git a/internal/rpc/friend/black.go b/internal/rpc/friend/black.go index 9df5abb33..c36abe56d 100644 --- a/internal/rpc/friend/black.go +++ b/internal/rpc/friend/black.go @@ -16,13 +16,15 @@ package friend import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + pbFriend "github.com/OpenIMSDK/protocol/friend" "github.com/OpenIMSDK/tools/mcontext" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func (s *friendServer) GetPaginationBlacks( diff --git a/internal/rpc/friend/callback.go b/internal/rpc/friend/callback.go index bd7716090..f29867bb0 100644 --- a/internal/rpc/friend/callback.go +++ b/internal/rpc/friend/callback.go @@ -17,13 +17,14 @@ package friend import ( "context" - cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" "github.com/OpenIMSDK/protocol/constant" pbfriend "github.com/OpenIMSDK/protocol/friend" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" + + cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" ) func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error { diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 7f3be3439..00ea68392 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -16,25 +16,28 @@ package friend import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/tools/log" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" - tablerelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/protocol/constant" pbfriend "github.com/OpenIMSDK/protocol/friend" registry "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" + tablerelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" ) type friendServer struct { diff --git a/internal/rpc/group/cache.go b/internal/rpc/group/cache.go index 6275292b6..0f12cd60f 100644 --- a/internal/rpc/group/cache.go +++ b/internal/rpc/group/cache.go @@ -17,8 +17,9 @@ package group import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" pbGroup "github.com/OpenIMSDK/protocol/group" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" ) func (s *groupServer) GetGroupInfoCache( diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 72661d16b..cb49d6f74 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -18,17 +18,18 @@ import ( "context" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/protocol/wrapperspb" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" ) func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (err error) { diff --git a/internal/rpc/group/convert.go b/internal/rpc/group/convert.go index 22dbfda5f..6f75234ff 100644 --- a/internal/rpc/group/convert.go +++ b/internal/rpc/group/convert.go @@ -15,8 +15,9 @@ package group import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func (s *groupServer) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo { diff --git a/internal/rpc/group/fill.go b/internal/rpc/group/fill.go index 9cf15f8a2..10d326deb 100644 --- a/internal/rpc/group/fill.go +++ b/internal/rpc/group/fill.go @@ -17,8 +17,9 @@ package group import ( "context" - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func (s *groupServer) FindGroupMember( diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index a7680dfaa..282d41011 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -31,17 +31,13 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" + "github.com/OpenIMSDK/tools/mw/specialerror" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/tools/mw/specialerror" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" "github.com/OpenIMSDK/protocol/constant" pbGroup "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/protocol/sdkws" @@ -50,6 +46,12 @@ import ( "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" ) func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { @@ -159,6 +161,9 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR if req.OwnerUserID == "" { return nil, errs.ErrArgs.Wrap("no group owner") } + if req.GroupInfo.GroupType != constant.WorkingGroup { + return nil, errs.ErrArgs.Wrap(fmt.Sprintf("group type %d not support", req.GroupInfo.GroupType)) + } if err := authverify.CheckAccessV3(ctx, req.OwnerUserID); err != nil { return nil, err } @@ -688,8 +693,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup return nil, errs.ErrGroupRequestHandled.Wrap("group request already processed") } var inGroup bool - _, err = s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.FromUserID) - if err == nil { + if _, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.FromUserID); err == nil { inGroup = true // 已经在群里了 } else if !s.IsNotFound(err) { return nil, err @@ -716,6 +720,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup return nil, err } } + log.ZDebug(ctx, "GroupApplicationResponse", "inGroup", inGroup, "HandleResult", req.HandleResult, "member", member) if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil { return nil, err } @@ -725,12 +730,14 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup return nil, err } s.Notification.GroupApplicationAcceptedNotification(ctx, req) + if member == nil { + log.ZDebug(ctx, "GroupApplicationResponse", "member is nil") + } else { + s.Notification.MemberEnterNotification(ctx, req.GroupID, req.FromUserID) + } case constant.GroupResponseRefuse: s.Notification.GroupApplicationRejectedNotification(ctx, req) } - if member != nil { - s.Notification.MemberEnterNotification(ctx, req) - } return &pbGroup.GroupApplicationResponseResp{}, nil } @@ -776,7 +783,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.InviterUserID}); err != nil { return nil, err } - s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID) + s.Notification.MemberEnterNotification(ctx, req.GroupID, req.InviterUserID) return resp, nil } groupRequest := relationTb.GroupRequestModel{ diff --git a/internal/rpc/group/super_group.go b/internal/rpc/group/super_group.go index 070e154bc..6de16b013 100644 --- a/internal/rpc/group/super_group.go +++ b/internal/rpc/group/super_group.go @@ -19,14 +19,15 @@ import ( "fmt" "strings" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/constant" pbGroup "github.com/OpenIMSDK/protocol/group" sdkws "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) func (s *groupServer) GetJoinedSuperGroupList( diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 5ed6a5f09..f5e4355ec 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -16,18 +16,20 @@ package msg import ( "context" + "github.com/OpenIMSDK/protocol/sdkws" "google.golang.org/protobuf/proto" - cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" "github.com/OpenIMSDK/protocol/constant" pbChat "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" ) func cbURL() string { diff --git a/internal/rpc/msg/delete.go b/internal/rpc/msg/delete.go index cdee8bdb5..ff258eaae 100644 --- a/internal/rpc/msg/delete.go +++ b/internal/rpc/msg/delete.go @@ -16,6 +16,7 @@ package msg import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "github.com/OpenIMSDK/protocol/constant" diff --git a/internal/rpc/msg/message_interceptor.go b/internal/rpc/msg/message_interceptor.go index 3c8bf965d..2b41ccb51 100644 --- a/internal/rpc/msg/message_interceptor.go +++ b/internal/rpc/msg/message_interceptor.go @@ -17,11 +17,12 @@ package msg import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type MessageInterceptorFunc func(ctx context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error) diff --git a/internal/rpc/msg/revoke.go b/internal/rpc/msg/revoke.go index 18066c1a2..d700e2df1 100644 --- a/internal/rpc/msg/revoke.go +++ b/internal/rpc/msg/revoke.go @@ -17,16 +17,18 @@ package msg import ( "context" "encoding/json" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "time" - unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.RevokeMsgResp, error) { diff --git a/internal/rpc/msg/send.go b/internal/rpc/msg/send.go index 8ec54e7d8..3d15bfd1d 100644 --- a/internal/rpc/msg/send.go +++ b/internal/rpc/msg/send.go @@ -16,9 +16,9 @@ package msg import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" - promePkg "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/protocol/constant" pbConversation "github.com/OpenIMSDK/protocol/conversation" pbMsg "github.com/OpenIMSDK/protocol/msg" @@ -28,6 +28,8 @@ import ( "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + promePkg "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" ) func (m *msgServer) SendMsg(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, error error) { @@ -149,7 +151,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbMsg.SendMsgReq if err := m.messageVerification(ctx, req); err != nil { return nil, err } - var isSend = true + isSend := true isNotification := msgprocessor.IsNotificationByMsg(req.MsgData) if !isNotification { isSend, err = m.modifyMessageByUserMessageReceiveOpt( diff --git a/internal/rpc/msg/server.go b/internal/rpc/msg/server.go index fe795e0eb..3aa4033d7 100644 --- a/internal/rpc/msg/server.go +++ b/internal/rpc/msg/server.go @@ -19,16 +19,17 @@ import ( "google.golang.org/grpc" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/protocol/conversation" + "github.com/OpenIMSDK/protocol/msg" + "github.com/OpenIMSDK/tools/discoveryregistry" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/protocol/conversation" - "github.com/OpenIMSDK/protocol/msg" - "github.com/OpenIMSDK/tools/discoveryregistry" ) type ( diff --git a/internal/rpc/msg/statistics.go b/internal/rpc/msg/statistics.go index c5a4658bb..dbad0721f 100644 --- a/internal/rpc/msg/statistics.go +++ b/internal/rpc/msg/statistics.go @@ -18,10 +18,11 @@ import ( "context" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) func (m *msgServer) GetActiveUser(ctx context.Context, req *msg.GetActiveUserReq) (*msg.GetActiveUserResp, error) { diff --git a/internal/rpc/msg/sync_msg.go b/internal/rpc/msg/sync_msg.go index e91138d6c..390299dbd 100644 --- a/internal/rpc/msg/sync_msg.go +++ b/internal/rpc/msg/sync_msg.go @@ -16,6 +16,7 @@ package msg import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" @@ -115,41 +116,75 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil { return nil, err } + + var ( + sendIDs []string + recvIDs []string + groupIDs []string + sendMap = make(map[string]string) + recvMap = make(map[string]string) + groupMap = make(map[string]*sdkws.GroupInfo) + ) + for _, chatLog := range chatLogs { + if chatLog.SenderNickname == "" { + sendIDs = append(sendIDs, chatLog.SendID) + } + switch chatLog.SessionType { + case constant.SingleChatType: + recvIDs = append(recvIDs, chatLog.RecvID) + case constant.GroupChatType, constant.SuperGroupChatType: + groupIDs = append(groupIDs, chatLog.GroupID) + } + } + if len(sendIDs) != 0 { + sendInfos, err := m.User.GetUsersInfo(ctx, sendIDs) + if err != nil { + return nil, err + } + for _, sendInfo := range sendInfos { + sendMap[sendInfo.UserID] = sendInfo.Nickname + } + } + if len(recvIDs) != 0 { + recvInfos, err := m.User.GetUsersInfo(ctx, recvIDs) + if err != nil { + return nil, err + } + for _, recvInfo := range recvInfos { + recvMap[recvInfo.UserID] = recvInfo.Nickname + } + } + if len(groupIDs) != 0 { + groupInfos, err := m.Group.GetGroupInfos(ctx, groupIDs, true) + if err != nil { + return nil, err + } + for _, groupInfo := range groupInfos { + groupMap[groupInfo.GroupID] = groupInfo + } + } for _, chatLog := range chatLogs { pbChatLog := &msg.ChatLog{} utils.CopyStructFields(pbChatLog, chatLog) pbChatLog.SendTime = chatLog.SendTime pbChatLog.CreateTime = chatLog.CreateTime if chatLog.SenderNickname == "" { - sendUser, err := m.User.GetUserInfo(ctx, chatLog.SendID) - if err != nil { - return nil, err - } - pbChatLog.SenderNickname = sendUser.Nickname + pbChatLog.SenderNickname = sendMap[chatLog.SendID] } switch chatLog.SessionType { case constant.SingleChatType: - recvUser, err := m.User.GetUserInfo(ctx, chatLog.RecvID) - if err != nil { - return nil, err - } - pbChatLog.RecvNickname = recvUser.Nickname + pbChatLog.RecvNickname = recvMap[chatLog.RecvID] case constant.GroupChatType, constant.SuperGroupChatType: - group, err := m.Group.GetGroupInfo(ctx, chatLog.GroupID) - if err != nil { - return nil, err - } - pbChatLog.SenderFaceURL = group.FaceURL - pbChatLog.GroupMemberCount = group.MemberCount - pbChatLog.RecvID = group.GroupID - pbChatLog.GroupName = group.GroupName - pbChatLog.GroupOwner = group.OwnerUserID - pbChatLog.GroupType = group.GroupType + pbChatLog.SenderFaceURL = groupMap[chatLog.GroupID].FaceURL + pbChatLog.GroupMemberCount = groupMap[chatLog.GroupID].MemberCount + pbChatLog.RecvID = groupMap[chatLog.GroupID].GroupID + pbChatLog.GroupName = groupMap[chatLog.GroupID].GroupName + pbChatLog.GroupOwner = groupMap[chatLog.GroupID].OwnerUserID + pbChatLog.GroupType = groupMap[chatLog.GroupID].GroupType } resp.ChatLogs = append(resp.ChatLogs, pbChatLog) } - resp.ChatLogsNum = total return resp, nil } diff --git a/internal/rpc/msg/utils.go b/internal/rpc/msg/utils.go index 1579bcbef..9753a3e01 100644 --- a/internal/rpc/msg/utils.go +++ b/internal/rpc/msg/utils.go @@ -18,10 +18,11 @@ import ( "github.com/redis/go-redis/v9" "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) func isMessageHasReadEnabled(msgData *sdkws.MsgData) bool { diff --git a/internal/rpc/msg/verify.go b/internal/rpc/msg/verify.go index c588d6cf7..8fbc01095 100644 --- a/internal/rpc/msg/verify.go +++ b/internal/rpc/msg/verify.go @@ -20,12 +20,13 @@ import ( "strconv" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) var ExcludeContentType = []int{constant.HasReadReceipt} diff --git a/internal/rpc/third/s3.go b/internal/rpc/third/s3.go index 38b0eb03c..943cd5d54 100644 --- a/internal/rpc/third/s3.go +++ b/internal/rpc/third/s3.go @@ -16,15 +16,19 @@ package third import ( "context" + "strconv" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" + "github.com/OpenIMSDK/protocol/third" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func (t *thirdServer) PartLimit(ctx context.Context, req *third.PartLimitReq) (*third.PartLimitResp, error) { @@ -151,7 +155,21 @@ func (t *thirdServer) CompleteMultipartUpload(ctx context.Context, req *third.Co } func (t *thirdServer) AccessURL(ctx context.Context, req *third.AccessURLReq) (*third.AccessURLResp, error) { - expireTime, rawURL, err := t.s3dataBase.AccessURL(ctx, req.Name, t.defaultExpire) + opt := &s3.AccessURLOption{} + if len(req.Query) > 0 { + switch req.Query["type"] { + case "": + case "image": + opt.Image = &s3.Image{} + opt.Image.Format = req.Query["format"] + opt.Image.Width, _ = strconv.Atoi(req.Query["width"]) + opt.Image.Height, _ = strconv.Atoi(req.Query["height"]) + log.ZDebug(ctx, "AccessURL image", "name", req.Name, "option", opt.Image) + default: + return nil, errs.ErrArgs.Wrap("invalid query type") + } + } + expireTime, rawURL, err := t.s3dataBase.AccessURL(ctx, req.Name, t.defaultExpire, opt) if err != nil { return nil, err } diff --git a/internal/rpc/third/third.go b/internal/rpc/third/third.go index 555e9371c..4c3bd32f8 100644 --- a/internal/rpc/third/third.go +++ b/internal/rpc/third/third.go @@ -27,14 +27,15 @@ import ( "google.golang.org/grpc" + "github.com/OpenIMSDK/protocol/third" + "github.com/OpenIMSDK/tools/discoveryregistry" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/protocol/third" - "github.com/OpenIMSDK/tools/discoveryregistry" ) func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { @@ -48,6 +49,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e if apiURL[len(apiURL)-1] != '/' { apiURL += "/" } + apiURL += "object/" rdb, err := cache.NewRedis() if err != nil { return err diff --git a/internal/rpc/third/tool.go b/internal/rpc/third/tool.go index 3034de674..f81a7ccf2 100644 --- a/internal/rpc/third/tool.go +++ b/internal/rpc/third/tool.go @@ -18,10 +18,11 @@ import ( "context" "errors" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "strings" "unicode/utf8" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/protocol/third" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 53598db0b..10580798a 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -17,12 +17,20 @@ package user import ( "context" "errors" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" - "github.com/OpenIMSDK/tools/log" "strings" "time" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/protocol/sdkws" + "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/tools/tx" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" + + registry "github.com/OpenIMSDK/tools/discoveryregistry" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" @@ -31,16 +39,10 @@ import ( tablerelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/protocol/sdkws" - pbuser "github.com/OpenIMSDK/protocol/user" - registry "github.com/OpenIMSDK/tools/discoveryregistry" - "github.com/OpenIMSDK/tools/errs" - "github.com/OpenIMSDK/tools/tx" - - "google.golang.org/grpc" + pbuser "github.com/OpenIMSDK/protocol/user" "github.com/OpenIMSDK/tools/utils" + "google.golang.org/grpc" ) type userServer struct { @@ -250,18 +252,27 @@ func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDR // SubscribeOrCancelUsersStatus Subscribe online or cancel online users. func (s *userServer) SubscribeOrCancelUsersStatus(ctx context.Context, req *pbuser.SubscribeOrCancelUsersStatusReq) (resp *pbuser.SubscribeOrCancelUsersStatusResp, err error) { - err = s.UserDatabase.SubscribeOrCancelUsersStatus(ctx, req.UserID, req.UserIDs, req.Genre) - if err != nil { - return nil, err + if req.Genre == constant.SubscriberUser { + err = s.UserDatabase.SubscribeUsersStatus(ctx, req.UserID, req.UserIDs) + if err != nil { + return nil, err + } + var status []*pbuser.OnlineStatus + status, err = s.UserDatabase.GetUserStatus(ctx, req.UserIDs) + if err != nil { + return nil, err + } + return &pbuser.SubscribeOrCancelUsersStatusResp{StatusList: status}, nil + } else if req.Genre == constant.Unsubscribe { + err = s.UserDatabase.UnsubscribeUsersStatus(ctx, req.UserID, req.UserIDs) + if err != nil { + return nil, err + } } - //var status map[string][]string - //TODO 获取用户在线列表,返回订阅的用户的在线列表 - return &pbuser.SubscribeOrCancelUsersStatusResp{}, nil } func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp, err error) { - //TODO 是否加一个参数校验-判断req.userID的数量,每一个获取加一个限制,一次请求限制500? onlineStatusList, err := s.UserDatabase.GetUserStatus(ctx, req.UserIDs) if err != nil { return nil, err diff --git a/internal/tools/cron_task.go b/internal/tools/cron_task.go index a7333a5d4..0bc8b00a3 100644 --- a/internal/tools/cron_task.go +++ b/internal/tools/cron_task.go @@ -21,16 +21,18 @@ import ( "github.com/robfig/cron/v3" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) -func StartCronTask() error { +func StartTask() error { fmt.Println("cron task start, config", config.Config.ChatRecordsClearTime) msgTool, err := InitMsgTool() if err != nil { return err } + msgTool.ConvertTools() c := cron.New() var wg sync.WaitGroup wg.Add(1) diff --git a/internal/tools/msg.go b/internal/tools/msg.go index d13f4597a..19cb67943 100644 --- a/internal/tools/msg.go +++ b/internal/tools/msg.go @@ -24,13 +24,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" @@ -38,6 +31,14 @@ import ( "github.com/OpenIMSDK/tools/mw" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" ) type MsgTool struct { diff --git a/internal/tools/msg_doc_convert.go b/internal/tools/msg_doc_convert.go new file mode 100644 index 000000000..598d0dbcf --- /dev/null +++ b/internal/tools/msg_doc_convert.go @@ -0,0 +1,33 @@ +package tools + +import ( + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/tools/mcontext" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" +) + +func (c *MsgTool) ConvertTools() { + ctx := mcontext.NewCtx("convert") + conversationIDs, err := c.conversationDatabase.GetAllConversationIDs(ctx) + if err != nil { + log.ZError(ctx, "get all conversation ids failed", err) + return + } + for _, conversationID := range conversationIDs { + conversationIDs = append(conversationIDs, msgprocessor.GetNotificationConversationIDByConversationID(conversationID)) + } + userIDs, err := c.userDatabase.GetAllUserID(ctx, 0, 0) + if err != nil { + log.ZError(ctx, "get all user ids failed", err) + return + } + log.ZDebug(ctx, "all userIDs", "len userIDs", len(userIDs)) + for _, userID := range userIDs { + conversationIDs = append(conversationIDs, msgprocessor.GetConversationIDBySessionType(constant.SingleChatType, userID, userID)) + conversationIDs = append(conversationIDs, msgprocessor.GetNotificationConversationID(constant.SingleChatType, userID, userID)) + } + log.ZDebug(ctx, "all conversationIDs", "len userIDs", len(conversationIDs)) + c.msgDatabase.ConvertMsgsDocLen(ctx, conversationIDs) +} diff --git a/pkg/authverify/token.go b/pkg/authverify/token.go index 0d26b6b04..e508c75cb 100644 --- a/pkg/authverify/token.go +++ b/pkg/authverify/token.go @@ -1,14 +1,30 @@ +// Copyright © 2023 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package authverify import ( "context" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/tokenverify" "github.com/OpenIMSDK/tools/utils" "github.com/golang-jwt/jwt/v4" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) func Secret() jwt.Keyfunc { diff --git a/pkg/callbackstruct/group.go b/pkg/callbackstruct/group.go index 940356e41..8282b6546 100644 --- a/pkg/callbackstruct/group.go +++ b/pkg/callbackstruct/group.go @@ -15,8 +15,9 @@ package callbackstruct import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" common "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" ) type CallbackCommand string diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 39865b9f8..96ecc20c3 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" + config2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/spf13/cobra" diff --git a/pkg/common/cmd/rpc.go b/pkg/common/cmd/rpc.go index 9a00353be..1f6fe16a5 100644 --- a/pkg/common/cmd/rpc.go +++ b/pkg/common/cmd/rpc.go @@ -20,8 +20,9 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/startrpc" "github.com/OpenIMSDK/tools/discoveryregistry" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/startrpc" ) type RpcCmd struct { diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 1e0bbba16..638fbf17a 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -16,6 +16,7 @@ package config import ( "bytes" + "github.com/OpenIMSDK/tools/discoveryregistry" "gopkg.in/yaml.v3" ) @@ -119,6 +120,7 @@ type configStruct struct { AccessKeyID string `yaml:"accessKeyID"` SecretAccessKey string `yaml:"secretAccessKey"` SessionToken string `yaml:"sessionToken"` + SignEndpoint string `yaml:"signEndpoint"` } `yaml:"minio"` Cos struct { BucketURL string `yaml:"bucketURL"` diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index e3fd99b9f..8b7999b25 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -17,11 +17,12 @@ package config import ( _ "embed" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "os" "path/filepath" "runtime" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "gopkg.in/yaml.v3" "github.com/OpenIMSDK/protocol/constant" diff --git a/pkg/common/config/version b/pkg/common/config/version index 1c5ae5820..3a285c2be 100644 --- a/pkg/common/config/version +++ b/pkg/common/config/version @@ -1 +1 @@ -v3.0.0 \ No newline at end of file +v3.1.0 \ No newline at end of file diff --git a/pkg/common/convert/black.go b/pkg/common/convert/black.go index cae002ada..f0f74fbcc 100644 --- a/pkg/common/convert/black.go +++ b/pkg/common/convert/black.go @@ -17,9 +17,10 @@ package convert import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/sdkws" sdk "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func BlackDB2Pb( diff --git a/pkg/common/convert/conversation.go b/pkg/common/convert/conversation.go index 7eccad9b0..4c9a5ea4e 100644 --- a/pkg/common/convert/conversation.go +++ b/pkg/common/convert/conversation.go @@ -15,9 +15,10 @@ package convert import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func ConversationDB2Pb(conversationDB *relation.ConversationModel) *conversation.Conversation { diff --git a/pkg/common/convert/friend.go b/pkg/common/convert/friend.go index 322f9d10a..255334840 100644 --- a/pkg/common/convert/friend.go +++ b/pkg/common/convert/friend.go @@ -17,9 +17,10 @@ package convert import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func FriendPb2DB(friend *sdkws.FriendInfo) *relation.FriendModel { diff --git a/pkg/common/convert/group.go b/pkg/common/convert/group.go index efd2c3710..525f6ec2c 100644 --- a/pkg/common/convert/group.go +++ b/pkg/common/convert/group.go @@ -17,9 +17,10 @@ package convert import ( "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" pbGroup "github.com/OpenIMSDK/protocol/group" sdkws "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func Db2PbGroupInfo(m *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo { diff --git a/pkg/common/convert/msg.go b/pkg/common/convert/msg.go index 525d35f1c..7708d7535 100644 --- a/pkg/common/convert/msg.go +++ b/pkg/common/convert/msg.go @@ -15,8 +15,9 @@ package convert import ( - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) func MsgPb2DB(msg *sdkws.MsgData) *unrelation.MsgDataModel { diff --git a/pkg/common/convert/user.go b/pkg/common/convert/user.go index 28f4781e7..26c70bb51 100644 --- a/pkg/common/convert/user.go +++ b/pkg/common/convert/user.go @@ -17,8 +17,9 @@ package convert import ( "time" - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/sdkws" + + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) func UsersDB2Pb(users []*relationTb.UserModel) (result []*sdkws.UserInfo) { diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index 7f0290c8f..0f2eb0292 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -24,9 +24,10 @@ import ( "github.com/dtm-labs/rockscache" "github.com/redis/go-redis/v9" + "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/tools/utils" ) const ( diff --git a/pkg/common/db/cache/friend.go b/pkg/common/db/cache/friend.go index 698f1364c..1a156cdb2 100644 --- a/pkg/common/db/cache/friend.go +++ b/pkg/common/db/cache/friend.go @@ -21,8 +21,9 @@ import ( "github.com/dtm-labs/rockscache" "github.com/redis/go-redis/v9" - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) const ( diff --git a/pkg/common/db/cache/group.go b/pkg/common/db/cache/group.go index d72f06908..e2a3f0103 100644 --- a/pkg/common/db/cache/group.go +++ b/pkg/common/db/cache/group.go @@ -23,9 +23,10 @@ import ( "github.com/dtm-labs/rockscache" "github.com/redis/go-redis/v9" + "github.com/OpenIMSDK/tools/utils" + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" unrelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" - "github.com/OpenIMSDK/tools/utils" ) const ( diff --git a/pkg/common/db/cache/init_redis.go b/pkg/common/db/cache/init_redis.go index 69bc0d484..61273f49f 100644 --- a/pkg/common/db/cache/init_redis.go +++ b/pkg/common/db/cache/init_redis.go @@ -22,9 +22,10 @@ import ( "github.com/redis/go-redis/v9" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mw/specialerror" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) const ( diff --git a/pkg/common/db/cache/msg.go b/pkg/common/db/cache/msg.go index 953396fbe..30eb41ae9 100644 --- a/pkg/common/db/cache/msg.go +++ b/pkg/common/db/cache/msg.go @@ -16,23 +16,25 @@ package cache import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "strconv" "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "github.com/dtm-labs/rockscache" "github.com/OpenIMSDK/tools/errs" "github.com/gogo/protobuf/jsonpb" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" + "github.com/redis/go-redis/v9" ) diff --git a/pkg/common/db/cache/user.go b/pkg/common/db/cache/user.go index 5c76af22f..05374cc5f 100644 --- a/pkg/common/db/cache/user.go +++ b/pkg/common/db/cache/user.go @@ -17,10 +17,13 @@ package cache import ( "context" "encoding/json" - "github.com/OpenIMSDK/protocol/user" + "hash/crc32" "strconv" "time" + "github.com/OpenIMSDK/protocol/user" + "github.com/OpenIMSDK/tools/errs" + "github.com/dtm-labs/rockscache" "github.com/redis/go-redis/v9" @@ -33,7 +36,7 @@ const ( userGlobalRecvMsgOptKey = "USER_GLOBAL_RECV_MSG_OPT_KEY:" olineStatusKey = "ONLINE_STATUS:" userOlineStatusExpireTime = time.Second * 60 * 60 * 24 - statusMod = 500 + statusMod = 501 ) type UserCache interface { @@ -161,15 +164,12 @@ func (u *UserCacheRedis) getOnlineStatusKey(userID string) string { return olineStatusKey + userID } -// GetUserStatus get user status +// GetUserStatus get user status. func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) { var res []*user.OnlineStatus for _, userID := range userIDs { - UserIDNum, err := strconv.Atoi(userID) - if err != nil { - return nil, err - } - var modKey = strconv.Itoa(UserIDNum % statusMod) + UserIDNum := crc32.ChecksumIEEE([]byte(userID)) + modKey := strconv.Itoa(int(UserIDNum % statusMod)) var onlineStatus user.OnlineStatus key := olineStatusKey + modKey result, err := u.rdb.HGet(ctx, key, userID).Result() @@ -183,12 +183,12 @@ func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([ }) continue } else { - return nil, err + return nil, errs.Wrap(err) } } err = json.Unmarshal([]byte(result), &onlineStatus) if err != nil { - return nil, err + return nil, errs.Wrap(err) } onlineStatus.UserID = userID res = append(res, &onlineStatus) @@ -196,27 +196,24 @@ func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([ return res, nil } -// SetUserStatus Set the user status and save it in redis +// SetUserStatus Set the user status and save it in redis. func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { for _, status := range list { var isNewKey int64 - UserIDNum, err := strconv.Atoi(status.UserID) - if err != nil { - return err - } - var modKey = strconv.Itoa(UserIDNum % statusMod) + UserIDNum := crc32.ChecksumIEEE([]byte(status.UserID)) + modKey := strconv.Itoa(int(UserIDNum % statusMod)) key := olineStatusKey + modKey jsonData, err := json.Marshal(status) if err != nil { - return err + return errs.Wrap(err) } isNewKey, err = u.rdb.Exists(ctx, key).Result() if err != nil { - return err + return errs.Wrap(err) } _, err = u.rdb.HSet(ctx, key, status.UserID, string(jsonData)).Result() if err != nil { - return err + return errs.Wrap(err) } if isNewKey > 0 { u.rdb.Expire(ctx, key, userOlineStatusExpireTime) diff --git a/pkg/common/db/controller/auth.go b/pkg/common/db/controller/auth.go index d864e078b..f44263076 100644 --- a/pkg/common/db/controller/auth.go +++ b/pkg/common/db/controller/auth.go @@ -16,14 +16,16 @@ package controller import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "github.com/golang-jwt/jwt/v4" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/tokenverify" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" ) type AuthDatabase interface { diff --git a/pkg/common/db/controller/black.go b/pkg/common/db/controller/black.go index 767797eb1..4a239829f 100644 --- a/pkg/common/db/controller/black.go +++ b/pkg/common/db/controller/black.go @@ -17,10 +17,11 @@ package controller import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type BlackDatabase interface { diff --git a/pkg/common/db/controller/chatlog.go b/pkg/common/db/controller/chatlog.go index 37f620271..acf2642da 100644 --- a/pkg/common/db/controller/chatlog.go +++ b/pkg/common/db/controller/chatlog.go @@ -15,8 +15,9 @@ package controller import ( - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" pbMsg "github.com/OpenIMSDK/protocol/msg" + + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type ChatLogDatabase interface { diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 2829f963e..6c4998c59 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -16,15 +16,17 @@ package controller import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type ConversationDatabase interface { diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 0f9315c20..a1cb547bf 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -20,14 +20,15 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type FriendDatabase interface { @@ -208,6 +209,7 @@ func (f *friendDatabase) RefuseFriendRequest( if fr.HandleResult != 0 { return errs.ErrArgs.Wrap("the friend request has been processed") } + log.ZDebug(ctx, "refuse friend request", "friendRequest db", fr, "friendRequest arg", friendRequest) friendRequest.HandleResult = constant.FriendResponseRefuse friendRequest.HandleTime = time.Now() err = f.friendRequest.Update(ctx, friendRequest) diff --git a/pkg/common/db/controller/group.go b/pkg/common/db/controller/group.go index ba4ae18df..677916bb8 100644 --- a/pkg/common/db/controller/group.go +++ b/pkg/common/db/controller/group.go @@ -24,14 +24,15 @@ import ( "go.mongodb.org/mongo-driver/mongo" "gorm.io/gorm" + "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/tools/tx" + "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/tools/tx" - "github.com/OpenIMSDK/tools/utils" ) type GroupDatabase interface { @@ -385,8 +386,24 @@ func (g *groupDatabase) HandlerGroupRequest( handleResult int32, member *relationTb.GroupMemberModel, ) error { - cache := g.cache.NewCache() - if err := g.tx.Transaction(func(tx any) error { + //cache := g.cache.NewCache() + //if err := g.tx.Transaction(func(tx any) error { + // if err := g.groupRequestDB.NewTx(tx).UpdateHandler(ctx, groupID, userID, handledMsg, handleResult); err != nil { + // return err + // } + // if member != nil { + // if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationTb.GroupMemberModel{member}); err != nil { + // return err + // } + // cache = cache.DelGroupMembersHash(groupID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID) + // } + // return nil + //}); err != nil { + // return err + //} + //return cache.ExecDel(ctx) + + return g.tx.Transaction(func(tx any) error { if err := g.groupRequestDB.NewTx(tx).UpdateHandler(ctx, groupID, userID, handledMsg, handleResult); err != nil { return err } @@ -394,13 +411,12 @@ func (g *groupDatabase) HandlerGroupRequest( if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationTb.GroupMemberModel{member}); err != nil { return err } - cache = cache.DelGroupMembersHash(groupID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID) + if err := g.cache.NewCache().DelGroupMembersHash(groupID).DelGroupMembersInfo(groupID, member.UserID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID).ExecDel(ctx); err != nil { + return err + } } return nil - }); err != nil { - return err - } - return cache.ExecDel(ctx) + }) } func (g *groupDatabase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error { diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index 7c03eb8b6..70a2c5e0e 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -21,6 +21,9 @@ import ( "github.com/redis/go-redis/v9" + "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" @@ -28,8 +31,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" - "github.com/OpenIMSDK/tools/errs" - "github.com/OpenIMSDK/tools/log" "go.mongodb.org/mongo-driver/mongo" @@ -117,6 +118,7 @@ type CommonMsgDatabase interface { pageNumber int32, showNumber int32, ) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) + ConvertMsgsDocLen(ctx context.Context, conversationIDs []string) } func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheModel cache.MsgModel) CommonMsgDatabase { @@ -729,34 +731,21 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio delStruct.delDocIDs = append(delStruct.delDocIDs, msgDocModel.DocID) delStruct.minSeq = msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.Seq } else { - var hasMarkDelFlag bool var delMsgIndexs []int for i, MsgInfoModel := range msgDocModel.Msg { if MsgInfoModel != nil && MsgInfoModel.Msg != nil { if utils.GetCurrentTimestampByMill() > MsgInfoModel.Msg.SendTime+(remainTime*1000) { delMsgIndexs = append(delMsgIndexs, i) - hasMarkDelFlag = true - } else { - // 到本条消息不需要删除, minSeq置为这条消息的seq - if len(delStruct.delDocIDs) > 0 { - log.ZDebug(ctx, "delete docs", "delDocIDs", delStruct.delDocIDs) - } - if err := db.msgDocDatabase.DeleteDocs(ctx, delStruct.delDocIDs); err != nil { - return 0, err - } - if hasMarkDelFlag { - log.ZDebug(ctx, "delete msg by index", "delMsgIndexs", delMsgIndexs, "docID", msgDocModel.DocID) - // mark del all delMsgIndexs - if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil { - return delStruct.getSetMinSeq(), err - } - } - return MsgInfoModel.Msg.Seq, nil } } } + if len(delMsgIndexs) > 0 { + if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil { + log.ZError(ctx, "deleteMsgRecursion DeleteMsgsInOneDocByIndex failed", err, "conversationID", conversationID, "index", index) + } + delStruct.minSeq = int64(msgDocModel.Msg[delMsgIndexs[len(delMsgIndexs)-1]].Msg.Seq) + } } - // 继续递归 index+1 seq, err := db.deleteMsgRecursion(ctx, conversationID, index+1, delStruct, remainTime) return seq, err } @@ -960,7 +949,14 @@ func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.Searc return 0, nil, err } for _, msg := range msgs { + if msg.IsRead { + msg.Msg.IsRead = true + } totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg)) } return total, totalMsgs, nil } + +func (db *commonMsgDatabase) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string) { + db.msgDocDatabase.ConvertMsgsDocLen(ctx, conversationIDs) +} diff --git a/pkg/common/db/controller/s3.go b/pkg/common/db/controller/s3.go index 220e8e070..1ced644c2 100644 --- a/pkg/common/db/controller/s3.go +++ b/pkg/common/db/controller/s3.go @@ -30,7 +30,7 @@ type S3Database interface { AuthSign(ctx context.Context, uploadID string, partNumbers []int) (*s3.AuthSignResult, error) InitiateMultipartUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*cont.InitiateUploadResult, error) CompleteMultipartUpload(ctx context.Context, uploadID string, parts []string) (*cont.UploadResult, error) - AccessURL(ctx context.Context, name string, expire time.Duration) (time.Time, string, error) + AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (time.Time, string, error) SetObject(ctx context.Context, info *relation.ObjectModel) error } @@ -70,14 +70,19 @@ func (s *s3Database) SetObject(ctx context.Context, info *relation.ObjectModel) return s.obj.SetObject(ctx, info) } -func (s *s3Database) AccessURL(ctx context.Context, name string, expire time.Duration) (time.Time, string, error) { +func (s *s3Database) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (time.Time, string, error) { obj, err := s.obj.Take(ctx, name) if err != nil { return time.Time{}, "", err } - opt := &s3.AccessURLOption{ - ContentType: obj.ContentType, - Filename: filepath.Base(obj.Name), + if opt == nil { + opt = &s3.AccessURLOption{} + } + if opt.ContentType == "" { + opt.ContentType = obj.ContentType + } + if opt.Filename == "" { + opt.Filename = filepath.Base(obj.Name) } expireTime := time.Now().Add(expire) rawURL, err := s.s3.AccessURL(ctx, obj.Key, expire, opt) diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go index 5b303ebd7..2957befee 100644 --- a/pkg/common/db/controller/user.go +++ b/pkg/common/db/controller/user.go @@ -16,16 +16,18 @@ package controller import ( "context" - unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" - "github.com/OpenIMSDK/protocol/constant" - "github.com/OpenIMSDK/protocol/user" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/protocol/user" + + unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" + "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/tx" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type UserDatabase interface { @@ -51,8 +53,10 @@ type UserDatabase interface { CountTotal(ctx context.Context, before *time.Time) (int64, error) // CountRangeEverydayTotal Get the user increment in the range CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) - //SubscribeOrCancelUsersStatus Subscribe or unsubscribe a user's presence status - SubscribeOrCancelUsersStatus(ctx context.Context, userID string, userIDs []string, genre int32) error + //SubscribeUsersStatus Subscribe a user's presence status + SubscribeUsersStatus(ctx context.Context, userID string, userIDs []string) error + // UnsubscribeUsersStatus unsubscribe a user's presence status + UnsubscribeUsersStatus(ctx context.Context, userID string, userIDs []string) error // GetAllSubscribeList Get a list of all subscriptions GetAllSubscribeList(ctx context.Context, userID string) ([]string, error) // GetSubscribedList Get all subscribed lists @@ -161,53 +165,58 @@ func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist boo return false, nil } -// GetAllUserID Get all user IDs +// GetAllUserID Get all user IDs. func (u *userDatabase) GetAllUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, err error) { return u.userDB.GetAllUserID(ctx, pageNumber, showNumber) } -// CountTotal Get the total number of users +// CountTotal Get the total number of users. func (u *userDatabase) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) { return u.userDB.CountTotal(ctx, before) } -// CountRangeEverydayTotal Get the user increment in the range +// CountRangeEverydayTotal Get the user increment in the range. func (u *userDatabase) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) { return u.userDB.CountRangeEverydayTotal(ctx, start, end) } -//SubscribeOrCancelUsersStatus Subscribe or unsubscribe a user's presence status -func (u *userDatabase) SubscribeOrCancelUsersStatus(ctx context.Context, userID string, userIDs []string, genre int32) error { - var err error - if genre == constant.SubscriberUser { - err = u.mongoDB.AddSubscriptionList(ctx, userID, userIDs) - } else if genre == constant.Unsubscribe { - err = u.mongoDB.UnsubscriptionList(ctx, userID, userIDs) - } +// SubscribeUsersStatus Subscribe or unsubscribe a user's presence status +func (u *userDatabase) SubscribeUsersStatus(ctx context.Context, userID string, userIDs []string) error { + err := u.mongoDB.AddSubscriptionList(ctx, userID, userIDs) + return err +} + +// UnsubscribeUsersStatus unsubscribe a user's presence status +func (u *userDatabase) UnsubscribeUsersStatus(ctx context.Context, userID string, userIDs []string) error { + err := u.mongoDB.UnsubscriptionList(ctx, userID, userIDs) return err } // GetAllSubscribeList Get a list of all subscriptions. func (u *userDatabase) GetAllSubscribeList(ctx context.Context, userID string) ([]string, error) { - - //TODO 获取所有订阅 - return nil, nil + list, err := u.mongoDB.GetAllSubscribeList(ctx, userID) + if err != nil { + return nil, err + } + return list, nil } -// GetSubscribedList Get all subscribed lists +// GetSubscribedList Get all subscribed lists. func (u *userDatabase) GetSubscribedList(ctx context.Context, userID string) ([]string, error) { - - //TODO 获取所有被订阅 - return nil, nil + list, err := u.mongoDB.GetSubscribedList(ctx, userID) + if err != nil { + return nil, err + } + return list, nil } -// GetUserStatus get user status +// GetUserStatus get user status. func (u *userDatabase) GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) { onlineStatusList, err := u.cache.GetUserStatus(ctx, userIDs) return onlineStatusList, err } -// SetUserStatus Set the user status and save it in redis +// SetUserStatus Set the user status and save it in redis. func (u *userDatabase) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { return u.cache.SetUserStatus(ctx, list) } diff --git a/pkg/common/db/localcache/conversation.go b/pkg/common/db/localcache/conversation.go index 98720fe3a..e1243e4c1 100644 --- a/pkg/common/db/localcache/conversation.go +++ b/pkg/common/db/localcache/conversation.go @@ -18,8 +18,9 @@ import ( "context" "sync" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/conversation" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type ConversationLocalCache struct { diff --git a/pkg/common/db/localcache/group.go b/pkg/common/db/localcache/group.go index 57cea7245..093353c86 100644 --- a/pkg/common/db/localcache/group.go +++ b/pkg/common/db/localcache/group.go @@ -18,9 +18,10 @@ import ( "context" "sync" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/tools/errs" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type GroupLocalCache struct { diff --git a/pkg/common/db/relation/black_model.go b/pkg/common/db/relation/black_model.go index eede403b1..9684b6f77 100644 --- a/pkg/common/db/relation/black_model.go +++ b/pkg/common/db/relation/black_model.go @@ -21,8 +21,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type BlackGorm struct { diff --git a/pkg/common/db/relation/chat_log_model.go b/pkg/common/db/relation/chat_log_model.go index 76ed9be62..8ffab26ab 100644 --- a/pkg/common/db/relation/chat_log_model.go +++ b/pkg/common/db/relation/chat_log_model.go @@ -20,11 +20,12 @@ import ( "google.golang.org/protobuf/proto" "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/constant" pbMsg "github.com/OpenIMSDK/protocol/msg" sdkws "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type ChatLogGorm struct { diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index 0efca79aa..f58ac6e22 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -19,9 +19,10 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type ConversationGorm struct { diff --git a/pkg/common/db/relation/friend_model.go b/pkg/common/db/relation/friend_model.go index 4b119c1f8..4ab77132d 100644 --- a/pkg/common/db/relation/friend_model.go +++ b/pkg/common/db/relation/friend_model.go @@ -19,8 +19,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type FriendGorm struct { diff --git a/pkg/common/db/relation/friend_request_model.go b/pkg/common/db/relation/friend_request_model.go index d17cc680b..689b31668 100644 --- a/pkg/common/db/relation/friend_request_model.go +++ b/pkg/common/db/relation/friend_request_model.go @@ -19,8 +19,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type FriendRequestGorm struct { @@ -70,10 +71,13 @@ func (f *FriendRequestGorm) UpdateByMap( // 更新记录 (非零值). func (f *FriendRequestGorm) Update(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) { + fr2 := *friendRequest + fr2.FromUserID = "" + fr2.ToUserID = "" return utils.Wrap( f.db(ctx). Where("from_user_id = ? AND to_user_id =?", friendRequest.FromUserID, friendRequest.ToUserID). - Updates(friendRequest). + Updates(fr2). Error, "", ) diff --git a/pkg/common/db/relation/group_member_model.go b/pkg/common/db/relation/group_member_model.go index da6a58398..57b2d33e7 100644 --- a/pkg/common/db/relation/group_member_model.go +++ b/pkg/common/db/relation/group_member_model.go @@ -19,10 +19,11 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/ormutil" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) var _ relation.GroupMemberModelInterface = (*GroupMemberGorm)(nil) diff --git a/pkg/common/db/relation/group_model.go b/pkg/common/db/relation/group_model.go index 853f5dccd..13e96b611 100644 --- a/pkg/common/db/relation/group_model.go +++ b/pkg/common/db/relation/group_model.go @@ -22,10 +22,11 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/ormutil" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) var _ relation.GroupModelInterface = (*GroupGorm)(nil) diff --git a/pkg/common/db/relation/group_request_model.go b/pkg/common/db/relation/group_request_model.go index 7c0497aaf..05f94c34b 100644 --- a/pkg/common/db/relation/group_request_model.go +++ b/pkg/common/db/relation/group_request_model.go @@ -21,8 +21,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type GroupRequestGorm struct { diff --git a/pkg/common/db/relation/meta_db.go b/pkg/common/db/relation/meta_db.go index 60e4a5464..6ab980120 100644 --- a/pkg/common/db/relation/meta_db.go +++ b/pkg/common/db/relation/meta_db.go @@ -33,5 +33,6 @@ func NewMetaDB(db *gorm.DB, table any) *MetaDB { } func (g *MetaDB) db(ctx context.Context) *gorm.DB { - return g.DB.WithContext(ctx).Model(g.table) + db := g.DB.WithContext(ctx).Model(g.table) + return db } diff --git a/pkg/common/db/relation/mysql_init.go b/pkg/common/db/relation/mysql_init.go index 9b8188ac4..9e06a9815 100644 --- a/pkg/common/db/relation/mysql_init.go +++ b/pkg/common/db/relation/mysql_init.go @@ -21,11 +21,12 @@ import ( mysqlDriver "github.com/go-sql-driver/mysql" "gorm.io/driver/mysql" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mw/specialerror" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "gorm.io/gorm" "gorm.io/gorm/logger" ) diff --git a/pkg/common/db/relation/object_model.go b/pkg/common/db/relation/object_model.go index 02ba0bcf0..8a97a49d5 100644 --- a/pkg/common/db/relation/object_model.go +++ b/pkg/common/db/relation/object_model.go @@ -19,8 +19,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/errs" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type ObjectInfoGorm struct { diff --git a/pkg/common/db/relation/user_model.go b/pkg/common/db/relation/user_model.go index b7c592eeb..758a62037 100644 --- a/pkg/common/db/relation/user_model.go +++ b/pkg/common/db/relation/user_model.go @@ -22,8 +22,9 @@ import ( "gorm.io/gorm" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" ) type UserGorm struct { @@ -85,7 +86,11 @@ func (u *UserGorm) Page( // 获取所有用户ID. func (u *UserGorm) GetAllUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, err error) { - return userIDs, errs.Wrap(u.db(ctx).Limit(int(showNumber)).Offset(int((pageNumber-1)*showNumber)).Pluck("user_id", &userIDs).Error) + if pageNumber == 0 || showNumber == 0 { + return userIDs, errs.Wrap(u.db(ctx).Pluck("user_id", &userIDs).Error) + } else { + return userIDs, errs.Wrap(u.db(ctx).Limit(int(showNumber)).Offset(int((pageNumber-1)*showNumber)).Pluck("user_id", &userIDs).Error) + } } func (u *UserGorm) GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error) { diff --git a/pkg/common/db/s3/cont/controller.go b/pkg/common/db/s3/cont/controller.go index 01dbc787f..891ecf38e 100644 --- a/pkg/common/db/s3/cont/controller.go +++ b/pkg/common/db/s3/cont/controller.go @@ -26,9 +26,10 @@ import ( "github.com/google/uuid" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" ) func New(impl s3.Interface) *Controller { @@ -256,5 +257,9 @@ func (c *Controller) IsNotFound(err error) bool { } func (c *Controller) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { + if opt.Image != nil { + opt.Filename = "" + opt.ContentType = "" + } return c.impl.AccessURL(ctx, name, expire, opt) } diff --git a/pkg/common/db/s3/cos/cos.go b/pkg/common/db/s3/cos/cos.go index cfdaaa5e4..32f213161 100644 --- a/pkg/common/db/s3/cos/cos.go +++ b/pkg/common/db/s3/cos/cos.go @@ -36,6 +36,19 @@ const ( maxNumSize = 1000 ) +const ( + imagePng = "png" + imageJpg = "jpg" + imageJpeg = "jpeg" + imageGif = "gif" + imageWebp = "webp" +) + +const ( + videoSnapshotImagePng = "png" + videoSnapshotImageJpg = "jpg" +) + func NewCos() (s3.Interface, error) { conf := config.Config.Object.Cos u, err := url.Parse(conf.BucketURL) @@ -248,19 +261,44 @@ func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name strin } func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { - var option *cos.PresignedURLOptions + var imageMogr string + var option cos.PresignedURLOptions if opt != nil { query := make(url.Values) + if opt.Image != nil { + // https://cloud.tencent.com/document/product/436/44880 + style := make([]string, 0, 2) + wh := make([]string, 2) + if opt.Image.Width > 0 { + wh[0] = strconv.Itoa(opt.Image.Width) + } + if opt.Image.Height > 0 { + wh[1] = strconv.Itoa(opt.Image.Height) + } + if opt.Image.Width > 0 || opt.Image.Height > 0 { + style = append(style, strings.Join(wh, "x")) + } + switch opt.Image.Format { + case + imagePng, + imageJpg, + imageJpeg, + imageGif, + imageWebp: + style = append(style, "format/"+opt.Image.Format) + } + if len(style) > 0 { + imageMogr = "&imageMogr2/thumbnail/" + strings.Join(style, "/") + "/ignore-error/1" + } + } if opt.ContentType != "" { query.Set("response-content-type", opt.ContentType) } if opt.Filename != "" { - query.Set("response-content-disposition", `attachment; filename="`+opt.Filename+`"`) + query.Set("response-content-disposition", `attachment; filename=`+strconv.Quote(opt.Filename)) } if len(query) > 0 { - option = &cos.PresignedURLOptions{ - Query: &query, - } + option.Query = &query } } if expire <= 0 { @@ -268,9 +306,13 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, } else if expire < time.Second { expire = time.Second } - rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, option) + rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, &option) if err != nil { return "", err } - return rawURL.String(), nil + urlStr := rawURL.String() + if imageMogr != "" { + urlStr += imageMogr + } + return urlStr, nil } diff --git a/pkg/common/db/s3/minio/image.go b/pkg/common/db/s3/minio/image.go new file mode 100644 index 000000000..62d87551e --- /dev/null +++ b/pkg/common/db/s3/minio/image.go @@ -0,0 +1,106 @@ +package minio + +import ( + "image" + _ "image/gif" + _ "image/jpeg" + _ "image/png" + "io" + + _ "golang.org/x/image/bmp" + _ "golang.org/x/image/tiff" + _ "golang.org/x/image/webp" +) + +const ( + formatPng = "png" + formatJpeg = "jpeg" + formatJpg = "jpg" + formatGif = "gif" +) + +func ImageStat(reader io.Reader) (image.Image, string, error) { + return image.Decode(reader) +} + +func ImageWidthHeight(img image.Image) (int, int) { + bounds := img.Bounds().Max + return bounds.X, bounds.Y +} + +func resizeImage(img image.Image, maxWidth, maxHeight int) image.Image { + bounds := img.Bounds() + imgWidth := bounds.Max.X + imgHeight := bounds.Max.Y + + // 计算缩放比例 + scaleWidth := float64(maxWidth) / float64(imgWidth) + scaleHeight := float64(maxHeight) / float64(imgHeight) + + // 如果都为0,则不缩放,返回原始图片 + if maxWidth == 0 && maxHeight == 0 { + return img + } + + // 如果宽度和高度都大于0,则选择较小的缩放比例,以保持宽高比 + if maxWidth > 0 && maxHeight > 0 { + scale := scaleWidth + if scaleHeight < scaleWidth { + scale = scaleHeight + } + + // 计算缩略图尺寸 + thumbnailWidth := int(float64(imgWidth) * scale) + thumbnailHeight := int(float64(imgHeight) * scale) + + // 使用"image"库的Resample方法生成缩略图 + thumbnail := image.NewRGBA(image.Rect(0, 0, thumbnailWidth, thumbnailHeight)) + for y := 0; y < thumbnailHeight; y++ { + for x := 0; x < thumbnailWidth; x++ { + srcX := int(float64(x) / scale) + srcY := int(float64(y) / scale) + thumbnail.Set(x, y, img.At(srcX, srcY)) + } + } + + return thumbnail + } + + // 如果只指定了宽度或高度,则根据最大不超过的规则生成缩略图 + if maxWidth > 0 { + thumbnailWidth := maxWidth + thumbnailHeight := int(float64(imgHeight) * scaleWidth) + + // 使用"image"库的Resample方法生成缩略图 + thumbnail := image.NewRGBA(image.Rect(0, 0, thumbnailWidth, thumbnailHeight)) + for y := 0; y < thumbnailHeight; y++ { + for x := 0; x < thumbnailWidth; x++ { + srcX := int(float64(x) / scaleWidth) + srcY := int(float64(y) / scaleWidth) + thumbnail.Set(x, y, img.At(srcX, srcY)) + } + } + + return thumbnail + } + + if maxHeight > 0 { + thumbnailWidth := int(float64(imgWidth) * scaleHeight) + thumbnailHeight := maxHeight + + // 使用"image"库的Resample方法生成缩略图 + thumbnail := image.NewRGBA(image.Rect(0, 0, thumbnailWidth, thumbnailHeight)) + for y := 0; y < thumbnailHeight; y++ { + for x := 0; x < thumbnailWidth; x++ { + srcX := int(float64(x) / scaleHeight) + srcY := int(float64(y) / scaleHeight) + thumbnail.Set(x, y, img.At(srcX, srcY)) + } + } + + return thumbnail + } + + // 默认情况下,返回原始图片 + return img +} diff --git a/pkg/common/db/s3/minio/minio.go b/pkg/common/db/s3/minio/minio.go index bb6e6ce24..9137f7b75 100644 --- a/pkg/common/db/s3/minio/minio.go +++ b/pkg/common/db/s3/minio/minio.go @@ -15,16 +15,28 @@ package minio import ( + "bytes" "context" + "encoding/json" "errors" "fmt" + "image" + "image/gif" + "image/jpeg" + "image/png" + "io" "net/http" "net/url" + "path" + "path/filepath" + "reflect" "strconv" "strings" "sync" "time" + "unsafe" + "github.com/OpenIMSDK/tools/log" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/signer" @@ -43,6 +55,13 @@ const ( maxNumSize = 10000 ) +const ( + maxImageWidth = 1024 + maxImageHeight = 1024 + maxImageSize = 1024 * 1024 * 50 + pathInfo = "openim/thumbnail" +) + func NewMinio() (s3.Interface, error) { conf := config.Config.Object.Minio u, err := url.Parse(conf.Endpoint) @@ -60,11 +79,26 @@ func NewMinio() (s3.Interface, error) { m := &Minio{ bucket: conf.Bucket, bucketURL: conf.Endpoint + "/" + conf.Bucket + "/", - opts: opts, core: &minio.Core{Client: client}, lock: &sync.Mutex{}, init: false, } + if conf.SignEndpoint == "" || conf.SignEndpoint == conf.Endpoint { + m.sign = m.core.Client + } else { + su, err := url.Parse(conf.SignEndpoint) + if err != nil { + return nil, err + } + m.opts = &minio.Options{ + Creds: credentials.NewStaticV4(conf.AccessKeyID, conf.SecretAccessKey, conf.SessionToken), + Secure: su.Scheme == "https", + } + m.sign, err = minio.New(su.Host, m.opts) + if err != nil { + return nil, err + } + } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if err := m.initMinio(ctx); err != nil { @@ -76,8 +110,10 @@ func NewMinio() (s3.Interface, error) { type Minio struct { bucket string bucketURL string + location string opts *minio.Options core *minio.Core + sign *minio.Client lock sync.Locker init bool } @@ -91,15 +127,43 @@ func (m *Minio) initMinio(ctx context.Context) error { if m.init { return nil } - exists, err := m.core.Client.BucketExists(ctx, config.Config.Object.Minio.Bucket) + conf := config.Config.Object.Minio + exists, err := m.core.Client.BucketExists(ctx, conf.Bucket) if err != nil { return fmt.Errorf("check bucket exists error: %w", err) } if !exists { - if err := m.core.Client.MakeBucket(ctx, config.Config.Object.Minio.Bucket, minio.MakeBucketOptions{}); err != nil { + if err := m.core.Client.MakeBucket(ctx, conf.Bucket, minio.MakeBucketOptions{}); err != nil { return fmt.Errorf("make bucket error: %w", err) } } + m.location, err = m.core.Client.GetBucketLocation(ctx, conf.Bucket) + if err != nil { + return err + } + func() { + if conf.SignEndpoint == "" || conf.SignEndpoint == conf.Endpoint { + return + } + defer func() { + if r := recover(); r != nil { + m.sign = m.core.Client + log.ZWarn( + context.Background(), + "set sign bucket location cache panic", + errors.New("failed to get private field value"), + "recover", + fmt.Sprintf("%+v", r), + "development version", + "github.com/minio/minio-go/v7 v7.0.61", + ) + } + }() + blc := reflect.ValueOf(m.sign).Elem().FieldByName("bucketLocCache") + vblc := reflect.New(reflect.PtrTo(blc.Type())) + *(*unsafe.Pointer)(vblc.UnsafePointer()) = unsafe.Pointer(blc.UnsafeAddr()) + vblc.Elem().Elem().Interface().(interface{ Set(string, string) }).Set(conf.Bucket, m.location) + }() m.init = true return nil } @@ -191,7 +255,7 @@ func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expi return nil, err } request.Header.Set("X-Amz-Content-Sha256", unsignedPayload) - request = signer.SignV4Trailer(*request, creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, "us-east-1", nil) + request = signer.SignV4Trailer(*request, creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, m.location, nil) result.Parts[i] = s3.SignPart{ PartNumber: partNumber, URL: request.URL.String(), @@ -206,7 +270,7 @@ func (m *Minio) PresignedPutObject(ctx context.Context, name string, expire time if err := m.initMinio(ctx); err != nil { return "", err } - rawURL, err := m.core.Client.PresignedPutObject(ctx, m.bucket, name, expire) + rawURL, err := m.sign.PresignedPutObject(ctx, m.bucket, name, expire) if err != nil { return "", err } @@ -303,6 +367,19 @@ func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name str return res, nil } +func (m *Minio) presignedGetObject(ctx context.Context, name string, expire time.Duration, query url.Values) (string, error) { + if expire <= 0 { + expire = time.Hour * 24 * 365 * 99 // 99 years + } else if expire < time.Second { + expire = time.Second + } + rawURL, err := m.sign.PresignedGetObject(ctx, m.bucket, name, expire, query) + if err != nil { + return "", err + } + return rawURL.String(), nil +} + func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { if err := m.initMinio(ctx); err != nil { return "", err @@ -313,17 +390,123 @@ func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration reqParams.Set("response-content-type", opt.ContentType) } if opt.Filename != "" { - reqParams.Set("response-content-disposition", `attachment; filename="`+opt.Filename+`"`) + reqParams.Set("response-content-disposition", `attachment; filename=`+strconv.Quote(opt.Filename)) } } - if expire <= 0 { - expire = time.Hour * 24 * 365 * 99 // 99 years - } else if expire < time.Second { - expire = time.Second + if opt.Image == nil || (opt.Image.Width < 0 && opt.Image.Height < 0 && opt.Image.Format == "") || (opt.Image.Width > maxImageWidth || opt.Image.Height > maxImageHeight) { + return m.presignedGetObject(ctx, name, expire, reqParams) } - u, err := m.core.Client.PresignedGetObject(ctx, m.bucket, name, expire, reqParams) + fileInfo, err := m.StatObject(ctx, name) if err != nil { return "", err } - return u.String(), nil + if fileInfo.Size > maxImageSize { + return "", errors.New("file size too large") + } + objectInfoPath := path.Join(pathInfo, fileInfo.ETag, "image.json") + var ( + img image.Image + info minioImageInfo + ) + data, err := m.getObjectData(ctx, objectInfoPath, 1024) + if err == nil { + if err := json.Unmarshal(data, &info); err != nil { + return "", fmt.Errorf("unmarshal minio image info.json error: %w", err) + } + if info.NotImage { + return "", errors.New("not image") + } + } else if m.IsNotFound(err) { + reader, err := m.core.Client.GetObject(ctx, m.bucket, name, minio.GetObjectOptions{}) + if err != nil { + return "", err + } + defer reader.Close() + imageInfo, format, err := ImageStat(reader) + if err == nil { + info.NotImage = false + info.Format = format + info.Width, info.Height = ImageWidthHeight(imageInfo) + img = imageInfo + } else { + info.NotImage = true + } + data, err := json.Marshal(&info) + if err != nil { + return "", err + } + if _, err := m.core.Client.PutObject(ctx, m.bucket, objectInfoPath, bytes.NewReader(data), int64(len(data)), minio.PutObjectOptions{}); err != nil { + return "", err + } + } else { + return "", err + } + if opt.Image.Width > info.Width || opt.Image.Width <= 0 { + opt.Image.Width = info.Width + } + if opt.Image.Height > info.Height || opt.Image.Height <= 0 { + opt.Image.Height = info.Height + } + opt.Image.Format = strings.ToLower(opt.Image.Format) + if opt.Image.Format == formatJpg { + opt.Image.Format = formatJpeg + } + switch opt.Image.Format { + case formatPng: + case formatJpeg: + case formatGif: + default: + if info.Format == formatGif { + opt.Image.Format = formatGif + } else { + opt.Image.Format = formatJpeg + } + } + reqParams.Set("response-content-type", "image/"+opt.Image.Format) + if opt.Image.Width == info.Width && opt.Image.Height == info.Height && opt.Image.Format == info.Format { + return m.presignedGetObject(ctx, name, expire, reqParams) + } + cacheKey := filepath.Join(pathInfo, fileInfo.ETag, fmt.Sprintf("image_w%d_h%d.%s", opt.Image.Width, opt.Image.Height, opt.Image.Format)) + if _, err := m.core.Client.StatObject(ctx, m.bucket, cacheKey, minio.StatObjectOptions{}); err == nil { + return m.presignedGetObject(ctx, cacheKey, expire, reqParams) + } else if !m.IsNotFound(err) { + return "", err + } + if img == nil { + reader, err := m.core.Client.GetObject(ctx, m.bucket, name, minio.GetObjectOptions{}) + if err != nil { + return "", err + } + defer reader.Close() + img, _, err = ImageStat(reader) + if err != nil { + return "", err + } + } + thumbnail := resizeImage(img, opt.Image.Width, opt.Image.Height) + buf := bytes.NewBuffer(nil) + switch opt.Image.Format { + case formatPng: + err = png.Encode(buf, thumbnail) + case formatJpeg: + err = jpeg.Encode(buf, thumbnail, nil) + case formatGif: + err = gif.Encode(buf, thumbnail, nil) + } + if _, err := m.core.Client.PutObject(ctx, m.bucket, cacheKey, buf, int64(buf.Len()), minio.PutObjectOptions{}); err != nil { + return "", err + } + return m.presignedGetObject(ctx, cacheKey, expire, reqParams) +} + +func (m *Minio) getObjectData(ctx context.Context, name string, limit int64) ([]byte, error) { + object, err := m.core.Client.GetObject(ctx, m.bucket, name, minio.GetObjectOptions{}) + if err != nil { + return nil, err + } + defer object.Close() + if limit < 0 { + return io.ReadAll(object) + } + return io.ReadAll(io.LimitReader(object, 1024)) } diff --git a/pkg/common/db/s3/minio/struct.go b/pkg/common/db/s3/minio/struct.go new file mode 100644 index 000000000..8200a67b1 --- /dev/null +++ b/pkg/common/db/s3/minio/struct.go @@ -0,0 +1,8 @@ +package minio + +type minioImageInfo struct { + NotImage bool `json:"notImage,omitempty"` + Width int `json:"width,omitempty"` + Height int `json:"height,omitempty"` + Format string `json:"format,omitempty"` +} diff --git a/pkg/common/db/s3/oss/oss.go b/pkg/common/db/s3/oss/oss.go index 774150389..d84cad1c6 100644 --- a/pkg/common/db/s3/oss/oss.go +++ b/pkg/common/db/s3/oss/oss.go @@ -36,6 +36,19 @@ const ( maxNumSize = 10000 ) +const ( + imagePng = "png" + imageJpg = "jpg" + imageJpeg = "jpeg" + imageGif = "gif" + imageWebp = "webp" +) + +const ( + videoSnapshotImagePng = "png" + videoSnapshotImageJpg = "jpg" +) + func NewOSS() (s3.Interface, error) { conf := config.Config.Object.Oss if conf.BucketURL == "" { @@ -139,7 +152,7 @@ func (o *OSS) AuthSign(ctx context.Context, uploadID string, name string, expire } for i, partNumber := range partNumbers { rawURL := fmt.Sprintf(`%s%s?partNumber=%d&uploadId=%s`, o.bucketURL, name, partNumber, uploadID) - request, err := http.NewRequestWithContext(ctx, http.MethodPut, rawURL, nil) + request, err := http.NewRequest(http.MethodPut, rawURL, nil) if err != nil { return nil, err } @@ -150,12 +163,7 @@ func (o *OSS) AuthSign(ctx context.Context, uploadID string, name string, expire request.Header.Set(oss.HTTPHeaderHost, request.Host) request.Header.Set(oss.HTTPHeaderDate, now) request.Header.Set(oss.HttpHeaderOssDate, now) - authorization := fmt.Sprintf( - `OSS %s:%s`, - o.credentials.GetAccessKeyID(), - o.getSignedStr(request, fmt.Sprintf(`/%s/%s?partNumber=%d&uploadId=%s`, o.bucket.BucketName, name, partNumber, uploadID), o.credentials.GetAccessKeySecret()), - ) - request.Header.Set(oss.HTTPHeaderAuthorization, authorization) + ossSignHeader(o.bucket.Client.Conn, request, fmt.Sprintf(`/%s/%s?partNumber=%d&uploadId=%s`, o.bucket.BucketName, name, partNumber, uploadID)) delete(request.Header, oss.HTTPHeaderDate) result.Parts[i] = s3.SignPart{ PartNumber: partNumber, @@ -266,11 +274,36 @@ func (o *OSS) ListUploadedParts(ctx context.Context, uploadID string, name strin func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { var opts []oss.Option if opt != nil { + if opt.Image != nil { + // 文档地址: https://help.aliyun.com/zh/oss/user-guide/resize-images-4?spm=a2c4g.11186623.0.0.4b3b1e4fWW6yji + var format string + switch opt.Image.Format { + case + imagePng, + imageJpg, + imageJpeg, + imageGif, + imageWebp: + format = opt.Image.Format + default: + opt.Image.Format = imageJpg + } + // https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,h_100,m_lfit + process := "image/resize,m_lfit" + if opt.Image.Width > 0 { + process += ",w_" + strconv.Itoa(opt.Image.Width) + } + if opt.Image.Height > 0 { + process += ",h_" + strconv.Itoa(opt.Image.Height) + } + process += ",format," + format + opts = append(opts, oss.Process(process)) + } if opt.ContentType != "" { opts = append(opts, oss.ResponseContentType(opt.ContentType)) } if opt.Filename != "" { - opts = append(opts, oss.ResponseContentDisposition(`attachment; filename="`+opt.Filename+`"`)) + opts = append(opts, oss.ResponseContentDisposition(`attachment; filename=`+strconv.Quote(opt.Filename))) } } if expire <= 0 { diff --git a/pkg/common/db/s3/oss/sign.go b/pkg/common/db/s3/oss/sign.go index 9811ac476..60ce43a3e 100644 --- a/pkg/common/db/s3/oss/sign.go +++ b/pkg/common/db/s3/oss/sign.go @@ -1,96 +1,11 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package oss import ( - "crypto/hmac" - "crypto/sha1" - "crypto/sha256" - "encoding/base64" - "hash" - "io" "net/http" - "sort" - "strings" + _ "unsafe" "github.com/aliyun/aliyun-oss-go-sdk/oss" ) -func (o *OSS) getAdditionalHeaderKeys(req *http.Request) ([]string, map[string]string) { - var keysList []string - keysMap := make(map[string]string) - srcKeys := make(map[string]string) - - for k := range req.Header { - srcKeys[strings.ToLower(k)] = "" - } - - for _, v := range o.bucket.Client.Config.AdditionalHeaders { - if _, ok := srcKeys[strings.ToLower(v)]; ok { - keysMap[strings.ToLower(v)] = "" - } - } - - for k := range keysMap { - keysList = append(keysList, k) - } - sort.Strings(keysList) - return keysList, keysMap -} - -func (o *OSS) getSignedStr(req *http.Request, canonicalizedResource string, keySecret string) string { - // Find out the "x-oss-"'s address in header of the request - ossHeadersMap := make(map[string]string) - additionalList, additionalMap := o.getAdditionalHeaderKeys(req) - for k, v := range req.Header { - if strings.HasPrefix(strings.ToLower(k), "x-oss-") { - ossHeadersMap[strings.ToLower(k)] = v[0] - } else if o.bucket.Client.Config.AuthVersion == oss.AuthV2 { - if _, ok := additionalMap[strings.ToLower(k)]; ok { - ossHeadersMap[strings.ToLower(k)] = v[0] - } - } - } - hs := newHeaderSorter(ossHeadersMap) - - // Sort the ossHeadersMap by the ascending order - hs.Sort() - - // Get the canonicalizedOSSHeaders - canonicalizedOSSHeaders := "" - for i := range hs.Keys { - canonicalizedOSSHeaders += hs.Keys[i] + ":" + hs.Vals[i] + "\n" - } - - // Give other parameters values - // when sign URL, date is expires - date := req.Header.Get(oss.HTTPHeaderDate) - contentType := req.Header.Get(oss.HTTPHeaderContentType) - contentMd5 := req.Header.Get(oss.HTTPHeaderContentMD5) - - // default is v1 signature - signStr := req.Method + "\n" + contentMd5 + "\n" + contentType + "\n" + date + "\n" + canonicalizedOSSHeaders + canonicalizedResource - h := hmac.New(func() hash.Hash { return sha1.New() }, []byte(keySecret)) - - // v2 signature - if o.bucket.Client.Config.AuthVersion == oss.AuthV2 { - signStr = req.Method + "\n" + contentMd5 + "\n" + contentType + "\n" + date + "\n" + canonicalizedOSSHeaders + strings.Join(additionalList, ";") + "\n" + canonicalizedResource - h = hmac.New(func() hash.Hash { return sha256.New() }, []byte(keySecret)) - } - _, _ = io.WriteString(h, signStr) - signedStr := base64.StdEncoding.EncodeToString(h.Sum(nil)) - - return signedStr -} +//go:linkname ossSignHeader github.com/aliyun/aliyun-oss-go-sdk/oss.(*Conn).signHeader +func ossSignHeader(c *oss.Conn, req *http.Request, canonicalizedResource string) diff --git a/pkg/common/db/s3/oss/sort.go b/pkg/common/db/s3/oss/sort.go deleted file mode 100644 index 667984ffb..000000000 --- a/pkg/common/db/s3/oss/sort.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package oss - -import ( - "bytes" - "sort" -) - -// headerSorter defines the key-value structure for storing the sorted data in signHeader. -type headerSorter struct { - Keys []string - Vals []string -} - -// newHeaderSorter is an additional function for function SignHeader. -func newHeaderSorter(m map[string]string) *headerSorter { - hs := &headerSorter{ - Keys: make([]string, 0, len(m)), - Vals: make([]string, 0, len(m)), - } - - for k, v := range m { - hs.Keys = append(hs.Keys, k) - hs.Vals = append(hs.Vals, v) - } - return hs -} - -// Sort is an additional function for function SignHeader. -func (hs *headerSorter) Sort() { - sort.Sort(hs) -} - -// Len is an additional function for function SignHeader. -func (hs *headerSorter) Len() int { - return len(hs.Vals) -} - -// Less is an additional function for function SignHeader. -func (hs *headerSorter) Less(i, j int) bool { - return bytes.Compare([]byte(hs.Keys[i]), []byte(hs.Keys[j])) < 0 -} - -// Swap is an additional function for function SignHeader. -func (hs *headerSorter) Swap(i, j int) { - hs.Vals[i], hs.Vals[j] = hs.Vals[j], hs.Vals[i] - hs.Keys[i], hs.Keys[j] = hs.Keys[j], hs.Keys[i] -} diff --git a/pkg/common/db/s3/s3.go b/pkg/common/db/s3/s3.go index fadb09a0b..afbe91955 100644 --- a/pkg/common/db/s3/s3.go +++ b/pkg/common/db/s3/s3.go @@ -116,9 +116,16 @@ type ListUploadedPartsResult struct { UploadedParts []UploadedPart `xml:"Part"` } +type Image struct { + Format string `json:"format"` + Width int `json:"width"` + Height int `json:"height"` +} + type AccessURLOption struct { ContentType string `json:"contentType"` Filename string `json:"filename"` + Image *Image `json:"image"` } type Interface interface { diff --git a/pkg/common/db/table/unrelation/msg.go b/pkg/common/db/table/unrelation/msg.go index 30e6670b5..c95b211a8 100644 --- a/pkg/common/db/table/unrelation/msg.go +++ b/pkg/common/db/table/unrelation/msg.go @@ -27,10 +27,11 @@ import ( ) const ( - singleGocMsgNum = 5000 - Msg = "msg" - OldestList = 0 - NewestList = -1 + singleGocMsgNum = 100 + singleGocMsgNum5000 = 5000 + Msg = "msg" + OldestList = 0 + NewestList = -1 ) type MsgDocModel struct { @@ -128,6 +129,7 @@ type MsgDocModelInterface interface { pageNumber int32, showNumber int32, ) (msgCount int64, userCount int64, groups []*GroupCount, dateCount map[string]int64, err error) + ConvertMsgsDocLen(ctx context.Context, conversationIDs []string) } func (MsgDocModel) TableName() string { @@ -138,6 +140,10 @@ func (MsgDocModel) GetSingleGocMsgNum() int64 { return singleGocMsgNum } +func (MsgDocModel) GetSingleGocMsgNum5000() int64 { + return singleGocMsgNum5000 +} + func (m *MsgDocModel) IsFull() bool { return m.Msg[len(m.Msg)-1].Msg != nil } diff --git a/pkg/common/db/table/unrelation/user.go b/pkg/common/db/table/unrelation/user.go index d264da467..1505829e5 100644 --- a/pkg/common/db/table/unrelation/user.go +++ b/pkg/common/db/table/unrelation/user.go @@ -23,7 +23,7 @@ const ( // UserModel collection structure. type UserModel struct { - UserID string `bson:"user_id" json:"userID"` + UserID string `bson:"user_id" json:"userID"` UserIDList []string `bson:"user_id_list" json:"userIDList"` } @@ -39,4 +39,8 @@ type UserModelInterface interface { UnsubscriptionList(ctx context.Context, userID string, userIDList []string) error // RemoveSubscribedListFromUser Among the unsubscribed users, delete the user from the subscribed list. RemoveSubscribedListFromUser(ctx context.Context, userID string, userIDList []string) error + // GetAllSubscribeList Get all users subscribed by this user + GetAllSubscribeList(ctx context.Context, id string) (userIDList []string, err error) + // GetSubscribedList Get the user subscribed by those users + GetSubscribedList(ctx context.Context, id string) (userIDList []string, err error) } diff --git a/pkg/common/db/unrelation/mongo.go b/pkg/common/db/unrelation/mongo.go index b580f4dbd..f08bb56a4 100644 --- a/pkg/common/db/unrelation/mongo.go +++ b/pkg/common/db/unrelation/mongo.go @@ -17,18 +17,20 @@ package unrelation import ( "context" "fmt" - "go.mongodb.org/mongo-driver/bson" "strings" "time" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/mw/specialerror" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) const ( @@ -116,10 +118,10 @@ func (m *Mongo) createMongoIndex(collection string, isUnique bool, keys ...strin for _, key := range keys { if strings.HasPrefix(key, "-") { keysDoc = append(keysDoc, bson.E{Key: strings.TrimLeft(key, "-"), Value: -1}) - //keysDoc = keysDoc.Append(strings.TrimLeft(key, "-"), bsonx.Int32(-1)) + // keysDoc = keysDoc.Append(strings.TrimLeft(key, "-"), bsonx.Int32(-1)) } else { keysDoc = append(keysDoc, bson.E{Key: key, Value: 1}) - //keysDoc = keysDoc.Append(key, bsonx.Int32(1)) + // keysDoc = keysDoc.Append(key, bsonx.Int32(1)) } } // create index diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index 27f7cf5ce..ce51ca49c 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -31,10 +31,11 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" "google.golang.org/protobuf/proto" - table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" + + table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) var ErrMsgListNotExist = errors.New("user not have msg in mongoDB") @@ -1072,11 +1073,6 @@ func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessa if err != nil { return 0, nil, err } - for _, msg1 := range msgs { - if msg1.IsRead { - msg1.Msg.IsRead = true - } - } return total, msgs, nil } @@ -1150,13 +1146,22 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa {"doc_id", 1}, }}, }, + { + {"$unwind", bson.M{"path": "$msgs"}}, + }, + { + {"$sort", bson.M{"msgs.msg.send_time": -1}}, + }, } cursor, err := m.MsgCollection.Aggregate(ctx, pipe) if err != nil { return 0, nil, err } - - var msgsDocs []table.MsgDocModel + type docModel struct { + DocID string `bson:"doc_id"` + Msg *table.MsgInfoModel `bson:"msgs"` + } + var msgsDocs []docModel err = cursor.All(ctx, &msgsDocs) if err != nil { return 0, nil, err @@ -1166,41 +1171,39 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } msgs := make([]*table.MsgInfoModel, 0) for index := range msgsDocs { - for i := range msgsDocs[index].Msg { - msg := msgsDocs[index].Msg[i] - if msg == nil || msg.Msg == nil { - continue + msgInfo := msgsDocs[index].Msg + if msgInfo == nil || msgInfo.Msg == nil { + continue + } + if msgInfo.Revoke != nil { + revokeContent := sdkws.MessageRevokedContent{ + RevokerID: msgInfo.Revoke.UserID, + RevokerRole: msgInfo.Revoke.Role, + ClientMsgID: msgInfo.Msg.ClientMsgID, + RevokerNickname: msgInfo.Revoke.Nickname, + RevokeTime: msgInfo.Revoke.Time, + SourceMessageSendTime: msgInfo.Msg.SendTime, + SourceMessageSendID: msgInfo.Msg.SendID, + SourceMessageSenderNickname: msgInfo.Msg.SenderNickname, + SessionType: msgInfo.Msg.SessionType, + Seq: msgInfo.Msg.Seq, + Ex: msgInfo.Msg.Ex, + } + data, err := json.Marshal(&revokeContent) + if err != nil { + return 0, nil, err } - if msg.Revoke != nil { - revokeContent := sdkws.MessageRevokedContent{ - RevokerID: msg.Revoke.UserID, - RevokerRole: msg.Revoke.Role, - ClientMsgID: msg.Msg.ClientMsgID, - RevokerNickname: msg.Revoke.Nickname, - RevokeTime: msg.Revoke.Time, - SourceMessageSendTime: msg.Msg.SendTime, - SourceMessageSendID: msg.Msg.SendID, - SourceMessageSenderNickname: msg.Msg.SenderNickname, - SessionType: msg.Msg.SessionType, - Seq: msg.Msg.Seq, - Ex: msg.Msg.Ex, - } - data, err := json.Marshal(&revokeContent) - if err != nil { - return 0, nil, err - } - elem := sdkws.NotificationElem{ - Detail: string(data), - } - content, err := json.Marshal(&elem) - if err != nil { - return 0, nil, err - } - msg.Msg.ContentType = constant.MsgRevokeNotification - msg.Msg.Content = string(content) + elem := sdkws.NotificationElem{ + Detail: string(data), + } + content, err := json.Marshal(&elem) + if err != nil { + return 0, nil, err } - msgs = append(msgs, msg) + msgInfo.Msg.ContentType = constant.MsgRevokeNotification + msgInfo.Msg.Content = string(content) } + msgs = append(msgs, msgInfo) } start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber n := int32(len(msgs)) diff --git a/pkg/common/db/unrelation/msg_convert.go b/pkg/common/db/unrelation/msg_convert.go new file mode 100644 index 000000000..8fbcd56e5 --- /dev/null +++ b/pkg/common/db/unrelation/msg_convert.go @@ -0,0 +1,68 @@ +package unrelation + +import ( + "context" + "fmt" + + "github.com/OpenIMSDK/tools/log" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + + table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" +) + +func (m *MsgMongoDriver) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string) { + for _, conversationID := range conversationIDs { + regex := primitive.Regex{Pattern: fmt.Sprintf("^%s:", conversationID)} + cursor, err := m.MsgCollection.Find(ctx, bson.M{"doc_id": regex}) + if err != nil { + log.ZError(ctx, "convertAll find msg doc failed", err, "conversationID", conversationID) + continue + } + var msgDocs []table.MsgDocModel + err = cursor.All(ctx, &msgDocs) + if err != nil { + log.ZError(ctx, "convertAll cursor all failed", err, "conversationID", conversationID) + continue + } + if len(msgDocs) < 1 { + continue + } + log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(msgDocs)", len(msgDocs)) + if len(msgDocs[0].Msg) == int(m.model.GetSingleGocMsgNum5000()) { + if _, err := m.MsgCollection.DeleteMany(ctx, bson.M{"doc_id": regex}); err != nil { + log.ZError(ctx, "convertAll delete many failed", err, "conversationID", conversationID) + continue + } + var newMsgDocs []interface{} + for _, msgDoc := range msgDocs { + if int64(len(msgDoc.Msg)) == m.model.GetSingleGocMsgNum() { + continue + } + var index int64 + for index < int64(len(msgDoc.Msg)) { + msg := msgDoc.Msg[index] + if msg != nil && msg.Msg != nil { + msgDocModel := table.MsgDocModel{DocID: m.model.GetDocID(conversationID, msg.Msg.Seq)} + end := index + m.model.GetSingleGocMsgNum() + if int(end) >= len(msgDoc.Msg) { + msgDocModel.Msg = msgDoc.Msg[index:] + } else { + msgDocModel.Msg = msgDoc.Msg[index:end] + } + newMsgDocs = append(newMsgDocs, msgDocModel) + index = end + } else { + break + } + } + } + _, err = m.MsgCollection.InsertMany(ctx, newMsgDocs) + if err != nil { + log.ZError(ctx, "convertAll insert many failed", err, "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs)) + } else { + log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs)) + } + } + } +} diff --git a/pkg/common/db/unrelation/super_group.go b/pkg/common/db/unrelation/super_group.go index e93ab2b43..5a9bfccc8 100644 --- a/pkg/common/db/unrelation/super_group.go +++ b/pkg/common/db/unrelation/super_group.go @@ -21,8 +21,9 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) func NewSuperGroupMongoDriver(database *mongo.Database) unrelation.SuperGroupModelInterface { diff --git a/pkg/common/db/unrelation/user.go b/pkg/common/db/unrelation/user.go index feec8aa21..3faec873f 100644 --- a/pkg/common/db/unrelation/user.go +++ b/pkg/common/db/unrelation/user.go @@ -16,15 +16,17 @@ package unrelation import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" + + "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" - "log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" ) -// prefixes and suffixes. +// prefixes and suffixes. const ( SubscriptionPrefix = "subscription_prefix" SubscribedPrefix = "subscribed_prefix" @@ -48,22 +50,35 @@ type UserMongoDriver struct { // AddSubscriptionList Subscriber's handling of thresholds. func (u *UserMongoDriver) AddSubscriptionList(ctx context.Context, userID string, userIDList []string) error { // Check the number of lists in the key. - filter := bson.M{SubscriptionPrefix + userID: bson.M{"$size": 1}} - result, err := u.userCollection.Find(context.Background(), filter) + pipeline := mongo.Pipeline{ + {{"$match", bson.D{{"user_id", SubscriptionPrefix + userID}}}}, + {{"$project", bson.D{{"count", bson.D{{"$size", "$user_id_list"}}}}}}, + } + // perform aggregate operations + cursor, err := u.userCollection.Aggregate(ctx, pipeline) if err != nil { - return err + return errs.Wrap(err) } - var newUserIDList []string - for result.Next(context.Background()) { - err := result.Decode(&newUserIDList) + defer cursor.Close(ctx) + var cnt struct { + Count int `bson:"count"` + } + // iterate over aggregated results + for cursor.Next(ctx) { + err := cursor.Decode(&cnt) if err != nil { - log.Fatal(err) + return errs.Wrap(err) } } + var newUserIDList []string // If the threshold is exceeded, pop out the previous MaximumSubscription - len(userIDList) and insert it. - if len(newUserIDList)+len(userIDList) > MaximumSubscription { + if cnt.Count+len(userIDList) > MaximumSubscription { + newUserIDList, err = u.GetAllSubscribeList(ctx, userID) + if err != nil { + return err + } newUserIDList = newUserIDList[MaximumSubscription-len(userIDList):] - _, err := u.userCollection.UpdateOne( + _, err = u.userCollection.UpdateOne( ctx, bson.M{"user_id": SubscriptionPrefix + userID}, bson.M{"$set": bson.M{"user_id_list": newUserIDList}}, @@ -71,16 +86,17 @@ func (u *UserMongoDriver) AddSubscriptionList(ctx context.Context, userID string if err != nil { return err } - //for i := 1; i <= MaximumSubscription-len(userIDList); i++ { - // _, err := u.userCollection.UpdateOne( - // ctx, - // bson.M{"user_id": SubscriptionPrefix + userID}, - // bson.M{SubscriptionPrefix + userID: bson.M{"$pop": -1}}, - // ) - // if err != nil { - // return err - // } - //} + // Another way to subscribe to N before pop,Delete after testing + /*for i := 1; i <= MaximumSubscription-len(userIDList); i++ { + _, err := u.userCollection.UpdateOne( + ctx, + bson.M{"user_id": SubscriptionPrefix + userID}, + bson.M{SubscriptionPrefix + userID: bson.M{"$pop": -1}}, + ) + if err != nil { + return err + } + }*/ } upsert := true opts := &options.UpdateOptions{ @@ -93,7 +109,7 @@ func (u *UserMongoDriver) AddSubscriptionList(ctx context.Context, userID string opts, ) if err != nil { - return err + return errs.Wrap(err) } for _, user := range userIDList { _, err = u.userCollection.UpdateOne( @@ -117,25 +133,50 @@ func (u *UserMongoDriver) UnsubscriptionList(ctx context.Context, userID string, bson.M{"$pull": bson.M{"user_id_list": bson.M{"$in": userIDList}}}, ) if err != nil { - return err + return errs.Wrap(err) } err = u.RemoveSubscribedListFromUser(ctx, userID, userIDList) if err != nil { - return err + return errs.Wrap(err) } return nil } // RemoveSubscribedListFromUser Among the unsubscribed users, delete the user from the subscribed list. func (u *UserMongoDriver) RemoveSubscribedListFromUser(ctx context.Context, userID string, userIDList []string) error { - var newUserIDList []string - for _, value := range userIDList { - newUserIDList = append(newUserIDList, SubscribedPrefix+value) + var err error + for _, userIDTemp := range userIDList { + _, err = u.userCollection.UpdateOne( + ctx, + bson.M{"user_id": SubscribedPrefix + userIDTemp}, + bson.M{"$pull": bson.M{"user_id_list": userID}}, + ) } - _, err := u.userCollection.UpdateOne( + return errs.Wrap(err) +} + +// GetAllSubscribeList Get all users subscribed by this user +func (u *UserMongoDriver) GetAllSubscribeList(ctx context.Context, userID string) (userIDList []string, err error) { + var user unrelation.UserModel + cursor := u.userCollection.FindOne( ctx, - bson.M{"user_id": bson.M{"$in": newUserIDList}}, - bson.M{"$pull": bson.M{"user_id_list": userID}}, - ) - return utils.Wrap(err, "") + bson.M{"user_id": SubscriptionPrefix + userID}) + err = cursor.Decode(&user) + if err != nil { + return nil, errs.Wrap(err) + } + return user.UserIDList, nil +} + +// GetSubscribedList Get the user subscribed by those users +func (u *UserMongoDriver) GetSubscribedList(ctx context.Context, userID string) (userIDList []string, err error) { + var user unrelation.UserModel + cursor := u.userCollection.FindOne( + ctx, + bson.M{"user_id": SubscribedPrefix + userID}) + err = cursor.Decode(&user) + if err != nil { + return nil, errs.Wrap(err) + } + return user.UserIDList, nil } diff --git a/pkg/common/http/http_client.go b/pkg/common/http/http_client.go index a646f774e..4a132526f 100644 --- a/pkg/common/http/http_client.go +++ b/pkg/common/http/http_client.go @@ -24,11 +24,12 @@ import ( urlLib "net/url" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) var client http.Client diff --git a/pkg/common/kafka/producer.go b/pkg/common/kafka/producer.go index 754f2166d..938757d40 100644 --- a/pkg/common/kafka/producer.go +++ b/pkg/common/kafka/producer.go @@ -19,12 +19,13 @@ import ( "errors" "time" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" log "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/Shopify/sarama" "google.golang.org/protobuf/proto" diff --git a/pkg/common/startrpc/start.go b/pkg/common/startrpc/start.go index d78aa1ff4..9b37734e4 100644 --- a/pkg/common/startrpc/start.go +++ b/pkg/common/startrpc/start.go @@ -16,11 +16,12 @@ package startrpc import ( "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "net" "strconv" "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" diff --git a/pkg/msgprocessor/conversation.go b/pkg/msgprocessor/conversation.go index b24794af8..ca77438ea 100644 --- a/pkg/msgprocessor/conversation.go +++ b/pkg/msgprocessor/conversation.go @@ -1,14 +1,29 @@ +// Copyright © 2023 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package msgprocessor import ( + "sort" + "strings" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" "google.golang.org/protobuf/proto" - "sort" - "strings" ) -func GetNotificationConversationID(msg *sdkws.MsgData) string { +func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string { switch msg.SessionType { case constant.SingleChatType: l := []string{msg.SendID, msg.RecvID} @@ -99,6 +114,30 @@ func GetConversationIDBySessionType(sessionType int, ids ...string) string { return "" } +func GetNotificationConversationIDByConversationID(conversationID string) string { + l := strings.Split(conversationID, "_") + if len(l) > 1 { + l[0] = "n" + return strings.Join(l, "_") + } else { + return "" + } +} + +func GetNotificationConversationID(sessionType int, ids ...string) string { + sort.Strings(ids) + if len(ids) > 2 || len(ids) < 1 { + return "" + } + switch sessionType { + case constant.SingleChatType: + return "n_" + strings.Join(ids, "_") // single chat + case constant.SuperGroupChatType: + return "n_" + ids[0] // super group chat + } + return "" +} + func IsNotification(conversationID string) bool { return strings.HasPrefix(conversationID, "n_") } diff --git a/pkg/msgprocessor/options.go b/pkg/msgprocessor/options.go index 920a6a2ea..c17c7cb05 100644 --- a/pkg/msgprocessor/options.go +++ b/pkg/msgprocessor/options.go @@ -16,8 +16,10 @@ package msgprocessor import "github.com/OpenIMSDK/protocol/constant" -type Options map[string]bool -type OptionsOpt func(Options) +type ( + Options map[string]bool + OptionsOpt func(Options) +) func NewOptions(opts ...OptionsOpt) Options { options := make(map[string]bool, 11) diff --git a/pkg/rpcclient/auth.go b/pkg/rpcclient/auth.go index cbf1324e0..69f21f38d 100644 --- a/pkg/rpcclient/auth.go +++ b/pkg/rpcclient/auth.go @@ -19,9 +19,10 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/auth" "github.com/OpenIMSDK/tools/discoveryregistry" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth { diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index 2b7d2c392..b123a6212 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -20,10 +20,11 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" pbConversation "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/errs" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type Conversation struct { diff --git a/pkg/rpcclient/friend.go b/pkg/rpcclient/friend.go index f1aaaa319..1bd004dd5 100644 --- a/pkg/rpcclient/friend.go +++ b/pkg/rpcclient/friend.go @@ -19,10 +19,11 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/friend" sdkws "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/discoveryregistry" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type Friend struct { diff --git a/pkg/rpcclient/group.go b/pkg/rpcclient/group.go index 57dcd0fa5..7dc333de6 100644 --- a/pkg/rpcclient/group.go +++ b/pkg/rpcclient/group.go @@ -20,13 +20,14 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type Group struct { diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 8e9416af9..205261dd9 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -21,13 +21,14 @@ import ( "google.golang.org/grpc" "google.golang.org/protobuf/proto" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" // "google.golang.org/protobuf/proto". ) diff --git a/pkg/rpcclient/notification/conevrsation.go b/pkg/rpcclient/notification/conevrsation.go index a5f57c570..d92ee82a0 100644 --- a/pkg/rpcclient/notification/conevrsation.go +++ b/pkg/rpcclient/notification/conevrsation.go @@ -17,9 +17,10 @@ package notification import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type ConversationNotificationSender struct { @@ -32,7 +33,8 @@ func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient) // SetPrivate调用. func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, - isPrivateChat bool, conversationID string) error { + isPrivateChat bool, conversationID string, +) error { tips := &sdkws.ConversationSetPrivateTips{ RecvID: recvID, SendID: sendID, diff --git a/pkg/rpcclient/notification/friend.go b/pkg/rpcclient/notification/friend.go index ddce86c8c..213d9cdfe 100644 --- a/pkg/rpcclient/notification/friend.go +++ b/pkg/rpcclient/notification/friend.go @@ -19,13 +19,14 @@ import ( "github.com/OpenIMSDK/tools/mcontext" + "github.com/OpenIMSDK/protocol/constant" + pbFriend "github.com/OpenIMSDK/protocol/friend" + "github.com/OpenIMSDK/protocol/sdkws" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" - "github.com/OpenIMSDK/protocol/constant" - pbFriend "github.com/OpenIMSDK/protocol/friend" - "github.com/OpenIMSDK/protocol/sdkws" ) type FriendNotificationSender struct { diff --git a/pkg/rpcclient/notification/group.go b/pkg/rpcclient/notification/group.go index fdf77500f..c334f75d8 100644 --- a/pkg/rpcclient/notification/group.go +++ b/pkg/rpcclient/notification/group.go @@ -18,9 +18,6 @@ import ( "context" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" pbGroup "github.com/OpenIMSDK/protocol/group" "github.com/OpenIMSDK/protocol/sdkws" @@ -28,6 +25,10 @@ import ( "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) func NewGroupNotificationSender( @@ -219,7 +220,13 @@ func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs [ return result, nil } -func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws.GroupMemberFullInfo, groupID string) error { +func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws.GroupMemberFullInfo, groupID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if opUser == nil { return errs.ErrInternalServer.Wrap("**sdkws.GroupMemberFullInfo is nil") } @@ -259,6 +266,12 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws } func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -266,6 +279,12 @@ func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, } func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -273,6 +292,12 @@ func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, } func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -280,6 +305,12 @@ func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Conte } func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx context.Context, tips *sdkws.GroupInfoSetAnnouncementTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -287,6 +318,12 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte } func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, req.GroupID) if err != nil { return err @@ -354,6 +391,12 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte } func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, req.GroupID) if err != nil { return err @@ -376,6 +419,12 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte } func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, req.GroupID) if err != nil { return err @@ -393,6 +442,12 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context. } func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -400,6 +455,12 @@ func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, } func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -418,12 +479,18 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips) } -func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) { - group, err := g.getGroupInfo(ctx, req.GroupID) +func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, groupID string, entrantUserID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() + group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err } - user, err := g.getGroupMember(ctx, req.GroupID, req.FromUserID) + user, err := g.getGroupMember(ctx, groupID, entrantUserID) if err != nil { return err } @@ -432,6 +499,12 @@ func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, r } func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context, tips *sdkws.GroupDismissedTips) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } @@ -439,6 +512,12 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context } func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -458,6 +537,12 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte } func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -474,6 +559,12 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context } func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, groupID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -493,6 +584,12 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr } func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Context, groupID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -512,6 +609,12 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte } func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -528,6 +631,12 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Con } func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, utils.GetFuncName(1)+" failed", err) + } + }() group, err := g.getGroupInfo(ctx, groupID) if err != nil { return err @@ -544,22 +653,6 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context. } func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { - group, err := g.getGroupInfo(ctx, groupID) - if err != nil { - return err - } - user, err := g.getGroupMemberMap(ctx, groupID, []string{mcontext.GetOpUserID(ctx), groupMemberUserID}) - if err != nil { - return err - } - tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]} - if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { - return err - } - return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips) -} - -func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) (err error) { defer log.ZDebug(ctx, "return") defer func() { if err != nil { @@ -570,12 +663,15 @@ func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Co if err != nil { return err } - user, err := g.getGroupMember(ctx, groupID, entrantUserID) + user, err := g.getGroupMemberMap(ctx, groupID, []string{mcontext.GetOpUserID(ctx), groupMemberUserID}) if err != nil { return err } - tips := &sdkws.MemberEnterTips{Group: group, EntrantUser: user} - return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips) + tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]} + if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { + return err + } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips) } func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, sendID, recvID string) (err error) { diff --git a/pkg/rpcclient/notification/msg.go b/pkg/rpcclient/notification/msg.go index ba5aef684..53e66fc7d 100644 --- a/pkg/rpcclient/notification/msg.go +++ b/pkg/rpcclient/notification/msg.go @@ -17,9 +17,10 @@ package notification import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/sdkws" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" ) type MsgNotificationSender struct { diff --git a/pkg/rpcclient/push.go b/pkg/rpcclient/push.go index 4401221c3..7b7adcfa5 100644 --- a/pkg/rpcclient/push.go +++ b/pkg/rpcclient/push.go @@ -19,9 +19,10 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/push" "github.com/OpenIMSDK/tools/discoveryregistry" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type Push struct { diff --git a/pkg/rpcclient/third.go b/pkg/rpcclient/third.go index c01ab4d0c..015702a93 100644 --- a/pkg/rpcclient/third.go +++ b/pkg/rpcclient/third.go @@ -23,9 +23,10 @@ import ( "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/third" "github.com/OpenIMSDK/tools/discoveryregistry" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type Third struct { diff --git a/pkg/rpcclient/user.go b/pkg/rpcclient/user.go index 6ca60dc75..3c24efbbd 100644 --- a/pkg/rpcclient/user.go +++ b/pkg/rpcclient/user.go @@ -16,17 +16,19 @@ package rpcclient import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "strings" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "google.golang.org/grpc" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/protocol/sdkws" "github.com/OpenIMSDK/protocol/user" "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" ) type User struct { @@ -154,6 +156,7 @@ func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumbe } return resp.UserIDs, nil } + func (u *UserRpcClient) SetUserStatus(ctx context.Context, userID string, status int32, platformID int) error { _, err := u.Client.SetUserStatus(ctx, &user.SetUserStatusReq{StatusList: []*user.OnlineStatus{{UserID: userID, Status: status, PlatformID: int32(platformID)}}}) return err diff --git a/scripts/advertise.sh b/scripts/advertise.sh index c1cd63f56..75f474bfe 100755 --- a/scripts/advertise.sh +++ b/scripts/advertise.sh @@ -1,4 +1,18 @@ -#!/bin/bash +#!/usr/bin/env bash +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + set -e set -o pipefail diff --git a/scripts/build.cmd b/scripts/build.cmd index f3c086a32..d153e6d9e 100644 --- a/scripts/build.cmd +++ b/scripts/build.cmd @@ -1,12 +1,13 @@ +@echo off set output_dir=%~dp0..\_output\bin\platforms\windows -go build -o %output_dir%\api.exe ../cmd/openim-api/main.go -go build -o %output_dir%\auth.exe ../cmd/openim-rpc/openim-rpc-auth/main.go -go build -o %output_dir%\conversation.exe ../cmd/openim-rpc/openim-rpc-conversation/main.go -go build -o %output_dir%\friend.exe ../cmd/openim-rpc/openim-rpc-friend/main.go -go build -o %output_dir%\group.exe ../cmd/openim-rpc/openim-rpc-group/main.go -go build -o %output_dir%\msg.exe ../cmd/openim-rpc/openim-rpc-msg/main.go -go build -o %output_dir%\third.exe ../cmd/openim-rpc/openim-rpc-third/main.go -go build -o %output_dir%\user.exe ../cmd/openim-rpc/openim-rpc-user/main.go -go build -o %output_dir%\push.exe ../cmd/openim-push/main.go -go build -o %output_dir%\msgtransfer.exe ../cmd/openim-msgtransfer/main.go -go build -o %output_dir%\msggateway.exe ../cmd/openim-msggateway/main.go \ No newline at end of file + +set "rpc_apps=auth conversation friend group msg third user" +set "other_apps=api push msgtransfer msggateway" + +for %%a in (%rpc_apps%) do ( + go build -o %output_dir%\%%a.exe ../cmd/openim-rpc/openim-rpc-%%a/main.go +) + +for %%a in (%other_apps%) do ( + go build -o %output_dir%\%%a.exe ../cmd/openim-%%a/main.go +) diff --git a/scripts/build_all_service.sh b/scripts/build_all_service.sh index fd6ad6dcd..24bb03665 100755 --- a/scripts/build_all_service.sh +++ b/scripts/build_all_service.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/scripts/check_all.sh b/scripts/check_all.sh index 84dabb1eb..ea9c2b5b7 100755 --- a/scripts/check_all.sh +++ b/scripts/check_all.sh @@ -61,7 +61,7 @@ check=$(ps aux | grep -w ./${openim_msgtransfer} | grep -v grep | wc -l) if [ $check -eq ${msg_transfer_service_num} ]; then echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTransfer"${COLOR_SUFFIX} else - echo $check ${msg_transfer_service_num} + echo $check ${msg_transfer_service_num} echo -e ${RED_PREFIX}"openImMsgTransfer service does not start normally, num err"${COLOR_SUFFIX} echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX} exit -1 diff --git a/scripts/common.sh b/scripts/common.sh index 8ae2abfa5..6068a1d95 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +19,7 @@ # Common utilities, variables and checks for all build scripts. set -o errexit -set -o nounset +set +o nounset set -o pipefail # Unset CDPATH, having it set messes up with script import paths @@ -104,9 +105,7 @@ openim::build::get_docker_wrapped_binaries() { "openim-rpc-msg,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}" "openim-rpc-third,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}" "openim-rpc-user,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}" - ) - echo "${targets[@]}" } diff --git a/scripts/coverage.sh b/scripts/coverage.sh index fbb2b36fc..ae5283671 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/scripts/docker_check_service.sh b/scripts/docker_check_service.sh index 14ec81974..b08c2aa7c 100755 --- a/scripts/docker_check_service.sh +++ b/scripts/docker_check_service.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/scripts/docker_start_all.sh b/scripts/docker_start_all.sh index 421900ef4..f617c5057 100755 --- a/scripts/docker_start_all.sh +++ b/scripts/docker_start_all.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,11 +23,11 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. #fixme Put the shell scripts name here need_to_start_server_shell=( - start_rpc_service.sh - msg_gateway_start.sh - push_start.sh - msg_transfer_start.sh - start_cron.sh + ${SCRIPTS_ROOT}/start_rpc_service.sh + ${SCRIPTS_ROOT}/msg_gateway_start.sh + ${SCRIPTS_ROOT}/push_start.sh + ${SCRIPTS_ROOT}/msg_transfer_start.sh + ${SCRIPTS_ROOT}/start_cron.sh ) #fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started @@ -41,8 +42,7 @@ echo "==========================================================">>$OPENIM_ROOT/ echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & for i in ${need_to_start_server_shell[*]}; do - chmod +x $i - ./$i + $i done sleep 15 diff --git a/scripts/enterprise/function.sh b/scripts/enterprise/function.sh index e2dc96a25..8b5cb0b2b 100755 --- a/scripts/enterprise/function.sh +++ b/scripts/enterprise/function.sh @@ -16,12 +16,12 @@ #input:[10023,2323,3434] #output:10023 2323 3434 list_to_string(){ -ports_list=$* -sub_s1=`echo $ports_list | sed 's/ //g'` -sub_s2=${sub_s1//,/ } -sub_s3=${sub_s2#*[} -sub_s4=${sub_s3%]*} -ports_array=$sub_s4 + ports_list=$* + sub_s1=`echo $ports_list | sed 's/ //g'` + sub_s2=${sub_s1//,/ } + sub_s3=${sub_s2#*[} + sub_s4=${sub_s3%]*} + ports_array=$sub_s4 } remove_space(){ value=$* diff --git a/scripts/enterprise/path_info.cfg b/scripts/enterprise/path_info.cfg index 6ce712593..3b18bbf90 100644 --- a/scripts/enterprise/path_info.cfg +++ b/scripts/enterprise/path_info.cfg @@ -1,11 +1,8 @@ #Don't put the space between "=" - -demo_server_name="openim_chat_api" +demo_server_name="chat-api" demo_server_binary_root="$BIN_DIR/" - - #Global configuration file default dir config_path="../.docker-compose_cfg/config.yaml" @@ -15,15 +12,14 @@ service_source_root=( ../cmd/api/chat/ ../cmd/api/admin/ #rpc service file - ../cmd/openim-rpc/admin/ - ../cmd/openim-rpc/chat/ + ../cmd/rpc/admin/ + ../cmd/rpc/chat/ ) + #service filename service_names=( - #api service filename - openim_chat_api - openim_admin_api - #rpc service filename - openim_admin - openim_chat + chat-api + admin-api + admin-rpc + chat-rpc ) diff --git a/scripts/env_check.sh b/scripts/env_check.sh index 35f918d80..7cd9f83a3 100755 --- a/scripts/env_check.sh +++ b/scripts/env_check.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/scripts/environment.sh b/scripts/environment.sh new file mode 100755 index 000000000..0c2aea971 --- /dev/null +++ b/scripts/environment.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +# Copyright 2020 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. + +# OPENIM 项目源码根目录 +IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. + +# 生成文件存放目录 +LOCAL_OUTPUT_ROOT="${IAM_ROOT}/${OUT_DIR:-_output}" + +# 设置统一的密码,方便记忆 +readonly PASSWORD=${PASSWORD:-'iam59!z$'} + +# Linux系统 going 用户 +readonly LINUX_USERNAME=${LINUX_USERNAME:-going} +# Linux root & going 用户密码 +readonly LINUX_PASSWORD=${LINUX_PASSWORD:-${PASSWORD}} + +# 设置安装目录 +readonly INSTALL_DIR=${INSTALL_DIR:-/tmp/installation} +mkdir -p ${INSTALL_DIR} +readonly ENV_FILE=${IAM_ROOT}/scripts/install/environment.sh + +# MariaDB 配置信息 +readonly MARIADB_ADMIN_USERNAME=${MARIADB_ADMIN_USERNAME:-root} # MariaDB root 用户 +readonly MARIADB_ADMIN_PASSWORD=${MARIADB_ADMIN_PASSWORD:-${PASSWORD}} # MariaDB root 用户密码 +readonly MARIADB_HOST=${MARIADB_HOST:-127.0.0.1:3306} # MariaDB 主机地址 +readonly MARIADB_DATABASE=${MARIADB_DATABASE:-openim} # MariaDB openim 应用使用的数据库名 +readonly MARIADB_USERNAME=${MARIADB_USERNAME:-openim} # openim 数据库用户名 +readonly MARIADB_PASSWORD=${MARIADB_PASSWORD:-${PASSWORD}} # openim 数据库密码 + +# Redis 配置信息 +readonly REDIS_HOST=${REDIS_HOST:-127.0.0.1} # Redis 主机地址 +readonly REDIS_PORT=${REDIS_PORT:-6379} # Redis 监听端口 +readonly REDIS_USERNAME=${REDIS_USERNAME:-''} # Redis 用户名 +readonly REDIS_PASSWORD=${REDIS_PASSWORD:-${PASSWORD}} # Redis 密码 + +# MongoDB 配置 +readonly MONGO_ADMIN_USERNAME=${MONGO_ADMIN_USERNAME:-root} # MongoDB root 用户 +readonly MONGO_ADMIN_PASSWORD=${MONGO_ADMIN_PASSWORD:-${PASSWORD}} # MongoDB root 用户密码 +readonly MONGO_HOST=${MONGO_HOST:-127.0.0.1} # MongoDB 地址 +readonly MONGO_PORT=${MONGO_PORT:-27017} # MongoDB 端口 +readonly MONGO_USERNAME=${MONGO_USERNAME:-openim} # MongoDB 用户名 +readonly MONGO_PASSWORD=${MONGO_PASSWORD:-${PASSWORD}} # MongoDB 密码 + +# openim 配置 +readonly IAM_DATA_DIR=${IAM_DATA_DIR:-/data/openim} # openim 各组件数据目录 +readonly IAM_INSTALL_DIR=${IAM_INSTALL_DIR:-/opt/openim} # openim 安装文件存放目录 +readonly IAM_CONFIG_DIR=${IAM_CONFIG_DIR:-/etc/openim} # openim 配置文件存放目录 +readonly IAM_LOG_DIR=${IAM_LOG_DIR:-/var/log/openim} # openim 日志文件存放目录 +readonly CA_FILE=${CA_FILE:-${IAM_CONFIG_DIR}/cert/ca.pem} # CA + +# openim-apiserver 配置 +readonly IAM_APISERVER_HOST=${IAM_APISERVER_HOST:-127.0.0.1} # openim-apiserver 部署机器 IP 地址 +readonly IAM_APISERVER_GRPC_BIND_ADDRESS=${IAM_APISERVER_GRPC_BIND_ADDRESS:-0.0.0.0} +readonly IAM_APISERVER_GRPC_BIND_PORT=${IAM_APISERVER_GRPC_BIND_PORT:-8081} +readonly IAM_APISERVER_INSECURE_BIND_ADDRESS=${IAM_APISERVER_INSECURE_BIND_ADDRESS:-127.0.0.1} +readonly IAM_APISERVER_INSECURE_BIND_PORT=${IAM_APISERVER_INSECURE_BIND_PORT:-8080} +readonly IAM_APISERVER_SECURE_BIND_ADDRESS=${IAM_APISERVER_SECURE_BIND_ADDRESS:-0.0.0.0} +readonly IAM_APISERVER_SECURE_BIND_PORT=${IAM_APISERVER_SECURE_BIND_PORT:-8443} +readonly IAM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${IAM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${IAM_CONFIG_DIR}/cert/openim-apiserver.pem} +readonly IAM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${IAM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${IAM_CONFIG_DIR}/cert/openim-apiserver-key.pem} + +# openim-authz-server 配置 +readonly IAM_AUTHZ_SERVER_HOST=${IAM_AUTHZ_SERVER_HOST:-127.0.0.1} # openim-authz-server 部署机器 IP 地址 +readonly IAM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS=${IAM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS:-127.0.0.1} +readonly IAM_AUTHZ_SERVER_INSECURE_BIND_PORT=${IAM_AUTHZ_SERVER_INSECURE_BIND_PORT:-9090} +readonly IAM_AUTHZ_SERVER_SECURE_BIND_ADDRESS=${IAM_AUTHZ_SERVER_SECURE_BIND_ADDRESS:-0.0.0.0} +readonly IAM_AUTHZ_SERVER_SECURE_BIND_PORT=${IAM_AUTHZ_SERVER_SECURE_BIND_PORT:-9443} +readonly IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${IAM_CONFIG_DIR}/cert/openim-authz-server.pem} +readonly IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${IAM_CONFIG_DIR}/cert/openim-authz-server-key.pem} +readonly IAM_AUTHZ_SERVER_CLIENT_CA_FILE=${IAM_AUTHZ_SERVER_CLIENT_CA_FILE:-${CA_FILE}} +readonly IAM_AUTHZ_SERVER_RPCSERVER=${IAM_AUTHZ_SERVER_RPCSERVER:-${IAM_APISERVER_HOST}:${IAM_APISERVER_GRPC_BIND_PORT}} + +# openim-pump 配置 +readonly IAM_PUMP_HOST=${IAM_PUMP_HOST:-127.0.0.1} # openim-pump 部署机器 IP 地址 +readonly IAM_PUMP_COLLECTION_NAME=${IAM_PUMP_COLLECTION_NAME:-iam_analytics} +readonly IAM_PUMP_MONGO_URL=${IAM_PUMP_MONGO_URL:-mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${IAM_PUMP_COLLECTION_NAME}?authSource=${IAM_PUMP_COLLECTION_NAME}} + +# openim-watcher配置 +readonly IAM_WATCHER_HOST=${IAM_WATCHER_HOST:-127.0.0.1} # openim-watcher 部署机器 IP 地址 + +# iamctl 配置 +readonly CONFIG_USER_USERNAME=${CONFIG_USER_USERNAME:-admin} +readonly CONFIG_USER_PASSWORD=${CONFIG_USER_PASSWORD:-Admin@2021} +readonly CONFIG_USER_CLIENT_CERTIFICATE=${CONFIG_USER_CLIENT_CERTIFICATE:-${HOME}/.openim/cert/admin.pem} +readonly CONFIG_USER_CLIENT_KEY=${CONFIG_USER_CLIENT_KEY:-${HOME}/.openim/cert/admin-key.pem} +readonly CONFIG_SERVER_ADDRESS=${CONFIG_SERVER_ADDRESS:-${IAM_APISERVER_HOST}:${IAM_APISERVER_SECURE_BIND_PORT}} +readonly CONFIG_SERVER_CERTIFICATE_AUTHORITY=${CONFIG_SERVER_CERTIFICATE_AUTHORITY:-${CA_FILE}} diff --git a/scripts/function.sh b/scripts/function.sh index e351c1ddb..ea7b50c5a 100755 --- a/scripts/function.sh +++ b/scripts/function.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh new file mode 100755 index 000000000..cee105a8a --- /dev/null +++ b/scripts/genconfig.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Copyright 2020 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. + +# 本脚本功能:根据 scripts/environment.sh 配置,生成 OPENIM 组件 YAML 配置文件。 +# 示例:genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml + +env_file="$1" +template_file="$2" + +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. + +source "${OPENIM_ROOT}/scripts/lib/init.sh" + +if [ $# -ne 2 ];then + openim::log::error "Usage: genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml" + exit 1 +fi + +source "${env_file}" + +declare -A envs + +set +u +for env in $(sed -n 's/^[^#].*${\(.*\)}.*/\1/p' ${template_file}) +do + if [ -z "$(eval echo \$${env})" ];then + openim::log::error "environment variable '${env}' not set" + missing=true + fi +done + +if [ "${missing}" ];then + openim::log::error 'You may run `source scripts/environment.sh` to set these environment' + exit 1 +fi + +eval "cat << EOF +$(cat ${template_file}) +EOF" diff --git a/scripts/init_pwd.sh b/scripts/init_pwd.sh index f33c9b3dc..1e5fa3b34 100755 --- a/scripts/init_pwd.sh +++ b/scripts/init_pwd.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright © 2023 OpenIM. All rights reserved. # diff --git a/scripts/lib/color.sh b/scripts/lib/color.sh index c4bdefe25..e6b9c3924 100755 --- a/scripts/lib/color.sh +++ b/scripts/lib/color.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +32,44 @@ COLOR_BGREEN='\033[42m';COLOR_BYELLOW='\033[43m'; COLOR_BBLUE='\033[44m';COLOR_BMAGENTA='\033[45m'; COLOR_BCYAN='\033[46m';COLOR_BWHITE='\033[47m'; +# Color definitions +COLOR_SUFFIX="\033[0m" # End all colors and special effects +BLACK_PREFIX="\033[30m" # Black prefix +RED_PREFIX="\033[31m" # Red prefix +GREEN_PREFIX="\033[32m" # Green prefix +YELLOW_PREFIX="\033[33m" # Yellow prefix +BLUE_PREFIX="\033[34m" # Blue prefix +SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix +WHITE_PREFIX="\033[37m" # White prefix +BOLD_PREFIX="\033[1m" # Bold prefix +UNDERLINE_PREFIX="\033[4m" # Underline prefix +ITALIC_PREFIX="\033[3m" # Italic prefix +BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix +CYAN_PREFIX="\033[0;36m" # Cyan prefix + +# --- helper functions for logs --- +info() +{ + echo -e "[${GREEN_PREFIX}INFO${COLOR_SUFFIX}] " "$@" +} +warn() +{ + echo -e "[${YELLOW_PREFIX}WARN${COLOR_SUFFIX}] " "$@" >&2 +} +fatal() +{ + echo -e "[${RED_PREFIX}ERROR${COLOR_SUFFIX}] " "$@" >&2 + exit 1 +} +debug() +{ + echo -e "[${BLUE_PREFIX}DEBUG${COLOR_SUFFIX}]===> " "$@" +} +success() +{ + echo -e "${BRIGHT_GREEN_PREFIX}===> [SUCCESS] <===${COLOR_SUFFIX}\n=> " "$@" +} + # Print colors you can use openim::color::print_color() { diff --git a/scripts/lib/golang.sh b/scripts/lib/golang.sh index b442e1160..0d35e9198 100755 --- a/scripts/lib/golang.sh +++ b/scripts/lib/golang.sh @@ -35,7 +35,6 @@ openim::golang::server_targets() { local targets=( openim-api openim-cmdutils - openim-cmdutils openim-crontask openim-msggateway openim-msgtransfer diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 04eb21de7..f9a55d37c 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -709,3 +709,23 @@ if [[ -z "${color_start-}" ]]; then fi # ex: ts=2 sw=2 et filetype=sh + + +# input: [10023, 2323, 3434] +# output: 10023 2323 3434 + +# Function function: Converts a list to a string, removing Spaces and parentheses +function list_to_string() { + ports_list=$* # 获取传入的参数列表 + sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格 + sub_s2=${sub_s1//,/ } # 将逗号替换为空格 + sub_s3=${sub_s2#*[} # 去除左括号及其之前的内容 + sub_s4=${sub_s3%]*} # 去除右括号及其之后的内容 + ports_array=$sub_s4 # 将处理后的字符串赋值给变量 ports_array +} + +# Function Function: Remove Spaces in the string +function remove_space() { + value=$* # 获取传入的参数 + result=$(echo $value | sed 's/ //g') # 去除空格 +} diff --git a/scripts/make-rules/common.mk b/scripts/make-rules/common.mk index 93057fef5..0da5af561 100644 --- a/scripts/make-rules/common.mk +++ b/scripts/make-rules/common.mk @@ -46,6 +46,12 @@ BIN_DIR := $(OUTPUT_DIR)/bin $(shell mkdir -p $(BIN_DIR)) endif +# BIN_TOOLS_DIR: Directory where executable files are stored. +ifeq ($(origin BIN_TOOLS_DIR),undefined) +BIN_TOOLS_DIR := $(OUTPUT_DIR)/bin-tools +$(shell mkdir -p $(BIN_TOOLS_DIR)) +endif + # TOOLS_DIR: The directory where tools are stored for build and testing. ifeq ($(origin TOOLS_DIR),undefined) TOOLS_DIR := $(OUTPUT_DIR)/tools diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index dedcdc9fc..cc54d017a 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -44,8 +44,8 @@ ifeq ($(origin GOBIN), undefined) GOBIN := $(GOPATH)/bin endif -# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ except those ending in.md -COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/*)) +# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ and ${ROOT_DIR}/tools/ except those ending in.md +COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/*)) ifeq (${COMMANDS},) $(error Could not determine COMMANDS, set ROOT_DIR or run in source dir) endif @@ -120,15 +120,20 @@ go.build.%: @echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)" @mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH) @if [ "$(COMMAND)" == "openim-sdk-core" ]; then \ - echo "===========> DEBUG: Compilation is not yet supported $(COMMAND)"; \ + echo "===========> DEBUG: OpenIM-SDK-Core It is no longer supported for openim-server $(COMMAND)"; \ elif [ "$(COMMAND)" == "openim-rpc" ]; then \ for d in $(wildcard $(ROOT_DIR)/cmd/openim-rpc/*); do \ cd $${d} && CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$$(basename $${d})$(GO_OUT_EXT) $${d}/main.go; \ done; \ else \ - CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ - $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \ + if [ -f $(ROOT_DIR)/cmd/$(COMMAND)/main.go ]; then \ + CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ + $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \ + elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/main.go ]; then \ + CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ + $(BIN_TOOLS_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/main.go; \ + fi \ fi ## go.install: Install deployment openim @@ -197,8 +202,8 @@ go.updates: tools.verify.go-mod-outdated ## go.clean: Clean all builds directories and files .PHONY: go.clean go.clean: - @echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR))" - @-rm -vrf $(TMP_DIR) $(BIN_DIR) + @echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR)) AND BIN_TOOLS_DIR($(BIN_TOOLS_DIR))" + @-rm -vrf $(TMP_DIR) $(BIN_DIR) $(BIN_TOOLS_DIR) @echo "===========> End clean..." ## copyright.help: Show copyright help diff --git a/scripts/msg_gateway_start.sh b/scripts/msg_gateway_start.sh index cc6f0b5dd..49d84fac5 100755 --- a/scripts/msg_gateway_start.sh +++ b/scripts/msg_gateway_start.sh @@ -30,7 +30,6 @@ echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" ulimit -n 200000 diff --git a/scripts/msg_transfer_start.sh b/scripts/msg_transfer_start.sh index b1e17769d..46c077c5d 100755 --- a/scripts/msg_transfer_start.sh +++ b/scripts/msg_transfer_start.sh @@ -28,7 +28,6 @@ echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" cd $OPENIM_ROOT @@ -38,10 +37,10 @@ prome_ports=($ports_array) #Check if the service exists #If it is exists,kill this process -check=`ps aux | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l` +check=`ps | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l` if [ $check -ge 1 ] then -oldPid=`ps aux | grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'` +oldPid=`ps | grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'` kill -9 $oldPid fi #Waiting port recycling @@ -59,10 +58,10 @@ for ((i = 0; i < ${msg_transfer_service_num}; i++)); do done #Check launched service process -check=`ps aux | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l` +check=`ps | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l` if [ $check -ge 1 ] then -newPid=`ps aux | grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'` +newPid=`ps | grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'` allPorts="" echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${openim_msgtransfer}${COLOR_SUFFIX} diff --git a/scripts/push_start.sh b/scripts/push_start.sh index 74b9aedc9..b474e1b99 100755 --- a/scripts/push_start.sh +++ b/scripts/push_start.sh @@ -32,7 +32,6 @@ echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" cd "$OPENIM_ROOT/scripts/" @@ -45,9 +44,9 @@ prome_ports=($ports_array) #Check if the service exists #If it is exists,kill this process -check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - oldPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + oldPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') kill -9 $oldPid fi #Waiting port recycling @@ -61,9 +60,9 @@ done sleep 3 #Check launched service process -check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + newPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}') allPorts="" diff --git a/scripts/start.bat b/scripts/start.bat new file mode 100644 index 000000000..8054acdc4 --- /dev/null +++ b/scripts/start.bat @@ -0,0 +1,12 @@ +cd %~p0../_output/bin/platforms/windows +start api.exe -p 10002 +start auth.exe -p 10060 +start conversation.exe -p 10080 +start friend.exe -p 10020 +start group.exe -p 10050 +start msg.exe -p 10030 +start msggateway.exe -p 10040 -w 10001 +start msgtransfer.exe +start third.exe -p 10090 +start push.exe -p 10070 +start user.exe -p 10010 \ No newline at end of file diff --git a/scripts/start_all.sh b/scripts/start_all.sh index 6470ae910..b6b4e3428 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -27,18 +27,17 @@ source $SCRIPTS_ROOT/function.sh cd $SCRIPTS_ROOT +echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}" +echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}" +echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" + if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then # exec build_all_service.sh "${SCRIPTS_ROOT}/build_all_service.sh" fi -echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}" -echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}" -echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" - bin_dir="$OPENIM_ROOT/_output/bin" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" if [ ! -d "$bin_dir" ]; then mkdir -p "$bin_dir" diff --git a/scripts/start_cron.sh b/scripts/start_cron.sh index 79b5b9c31..ddd3661ae 100755 --- a/scripts/start_cron.sh +++ b/scripts/start_cron.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,14 +31,13 @@ echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" #Check if the service exists #If it is exists,kill this process -check=`ps aux | grep -w ./${cron_task_name} | grep -v grep| wc -l` +check=`ps | grep -w ./${cron_task_name} | grep -v grep| wc -l` if [ $check -ge 1 ] then -oldPid=`ps aux | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'` +oldPid=`ps | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'` kill -9 $oldPid fi #Waiting port recycling @@ -50,10 +50,10 @@ nohup ./${cron_task_name} >>$OPENIM_ROOT/logs/openIM.log 2>&1 & #done #Check launched service process -check=`ps aux | grep -w ./${cron_task_name} | grep -v grep| wc -l` +check=`ps | grep -w ./${cron_task_name} | grep -v grep| wc -l` if [ $check -ge 1 ] then -newPid=`ps aux | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'` +newPid=`ps | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'` allPorts="" echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${cron_task_name}${COLOR_SUFFIX} diff --git a/scripts/start_rpc_service.sh b/scripts/start_rpc_service.sh index f1624c34e..51e13298f 100755 --- a/scripts/start_rpc_service.sh +++ b/scripts/start_rpc_service.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +31,6 @@ echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/sdk/db/" #service filename service_filename=( @@ -75,7 +75,7 @@ service_prometheus_port_name=( for ((i = 0; i < ${#service_filename[*]}; i++)); do #Check whether the service exists - service_name="ps -aux |grep -w ${service_filename[$i]} |grep -v grep" + service_name="ps |grep -w ${service_filename[$i]} |grep -v grep" count="${service_name}| wc -l" if [ $(eval ${count}) -gt 0 ]; then diff --git a/scripts/style_info.sh b/scripts/style_info.sh index b56eceeff..452240035 100755 --- a/scripts/style_info.sh +++ b/scripts/style_info.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + # Copyright © 2023 OpenIM. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,50 +14,53 @@ # See the License for the specific language governing permissions and # limitations under the License. +function style-info() { + COLOR_SUFFIX="\033[0m" # End all colors and special effects + + BLACK_PREFIX="\033[30m" # Black prefix + RED_PREFIX="\033[31m" # Red prefix + GREEN_PREFIX="\033[32m" # Green prefix + YELLOW_PREFIX="\033[33m" # Yellow prefix + BLUE_PREFIX="\033[34m" # Blue prefix + PURPLE_PREFIX="\033[35m" # Purple prefix + SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix + WHITE_PREFIX="\033[37m" # White prefix + BOLD_PREFIX="\033[1m" # Bold prefix + UNDERLINE_PREFIX="\033[4m" # Underline prefix + ITALIC_PREFIX="\033[3m" # Italic prefix + + CYAN_PREFIX="033[0;36m" # Cyan prefix + + BACKGROUND_BLACK="\033[40m" # Black background + BACKGROUND_RED="\033[41m" # Red background + BACKGROUND_GREEN="\033[42m" # Green background + BACKGROUND_YELLOW="\033[43m" # Yellow background + BACKGROUND_BLUE="\033[44m" # Blue background + BACKGROUND_PURPLE="\033[45m" # Purple background + BACKGROUND_SKY_BLUE="\033[46m" # Sky blue background + BACKGROUND_WHITE="\033[47m" # White background + + BLINK="\033[5m" # Blinking effect + INVERT="\033[7m" # Invert color + HIDE="\033[8m" # Hide text + + GRAY_PREFIX="\033[90m" # Gray prefix + LIGHT_RED_PREFIX="\033[91m" # Light red prefix + LIGHT_GREEN_PREFIX="\033[92m" # Light green prefix + LIGHT_YELLOW_PREFIX="\033[93m" # Light yellow prefix + LIGHT_BLUE_PREFIX="\033[94m" # Light blue prefix + LIGHT_PURPLE_PREFIX="\033[95m" # Light purple prefix + LIGHT_SKY_BLUE_PREFIX="\033[96m" # Light sky blue prefix + LIGHT_WHITE_PREFIX="\033[97m" # Light white prefix + + BACKGROUND_GRAY="\033[100m" # Gray background + BACKGROUND_LIGHT_RED="\033[101m" # Light red background + BACKGROUND_LIGHT_GREEN="\033[102m" # Light green background + BACKGROUND_LIGHT_YELLOW="\033[103m" # Light yellow background + BACKGROUND_LIGHT_BLUE="\033[104m" # Light blue background + BACKGROUND_LIGHT_PURPLE="\033[105m" # Light purple background + BACKGROUND_LIGHT_SKY_BLUE="\033[106m" # Light sky blue background + BACKGROUND_LIGHT_WHITE="\033[107m" # Light white background +} -COLOR_SUFFIX="\033[0m" # End all colors and special effects - -BLACK_PREFIX="\033[30m" # Black prefix -RED_PREFIX="\033[31m" # Red prefix -GREEN_PREFIX="\033[32m" # Green prefix -YELLOW_PREFIX="\033[33m" # Yellow prefix -BLUE_PREFIX="\033[34m" # Blue prefix -PURPLE_PREFIX="\033[35m" # Purple prefix -SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix -WHITE_PREFIX="\033[37m" # White prefix -BOLD_PREFIX="\033[1m" # Bold prefix -UNDERLINE_PREFIX="\033[4m" # Underline prefix -ITALIC_PREFIX="\033[3m" # Italic prefix - -CYAN_PREFIX="033[0;36m" # Cyan prefix - -BACKGROUND_BLACK="\033[40m" # Black background -BACKGROUND_RED="\033[41m" # Red background -BACKGROUND_GREEN="\033[42m" # Green background -BACKGROUND_YELLOW="\033[43m" # Yellow background -BACKGROUND_BLUE="\033[44m" # Blue background -BACKGROUND_PURPLE="\033[45m" # Purple background -BACKGROUND_SKY_BLUE="\033[46m" # Sky blue background -BACKGROUND_WHITE="\033[47m" # White background - -BLINK="\033[5m" # Blinking effect -INVERT="\033[7m" # Invert color -HIDE="\033[8m" # Hide text - -GRAY_PREFIX="\033[90m" # Gray prefix -LIGHT_RED_PREFIX="\033[91m" # Light red prefix -LIGHT_GREEN_PREFIX="\033[92m" # Light green prefix -LIGHT_YELLOW_PREFIX="\033[93m" # Light yellow prefix -LIGHT_BLUE_PREFIX="\033[94m" # Light blue prefix -LIGHT_PURPLE_PREFIX="\033[95m" # Light purple prefix -LIGHT_SKY_BLUE_PREFIX="\033[96m" # Light sky blue prefix -LIGHT_WHITE_PREFIX="\033[97m" # Light white prefix - -BACKGROUND_GRAY="\033[100m" # Gray background -BACKGROUND_LIGHT_RED="\033[101m" # Light red background -BACKGROUND_LIGHT_GREEN="\033[102m" # Light green background -BACKGROUND_LIGHT_YELLOW="\033[103m" # Light yellow background -BACKGROUND_LIGHT_BLUE="\033[104m" # Light blue background -BACKGROUND_LIGHT_PURPLE="\033[105m" # Light purple background -BACKGROUND_LIGHT_SKY_BLUE="\033[106m" # Light sky blue background -BACKGROUND_LIGHT_WHITE="\033[107m" # Light white background +style-info \ No newline at end of file diff --git a/scripts/wait-for-it.sh b/scripts/wait-for-it.sh new file mode 100755 index 000000000..32c1cbb0b --- /dev/null +++ b/scripts/wait-for-it.sh @@ -0,0 +1,186 @@ +#!/usr/bin/env bash + +# Copyright 2020 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. + +# Use this script to test if a given TCP host/port are available + +WAITFORIT_cmdname=${0##*/} + +openim_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" +source "${openim_root}/scripts/lib/color.sh" + +echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then info "$@" 1>&2; fi } + +usage() +{ + cat << USAGE >&2 +Usage: + $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args] + -h HOST | --host=HOST Host or IP under test + -p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port + -s | --strict Only execute subcommand if the test succeeds + -q | --quiet Don't output any status messages + -t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit 1 +} + +function wait_for() +{ + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + else + echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout" + fi + WAITFORIT_start_ts=$(date +%s) + while : + do + if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then + nc -z $WAITFORIT_HOST $WAITFORIT_PORT + WAITFORIT_result=$? + else + (echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 + WAITFORIT_result=$? + fi + if [[ $WAITFORIT_result -eq 0 ]]; then + WAITFORIT_end_ts=$(date +%s) + echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds" + break + fi + sleep 1 + done + return $WAITFORIT_result +} + +function wait_for_wrapper() +{ + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + if [[ $WAITFORIT_QUIET -eq 1 ]]; then + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + else + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + fi + WAITFORIT_PID=$! + trap "kill -INT -$WAITFORIT_PID" INT + wait $WAITFORIT_PID + WAITFORIT_RESULT=$? + if [[ $WAITFORIT_RESULT -ne 0 ]]; then + echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + fi + return $WAITFORIT_RESULT +} + +# process arguments +while [[ $# -gt 0 ]] +do + case "$1" in + *:* ) + WAITFORIT_hostport=(${1//:/ }) + WAITFORIT_HOST=${WAITFORIT_hostport[0]} + WAITFORIT_PORT=${WAITFORIT_hostport[1]} + shift 1 + ;; + --child) + WAITFORIT_CHILD=1 + shift 1 + ;; + -q | --quiet) + WAITFORIT_QUIET=1 + shift 1 + ;; + -s | --strict) + WAITFORIT_STRICT=1 + shift 1 + ;; + -h) + WAITFORIT_HOST="$2" + if [[ $WAITFORIT_HOST == "" ]]; then break; fi + shift 2 + ;; + --host=*) + WAITFORIT_HOST="${1#*=}" + shift 1 + ;; + -p) + WAITFORIT_PORT="$2" + if [[ $WAITFORIT_PORT == "" ]]; then break; fi + shift 2 + ;; + --port=*) + WAITFORIT_PORT="${1#*=}" + shift 1 + ;; + -t) + WAITFORIT_TIMEOUT="$2" + if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi + shift 2 + ;; + --timeout=*) + WAITFORIT_TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + WAITFORIT_CLI=("$@") + break + ;; + --help) + usage + ;; + *) + warn "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then + echoerr "Error: you need to provide a host and port to test." + usage +fi + +WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15} +WAITFORIT_STRICT=${WAITFORIT_STRICT:-0} +WAITFORIT_CHILD=${WAITFORIT_CHILD:-0} +WAITFORIT_QUIET=${WAITFORIT_QUIET:-0} + +# check to see if timeout is from busybox? +WAITFORIT_TIMEOUT_PATH=$(type -p timeout) +WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH) +if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then + WAITFORIT_ISBUSY=1 + WAITFORIT_BUSYTIMEFLAG="-t" + +else + WAITFORIT_ISBUSY=0 + WAITFORIT_BUSYTIMEFLAG="" +fi + +if [[ $WAITFORIT_CHILD -gt 0 ]]; then + wait_for + WAITFORIT_RESULT=$? + exit $WAITFORIT_RESULT +else + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + wait_for_wrapper + WAITFORIT_RESULT=$? + else + wait_for + WAITFORIT_RESULT=$? + fi +fi + +if [[ $WAITFORIT_CLI != "" ]]; then + if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then + echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess" + exit $WAITFORIT_RESULT + fi + exec "${WAITFORIT_CLI[@]}" +else + exit $WAITFORIT_RESULT +fi diff --git a/test/common.sh b/test/common.sh index 904608894..e583fe8b3 100644 --- a/test/common.sh +++ b/test/common.sh @@ -12,4 +12,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/test/wrktest.sh b/test/wrktest.sh new file mode 100755 index 000000000..f57d16402 --- /dev/null +++ b/test/wrktest.sh @@ -0,0 +1,274 @@ +#!/bin/bash + +# Copyright 2020 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. + +: << EOF +The API performance test script automatically executes wrk commands, collects data, analyzes it, and calls gnuplot to plot it + +Usage (to test API performance) : + +Start the openim-api(port 10002) + +Execute the test script: ./wrktest.sh + +The script will generate the data file.dat, each column meaning: concurrency QPS average response time success rate + +Usage (Compare the results of 2 tests) + +1. The performance test:. / wrktest. Sh openim apiserver - http://127.0.0.1:10002/healthz + +Execute the command:./wrktest.sh diff apiserver.dat http.dat + +> Note: Make sure you have wrk and gnuplot installed on your system + +EOF + +openim_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" +wrkdir="${openim_root}/_output/wrk" +jobname="openim-api" +duration="300s" +threads=$((3 * `grep -c processor /proc/cpuinfo`)) + +source "${openim_root}/scripts/lib/color.sh" + +# Set wrk options +openim::wrk::setup() { + #concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000 100000 200000 500000 1000000" + concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000" + cmd="wrk -t${threads} -d${duration} -T30s --latency" +} + +# Print usage infomation +openim::wrk::usage() +{ + cat << EOF + +Usage: $0 [OPTION] [diff] URL +Performance automation test script. + + URL HTTP request url, like: http://127.0.0.1:10002/healthz + diff Compare two performance test results + +OPTIONS: + -h Usage information + -n Performance test task name, default: apiserver + -d Directory used to store performance data and gnuplot graphic, default: _output/wrk + +Reprot bugs to <3293172751nss@gmail.com>. +EOF +} + +# Convert plot data to useable data +function openim::wrk::convert_plot_data() +{ + echo "$1" | awk -v datfile="${wrkdir}/${datfile}" ' { + if ($0 ~ "Running") { + common_time=$2 + } +if ($0 ~ "connections") { + connections=$4 + common_threads=$1 +} +if ($0 ~ "Latency ") { + avg_latency=convertLatency($2) +} +if ($0 ~ "50%") { + p50=convertLatency($2) +} +if ($0 ~ "75%") { + p75=convertLatency($2) +} +if ($0 ~ "90%") { + p90=convertLatency($2) +} +if ($0 ~ "99%") { + p99=convertLatency($2) +} +if ($0 ~ "Requests/sec") { + qps=$2 +} +if ($0 ~ "requests in") { + allrequest=$1 +} +if ($0 ~ "Socket errors") { + err=$4+$6+$8+$10 +} +} +END { +rate=sprintf("%.2f", (allrequest-err)*100/allrequest) +print connections,qps,avg_latency,rate >> datfile +} + +function convertLatency(s) { + if (s ~ "us") { + sub("us", "", s) + return s/1000 + } +if (s ~ "ms") { + sub("ms", "", s) + return s +} +if (s ~ "s") { + sub("s", "", s) + return s * 1000 +} +}' +} + +# Remove existing data file +function openim::wrk::prepare() +{ + rm -f ${wrkdir}/${datfile} +} + +# Plot according to gunplot data file +function openim::wrk::plot() { + gnuplot << EOF +set terminal png enhanced #输出格式为png文件 +set ylabel 'QPS' +set xlabel 'Concurrent' +set y2label 'Average Latency (ms)' +set key top left vertical noreverse spacing 1.2 box +set tics out nomirror +set border 3 front +set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2 +set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2 +set style data linespoints + +set grid #显示网格 +set xtics nomirror rotate #by 90#只需要一个x轴 +set mxtics 5 +set mytics 5 #可以增加分刻度 +set ytics nomirror +set y2tics + +set autoscale y +set autoscale y2 + +set output "${wrkdir}/${qpsttlb}" #指定数据文件名称 +set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}" +plot "${wrkdir}/${datfile}" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "QPS","${wrkdir}/${datfile}" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "Avg Latency (ms)" + +unset y2tics +unset y2label +set ytics nomirror +set yrange[0:100] +set output "${wrkdir}/${successrate}" #指定数据文件名称 +set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}" +plot "${wrkdir}/${datfile}" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#F62817" t "Success Rate" +EOF +} + +# Plot diff graphic +function openim::wrk::plot_diff() +{ + gnuplot << EOF +set terminal png enhanced #输出格式为png文件 +set xlabel 'Concurrent' +set ylabel 'QPS' +set y2label 'Average Latency (ms)' +set key below left vertical noreverse spacing 1.2 box autotitle columnheader +set tics out nomirror +set border 3 front +set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2 +set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2 +set style data linespoints + +#set border 3 lt 3 lw 2 #这会让你的坐标图的border更好看 +set grid #显示网格 +set xtics nomirror rotate #by 90#只需要一个x轴 +set mxtics 5 +set mytics 5 #可以增加分刻度 +set ytics nomirror +set y2tics + +#set pointsize 0.4 #点的像素大小 +#set datafile separator '\t' #数据文件的字段用\t分开 + +set autoscale y +set autoscale y2 + +#设置图像的大小 为标准大小的2倍 +#set size 2.3,2 + +set output "${wrkdir}/${t1}_${t2}.qps.ttlb.diff.png" #指定数据文件名称 +set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}" +plot "/tmp/plot_diff.dat" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "${t1} QPS","/tmp/plot_diff.dat" using 5:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" axis x1y1 t "${t2} QPS","/tmp/plot_diff.dat" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "${t1} Avg Latency (ms)", "/tmp/plot_diff.dat" using 6:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#6495ED" axis x2y2 t "${t2} Avg Latency (ms)" + +unset y2tics +unset y2label +set ytics nomirror +set yrange[0:100] +set output "${wrkdir}/${t1}_${t2}.successrate.diff.png" #指定数据文件名称 +set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}" +plot "/tmp/plot_diff.dat" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" t "${t1} Success Rate","/tmp/plot_diff.dat" using 7:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" t "${t2} Success Rate" +EOF +} + +# Start API performance testing +openim::wrk::start_performance_test() { + openim::wrk::prepare + + for c in ${concurrent} + do + wrkcmd="${cmd} -c ${c} $1" + echo "Running wrk command: ${wrkcmd}" + result=`eval ${wrkcmd}` + openim::wrk::convert_plot_data "${result}" + done + + echo -e "\nNow plot according to ${COLOR_MAGENTA}${wrkdir}/${datfile}${COLOR_NORMAL}" + openim::wrk::plot &> /dev/null + echo -e "QPS graphic file is: ${COLOR_MAGENTA}${wrkdir}/${qpsttlb}${COLOR_NORMAL} +Success rate graphic file is: ${COLOR_MAGENTA}${wrkdir}/${successrate}${COLOR_NORMAL}" +} + +while getopts "hd:n:" opt;do + case ${opt} in + d) + wrkdir=${OPTARG} + ;; + n) + jobname=${OPTARG} + ;; + ?) + openim::wrk::usage + exit 0 + ;; + esac +done + +shift $(($OPTIND-1)) + +mkdir -p ${wrkdir} +case $1 in + "diff") + if [ "$#" -lt 3 ];then + openim::wrk::usage + exit 0 + fi + + t1=$(basename $2|sed 's/.dat//g') # 对比图中红色线条名称 + t2=$(basename $3|sed 's/.dat//g') # 对比图中粉色线条名称 + + join $2 $3 > /tmp/plot_diff.dat + openim::wrk::plot_diff `basename $2` `basename $3` + exit 0 + ;; + *) + if [ "$#" -lt 1 ];then + openim::wrk::usage + exit 0 + fi + url="$1" + + qpsttlb="${jobname}_qps_ttlb.png" + successrate="${jobname}_successrate.png" + datfile="${jobname}.dat" + + openim::wrk::setup + openim::wrk::start_performance_test "${url}" + ;; +esac diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 000000000..13339766d --- /dev/null +++ b/tools/README.md @@ -0,0 +1,45 @@ +# Notes about go workspace + +As openim is using go1.18's [workspace feature](https://go.dev/doc/tutorial/workspaces), once you add a new module, you need to run `go work use -r .` at root directory to update the workspace synced. + +### Create a new extensions + +1. Create your tools_name directory in pkg `/tools` first and cd into it. +2. Init the project. +3. Then `go work use -r .` at current directory to update the workspace. +4. Create your tools + +You can execute the following commands to do things above: + +```bash +# 4dd91a700d3f:/openim# tree +# . +# ├── LICENSE +# ├── README.md +# ├── openim-chat +# │ ├── bin +# │ ├── config +# │ ├── logs +# │ └── scripts +# ├── openim-server +# │ ├── bin +# │ ├── config +# │ ├── logs +# │ └── scripts +# ├── openkf +# │ ├── bin +# │ ├── config +# │ ├── logs +# │ └── scripts +# cd tools_code_dir +# edit the CRD_NAME and CRD_GROUP to your own +export OPENIM_TOOLS_NAME= + +# copy and paste to create a new CRD and Controller +mkdir tools/${OPENIM_TOOLS_NAME} +cd tools/${OPENIM_TOOLS_NAME} +go mod init github.com/OpenIMSDK/Open-IM-Server/tools/${OPENIM_TOOLS_NAME} +go mod tidy +go work use -r . +cd ../.. +``` \ No newline at end of file diff --git a/tools/infra/go.mod b/tools/infra/go.mod new file mode 100644 index 000000000..66a5b837d --- /dev/null +++ b/tools/infra/go.mod @@ -0,0 +1,3 @@ +module github.com/OpenIMSDK/Open-IM-Server/tools/infra + +go 1.20 diff --git a/tools/infra/main.go b/tools/infra/main.go new file mode 100644 index 000000000..55243d386 --- /dev/null +++ b/tools/infra/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "log" +) + +func main() { + log.Println("Current module is still under development.") + message := ` +Current module is still under development. + +____ _____ __ __ +/ __ \ |_ _|| \/ | +| | | | _ __ ___ _ __ | | | \ / | +| | | || '_ \ / _ \| '_ \ | | | |\/| | +| |__| || |_) || __/| | | | _| |_ | | | | +\____/ | .__/ \___||_| |_||_____||_| |_| + | | + |_| + +Keep checking for updates! +` + + fmt.Println(message) +} diff --git a/tools/ncpu/go.mod b/tools/ncpu/go.mod new file mode 100644 index 000000000..c42fd4cc2 --- /dev/null +++ b/tools/ncpu/go.mod @@ -0,0 +1,5 @@ +module github.com/OpenIMSDK/Open-IM-Server/tools/ncpu + +go 1.20 + +require go.uber.org/automaxprocs v1.5.3 diff --git a/tools/ncpu/go.sum b/tools/ncpu/go.sum new file mode 100644 index 000000000..804f593b5 --- /dev/null +++ b/tools/ncpu/go.sum @@ -0,0 +1,7 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= +go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/tools/ncpu/main.go b/tools/ncpu/main.go new file mode 100644 index 000000000..b55852554 --- /dev/null +++ b/tools/ncpu/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" + "runtime" + + "go.uber.org/automaxprocs/maxprocs" +) + +func main() { + maxprocs.Set() + fmt.Print(runtime.GOMAXPROCS(0)) +}