fix: token update

Signed-off-by: Gordon <1432970085@qq.com>
pull/699/head
Gordon 2 years ago
commit bc70c5bb15

@ -1,5 +1,5 @@
USER=root
PASSWORD=openIM123
MINIO_ENDPOINT=http://116.30.3.80:10005
API_URL=http://116.30.3.80:10002/object/
DATA_DIR=./
MINIO_ENDPOINT=http://113.99.98.99:10005
API_URL=http://113.99.98.99:10002/object/
DATA_DIR=./

@ -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.
coverage:
status:
project:

14
.github/labels.yml vendored

@ -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.
# Refer to Kubernetes for size/* Settings
# https://github.com/Kubernetes/Kubernetes
XS:

14
.github/sync.yml vendored

@ -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.
# https://github.com/BetaHuhn/repo-file-sync-action
# Synchronization for the.github repository
OpenIMSDK/.github:

@ -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.
# https://github.com/apps/weekly-digest/installations/new
publishDay: sun
canPublishIssues: true

@ -1,3 +1,17 @@
# 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: Assign issue to comment author
on:
issue_comment:

@ -1,3 +1,17 @@
# 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: Auto PR to release
on:
@ -5,16 +19,10 @@ on:
# types:
# - closed
env:
GH_TOKEN: ${{ secrets.REDBOT_GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
jobs:
create-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
if: github.event.pull_request.base.ref == 'main'
steps:
- name: Check out code
uses: actions/checkout@v3
@ -29,14 +37,14 @@ jobs:
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: 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 642 --repo $OWNER/$REPO | grep -oP 'Fixes #\K\d+')
ISSUEID=$(gh pr view ${{ github.event.pull_request.number }} --repo $OWNER/$REPO | grep -oP 'Fixes #\K\d+')
echo "===========> $ISSUEID"
ISSUE=$(gh issue view $ISSUEID --repo $OWNER/$REPO --json labels,assignees,milestone,title)
echo "===========> $ISSUE"
@ -46,12 +54,17 @@ jobs:
MILESTONE=$(echo $ISSUE | jq -r '.milestone | select(.title) | .title')
TITLE=$(echo $ISSUE | jq -r '.title')
echo $ISSUE | jq
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 ""
# 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"
# 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:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
GH_TOKEN: ${{ github.token }}
ISSUE: ${{ github.event.issue.html_url }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}

@ -1,3 +1,17 @@
# 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: Invite users to join our group
on:
issue_comment:

@ -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: 'Github Rebot for Cherry Pick when PR is merged'
on:
pull_request_target:

@ -1,3 +1,17 @@
# 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: Github Rebot for Cherry Pick On Comment
on:
issue_comment:

@ -12,38 +12,99 @@
# See the License for the specific language governing permissions and
# limitations under the License.
name: OpenIM Build Docker Images
name: Publish Docker image
on:
push:
branches:
- main
tags:
- v*
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
bin:
- openim-server
steps:
- name: Checkout
- name: Check out the repo
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ghcr.io/${{ github.repository_owner }}/openim-${{ matrix.bin }}
- name: Build and release Docker images
uses: docker/build-push-action@v3
images: openim/openim-server
tags: latest
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
platforms: linux/386,linux/amd64,linux/arm64/v8
target: ${{ matrix.bin }}
tags: ${{ steps.metadata.outputs.tags }}
push: true
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Log in to AliYun Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: ${{ secrets.ALIREGISTRY_USERNAME }}
password: ${{ secrets.ALIREGISTRY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta2
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server
tags: latest
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta2.outputs.tags }}
labels: ${{ steps.meta2.outputs.labels }}
# name: OpenIM Build Docker Images
# on:
# push:
# tags:
# - v*
# jobs:
# build:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# bin:
# - openim-server
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Setup Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Docker metadata
# id: metadata
# uses: docker/metadata-action@v4
# with:
# images: ghcr.io/${{ github.repository_owner }}/openim-${{ matrix.bin }}
# - name: Build and release Docker images
# uses: docker/build-push-action@v3
# with:
# platforms: linux/386,linux/amd64,linux/arm64/v8
# target: ${{ matrix.bin }}
# tags: ${{ steps.metadata.outputs.tags }}
# push: true

@ -1,3 +1,17 @@
# 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: Check-Coverage
on:

@ -1,3 +1,17 @@
# 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: "OpenIM CLA Assistant"
on:
issue_comment:

@ -13,7 +13,7 @@
# limitations under the License.
name: "Code Scanning - Action"
name: "OpenIM Code Scanning - Action"
on:
push:
@ -42,8 +42,8 @@ jobs:
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
actions: write
contents: write
steps:
- name: Checkout repository
@ -53,8 +53,8 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java, ruby
with:
languages: go
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
@ -68,9 +68,9 @@ jobs:
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language
#- run: |
# make bootstrap
# make release
# - run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

@ -0,0 +1,62 @@
name: Create Branch on Tag
on:
push:
tags:
- 'v*.*.0'
jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git
run: |
git config --global user.name 'kubbot'
git config --global user.email '3293172751yxy@gmail.com'
- name: Install git-chglog
run: make install.git-chglog
- name: Create Branch
run: |
TAG_NAME=${GITHUB_REF/refs\/tags\//}
IFS='.' read -ra VERSION_PARTS <<< "$TAG_NAME"
if [[ "${VERSION_PARTS[2]}" = "0" ]]; then
BRANCH_NAME="release-v${VERSION_PARTS[0]}.${VERSION_PARTS[1]}"
echo "Creating branch $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
fi
- name: Push Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Auto Commit CHANGELOG"
branch: release-v${VERSION_PARTS[0]}.${VERSION_PARTS[1]}
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
- name: Create and Push CHANGELOG
run: |
git checkout main
TAG_NAME=${GITHUB_REF/refs\/tags\//}
IFS='.' read -ra VERSION_PARTS <<< "$TAG_NAME"
if [[ "${VERSION_PARTS[2]}" = "0" ]]; then
cd CHANGELOG
git-chglog --tag-filter-pattern "v${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.*" -o "CHANGELOG-${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.md"
git add "CHANGELOG-${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.md"
git commit -m "Update CHANGELOG for $TAG_NAME"
fi
- name: Push Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Auto Commit CHANGELOG"
branch: main
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

@ -1,3 +1,17 @@
# 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: deploy for dev
on:

@ -1,2 +1,16 @@
# 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: OpenIM e2e Test

@ -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: OpenIM Run Gosec
# gosec is a source code security audit tool for the Go language. It performs a static

@ -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: Good frist issue add comment
on:
issues:

@ -1,3 +1,17 @@
# 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: 'issue translator'
on:
issue_comment:

@ -1,12 +1,23 @@
# 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: Github Rebot for Link check error
# Every Monday at 12:30 p.m
on:
schedule:
- cron: '30 12 * * 1'
push:
branches:
- main
jobs:
linkChecker:

@ -1,3 +1,17 @@
# 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: 'Lock Threads'
on:

@ -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: 'OpenIM Commit Action'
on:

@ -128,6 +128,14 @@ jobs:
# commit_author: Kubbot # defaults to author of the commit that triggered the run
continue-on-error: true
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore(fmt): robot automated format and lint Change"
commit_options: '--no-verify --signoff'
branch: main
continue-on-error: true
- name: Set Current Directory
id: set_directory
run: |

@ -1,11 +1,24 @@
# 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: Github Pull Request
on:
push:
branches: [main]
paths-ignore:
- 'README.md'
- 'CONTRIBUTING.md'
- 'CONTRIBUTING.md'
- 'docs/**'
pull_request:
branches: [main]
@ -22,18 +35,80 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get League branch Patch
run: |
git config user.name 'openimbot'
git config user.email 'openimsdk@qq.com'
git checkout -b cicd/patch-${{ github.event.number }}
- uses: actions/setup-node@v3
- name: Setup Go
uses: actions/setup-go@v2
- name: Run go modules tidy
run: |
sudo make tidy
sudo make tools.verify.go-gitlint
echo "Run go modules tidy successfully"
- name: Run go format
run: |
sudo make format
echo "Run go format successfully"
continue-on-error: true
- name: Generate all necessary files, such as error code files
run: |
make generate
echo "Generate all necessary files successfully"
continue-on-error: true
- name: Run unit test and get test coverage
run: |
make cover
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
sudo make add-copyright
echo "OpenIM verify successfully"
continue-on-error: true
- name: Commit code
run: |
git add .
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
commit-message: 'build: update distribution'
title: 'build: update distribution'
commit-message: "cicd: bump League Patch to cicd/patch-${{ github.event.number }}"
title: Bump League Patch to cicd/patch-${{ github.event.number }}
body: |
- Updates the distribution for changes on `main`
Auto-generated by [create-pull-request][1]
[1]: https://github.com/OpenIMSDK/Open-IM-Sever
branch: 'bot/update-distribution'
Review criteria:
- [ ] Disenchanter can connect and issue actions
This is an automated PR.
<sub>[workflow](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/.github/workflows/pull-request.yml).</sub>
base: main
branch: cicd/patch-${{ github.event.number }}
labels: kind/documentation, area/test, ok-to-test
token: ${{ secrets.REDBOT_GITHUB_TOKEN }}

@ -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: OpenIM Server Release
on:

@ -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: OpenIM Start Execute Scripts
on:

@ -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.
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# You can adjust the behavior by modifying this file.

@ -36,8 +36,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-cmdutils
id: openim-cmdutils
main: ./cmd/openim-cmdutils/main.go
@ -53,8 +54,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-crontask
id: openim-crontask
main: ./cmd/openim-crontask/main.go
@ -70,8 +72,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-msggateway
id: openim-msggateway
main: ./cmd/openim-msggateway/main.go
@ -87,8 +90,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-msgtransfer
id: openim-msgtransfer
main: ./cmd/openim-msgtransfer/main.go
@ -104,8 +108,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-push
id: openim-push
main: ./cmd/openim-push/main.go
@ -121,8 +126,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-auth
id: openim-rpc-auth
main: ./cmd/openim-rpc/openim-rpc-auth/main.go
@ -138,8 +144,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-conversation
id: openim-rpc-conversation
main: ./cmd/openim-rpc/openim-rpc-conversation/main.go
@ -155,8 +162,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-friend
id: openim-rpc-friend
main: ./cmd/openim-rpc/openim-rpc-friend/main.go
@ -172,8 +180,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-group
id: openim-rpc-group
main: ./cmd/openim-rpc/openim-rpc-group/main.go
@ -189,8 +198,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-msg
id: openim-rpc-msg
main: ./cmd/openim-rpc/openim-rpc-msg/main.go
@ -206,8 +216,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-third
id: openim-rpc-third
main: ./cmd/openim-rpc/openim-rpc-third/main.go
@ -223,8 +234,9 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
- binary: openim-rpc-user
id: openim-rpc-user
main: ./cmd/openim-rpc/openim-rpc-user/main.go
@ -240,8 +252,8 @@ builds:
- ppc64le
- arm64
goarm:
- 6
- 7
- "6"
- "7"
archives:
- format: tar.gz
@ -323,6 +335,66 @@ changelog:
- title: Other work
order: 9999
dockers:
- image_templates:
- "openimsdk/open-im-server:{{ .Tag }}-amd64"
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md"
- "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png"
- '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]'
- "--label=io.artifacthub.package.license=Apace-2.0"
- "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"
extra_files:
- scripts/entrypoint.sh
- image_templates:
- "goreleaser/goreleaser:{{ .Tag }}-arm64"
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md"
- "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png"
- '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]'
- "--label=io.artifacthub.package.license=Apace-2.0"
- "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
goarch: arm64
extra_files:
- scripts/entrypoint.sh
docker_manifests:
- name_template: "goreleaser/goreleaser:{{ .Tag }}"
image_templates:
- "goreleaser/goreleaser:{{ .Tag }}-amd64"
- "goreleaser/goreleaser:{{ .Tag }}-arm64"
- name_template: "ghcr.io/goreleaser/goreleaser:{{ .Tag }}"
image_templates:
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
- name_template: "goreleaser/goreleaser:latest"
image_templates:
- "goreleaser/goreleaser:{{ .Tag }}-amd64"
- "goreleaser/goreleaser:{{ .Tag }}-arm64"
- name_template: "ghcr.io/goreleaser/goreleaser:latest"
image_templates:
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
- "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
nfpms:
- id: packages
@ -412,37 +484,37 @@ release:
## Helping out
We release logs are recorded on [✨ CHANGELOG](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CHANGELOG/CHANGELOG.md)
This release is only possible thanks to **all** the support of some **awesome people**!
Want to be one of them?
**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.
<p align="center">
<a href="https://github.com/openimbot/openimbot/blob/main/assets/icon/blue%E9%80%8F%E6%98%8E.png" style="float: left; margin-right: 10px;">
<a href="https://github.com/kubbot" style="float: left; margin-right: 10px;">
<img src="https://github.com/openimbot/openimbot/blob/main/assets/icon/blue%E9%80%8F%E6%98%8E.png" width="50" height="50" />
</a>
<a href="https://www.openim.online">
<img src="https://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo.png" />
</a>
<a href="https://github.com/openimbot/openimbot/blob/main/assets/icon/red%E9%80%8F%E6%98%8E.png" style="float: right; margin-left: 10px;">
<a href="https://github.com/openimbot" style="float: right; margin-left: 10px;">
<img src="https://github.com/openimbot/openimbot/blob/main/assets/icon/red%E9%80%8F%E6%98%8E.png" width="50" height="50" />
</a>
</p>
## Contact Us
## Get Involved with OpenIM!
We value close connections with our users, developers, and contributors here at OpenIMSDK. With a large community and maintainer team, we're always here to help and support you. Whether you're looking to join our community or have any questions or suggestions, we welcome you to get in touch with us.
**Here are some ways to get involved with the OpenIM community:**
Our most recommended way to get in touch is through [Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg). Even if you're in China, Slack is usually not blocked by firewalls, making it an easy way to connect with us. Our Slack community is the ideal place to discuss and share ideas and suggestions with other users and developers of OpenIMSDK. You can ask technical questions, seek help, or share your experiences with other users of OpenIMSDK.
📢 **Slack Channel**: Join our Slack channels for discussions, communication, and support. Click [here](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to join the Open-IM-Server Slack team channel.
In [OpenIM community is recruiting new members! discussion](https://github.com/orgs/OpenIMSDK/discussions/426) please leave your information, convenient we will better developers around the small gift to send to your hands.
📧 **Gmail Contact**: If you have any questions, suggestions, or feedback for our open-source projects, please feel free to [contact us via email](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=winxu81@gmail.com).
In addition to Slack, we also offer the following ways to get in touch:
📖 **Blog**: Stay up-to-date with OpenIM-Server projects and trends by reading our [blog](https://doc.rentsoft.cn/). We share the latest developments, tech trends, and other interesting information related to OpenIM.
+ <a href="https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg" target="_blank"><img src="https://img.shields.io/badge/slack-%40OpenIMSDKCore-informational?logo=slack&style=flat-square"></a>: We also have Slack channels for you to communicate and discuss. To join, visit https://slack.com/ and join our [👀 Open-IM-Server slack](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) team channel.
+ <a href="https://mail.google.com/mail/u/0/?fs=1&tf=cm&to=4closetool3@gmail.com" target="_blank"><img src="https://img.shields.io/badge/gmail-%40OOpenIMSDKCore?style=social&logo=gmail"></a>: Get in touch with us on [Gmail](winxu81@gmail.com). If you have any questions or issues that need resolving, or any suggestions and feedback for our open source projects, please feel free to contact us via email.
+ <a href="https://doc.rentsoft.cn/" target="_blank"><img src="https://img.shields.io/badge/%E5%8D%9A%E5%AE%A2-%40OpenIMSDKCore-blue?style=social&logo=Octopus%20Deploy"></a>: Read our [blog](https://doc.rentsoft.cn/). Our blog is a great place to stay up-to-date with Open-IM-Server projects and trends. On the blog, we share our latest developments, tech trends, and other interesting information.
+ <a href="https://github.com/OpenIMSDK/OpenIM-Docs/blob/main/docs/images/WechatIMG20.jpeg" target="_blank"><img src="https://img.shields.io/badge/%E5%BE%AE%E4%BF%A1-OpenIMSDKCore-brightgreen?logo=wechat&style=flat-square"></a>: Add [Wechat](https://github.com/OpenIMSDK/OpenIM-Docs/blob/main/docs/images/WechatIMG20.jpeg) and indicate that you are a user or developer of Open-IM-Server. We will process your request as soon as possible.
📱 **WeChat**: Add us on WeChat (QR Code) and indicate that you are a user or developer of Open-IM-Server. We'll process your request as soon as possible.
Whether you're looking to join our community or have any questions or suggestions, we welcome you to get in touch with us.
Remember, your contributions play a vital role in making OpenIM successful, and we look forward to your active participation in our community! 🙌

@ -1,6 +1,7 @@
# Changelog
- [Changelog](#changelog)
- [OpenIM versioning policy](#openim-versioning-policy)
- [command](#command)
- [create next tag](#create-next-tag)
- [Release version logs](#release-version-logs)
@ -15,6 +16,10 @@ All notable changes to this project will be documented in this file.
+ [https://github.com/OpenIMSDK/Open-IM-Server/releases](https://github.com/OpenIMSDK/Open-IM-Server/releases)
## OpenIM versioning policy
+ [OpenIM Version](../docs/conversions/version.md)
## command
```bash

@ -68,6 +68,11 @@ multiarch:
install:
@$(MAKE) go.install
## check: Check OpenIM deployment ✨
.PHONY: check
check:
@$(MAKE) go.check
## tidy: tidy go.mod ✨
.PHONY: tidy
tidy:
@ -176,6 +181,11 @@ verify-copyright:
add-copyright:
@$(MAKE) copyright.add
## advertise: Project introduction, become a contributor ✨
.PHONY: advertise
advertise:
@$(MAKE) copyright.advertise
## release: release the project ✨
.PHONY: release
release: release.verify release.ensure-tag

@ -13,7 +13,7 @@
<a href="https://goreportcard.com/report/github.com/OpenIMSDK/Open-IM-Server"><img src="https://goreportcard.com/badge/github.com/OpenIMSDK/Open-IM-Server" alt="A+"></a>
<a href="https://github.com/OpenIMSDK/Open-IM-Server/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22good+first+issue%22"><img src="https://img.shields.io/github/issues/OpenIMSDK/Open-IM-Server/good%20first%20issue?logo=%22github%22" alt="good first"></a>
<a href="https://github.com/OpenIMSDK/Open-IM-Server"><img src="https://img.shields.io/github/stars/OpenIMSDK/Open-IM-Server.svg?style=flat&logo=github&colorB=deeppink&label=stars"></a>
<a href="https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg"><img src="https://img.shields.io/badge/Slack-100%2B-blueviolet?logo=slack&amp;logoColor=white"></a>
<a href="https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg"><img src="https://img.shields.io/badge/Slack-300%2B-blueviolet?logo=slack&amp;logoColor=white"></a>
<a href="https://github.com/OpenIMSDK/Open-IM-Server/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green"></a>
<a href="https://golang.org/"><img src="https://img.shields.io/badge/Language-Go-blue.svg"></a>
</p>
@ -51,15 +51,15 @@ Open-IM-Server is not a standalone product and does not include account registra
1. Clone the project
```
clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```bash
# choose what you need
BRANCH=release-v3.0
git clone -b $BRANCH https://github.com/OpenIMSDK/Open-IM-Server openim && export openim=$(pwd)/openim && cd $openim && make build
```
1. Modify .env
2. Modify .env
```
```bash
USER=root #no need to modify
PASSWORD=openIM123 #A combination of 8 or more numbers and letters, this password applies to redis, mysql, mongo, as well as accessSecret in config/config.yaml
ENDPOINT=http://127.0.0.1:10005 #minio's external service IP and port, or use the domain name storage.xx.xx, the app must be able to access this IP and port or domain,
@ -67,20 +67,19 @@ API_URL=http://127.0.0.1:10002/object/ #the app must be able to access this IP a
DATA_DIR=./ #designate large disk directory
```
1. Deploy and start
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.
> **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.
```
chmod +x install_im_server.sh;
./install_im_server.sh;
make install
```
1. Check the service
4. Check the service
```
cd scripts;
./docker_check_service.sh
```bash
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)
@ -89,23 +88,15 @@ cd scripts;
### Compile from source
1. Go 1.18 or higher version.
2. Clone
```
git clone https://github.com/OpenIMSDK/Open-IM-Server
cd Open-IM-Server
git checkout release-v3.0 #or other release branch
```
3. Compile
Ur need `Go 1.18` or higher version, and `make`.
```bash
# choose what you need
BRANCH=release-v3.0
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)
```
cd Open-IM-server/scripts
chmod +x *.sh
./build_all_service.sh
```
`make help` to help you see the instructions supported by OpenIM.
All services have been successfully built as shown in the figure

@ -0,0 +1,12 @@
FROM golang:1.20.0 as build
WORKDIR /openim
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
mkdir -p /var/log/miniblog
COPY miniblog /openim
EXPOSE 10002
CMD ["./bin/openim-api","--port", "10002"]

@ -12,89 +12,145 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#OpenIM config
#---------------Infrastructure configuration---------------------#
# -----------------------------------------------------------------
# Infrastructural configurations, please modify based on your setup
# -----------------------------------------------------------------
###################### Zookeeper ######################
# Zookeeper configuration
# It's not recommended to modify the schema
#
# Zookeeper address
# 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
# Currently, only single machine setup is supported
#
# Maximum number of open connections
# Maximum number of idle connections
# Maximum lifetime in seconds a connection can be reused
# Log level: 1=slient, 2=error, 3=warn, 4=info
# Slow query threshold in milliseconds
mysql:
address: [ 127.0.0.1:13306 ] #目前仅支持单机
address: [ 127.0.0.1:13306 ]
username: root
password: openIM123
database: openIM_v3 #不建议修改
maxOpenConn: 1000 #最大连接数
maxIdleConn: 100 #最大空闲连接数
maxLifeTime: 60 #连接可以重复使用的最长时间(秒)
logLevel: 4 #日志级别 1=slient 2=error 3=warn 4=info
slowThreshold: 500 #慢语句阈值 (毫秒)
database: openIM_v3
maxOpenConn: 1000
maxIdleConn: 100
maxLifeTime: 60
logLevel: 4
slowThreshold: 500
###################### Mongo ######################
# MongoDB configuration
# If uri is not empty, it will be used directly
#
# MongoDB address for standalone setup, Mongos address for sharded cluster setup
# Default MongoDB database name
# Maximum connection pool size
mongo:
uri: #不为空则直接使用该值
address: [ 127.0.0.1:37017 ] #单机时为mongo地址使用分片集群时为mongos地址
database: openIM_v3 #mongo db 默认即可
uri:
address: [ 127.0.0.1:37017 ]
database: openIM_v3
username: root
password: openIM123
maxPoolSize: 100
maxPoolSize: 100
###################### Redis ######################
# Redis configuration
#
# Username is required only for Redis version 6.0+
redis:
address: [ 127.0.0.1:16379 ] #
username: #only redis version 6.0+ need username
address: [ 127.0.0.1:16379 ]
username:
password: openIM123
###################### Kafka ######################
# Kafka configuration
#
# Kafka username
# Kafka password
# It's not recommended to modify this topic name
# Consumer group ID, it's not recommended to modify
kafka:
username: #用户名
password: #密码
addr: [ 127.0.0.1:9092 ] #
username:
password:
addr: [ 127.0.0.1:9092 ]
latestMsgToRedis:
topic: "latestMsgToRedis" #不建议修改
topic: "latestMsgToRedis"
offlineMsgToMongo:
topic: "offlineMsgToMongoMysql" #不建议修改
topic: "offlineMsgToMongoMysql"
msgToPush:
topic: "msgToPush" #不建议修改
consumerGroupID: #消费者组,不建议修改
msgToRedis: redis #
msgToMongo: mongo #
msgToMySql: mysql #
msgToPush: push #
topic: "msgToPush"
consumerGroupID:
msgToRedis: redis
msgToMongo: mongo
msgToMySql: mysql
msgToPush: push
###################### RPC ######################
# RPC configuration
#
# IP address to register with zookeeper when starting RPC, the IP and corresponding rpcPort should be accessible by api/gateway
# Default listen IP is 0.0.0.0
rpc:
registerIP: #作为rpc启动时注册到zookeeper的IPapi/gateway能访问到此ip和对应的rpcPort中的端口
listenIP: #默认为0.0.0.0
registerIP:
listenIP: 0.0.0.0
###################### API ######################
# API configuration
#
# API service port
# Default listen IP is 0.0.0.0
api:
openImApiPort: [ 10002 ] #api服务端口
listenIP: #默认为0.0.0.0
openImApiPort: [ 10002 ]
listenIP: 0.0.0.0
###################### Gateway ######################
# Object storage configuration
#
# Use minio for object storage
# API URL should be accessible by the app
# It's not recommended to modify the bucket name
# Endpoint should be accessible by the app
# Session token
# Configuration for Tencent COS
# Configuration for Aliyun OSS
object:
enable: "minio" #使用minio
apiURL: "http://127.0.0.1:10002/object/" #地址需要app能访问到
enable: "minio"
apiURL: "http://127.0.0.1:10002/object/"
minio:
bucket: "openim" #不建议修改
endpoint: http://127.0.0.1:10005 #地址需要app能够访问
bucket: "openim"
endpoint: http://127.0.0.1:10005
accessKeyID: root
secretAccessKey: openIM123
sessionToken: "" #token
cos: #tencent cos
sessionToken: ""
cos:
bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com"
secretID: ""
secretKey: ""
sessionToken: ""
oss: #ali oss
oss:
endpoint: "https://oss-cn-chengdu.aliyuncs.com"
bucket: "demo-9999999"
bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com"
accessKeyID: ""
accessKeyID: root
accessKeySecret: ""
sessionToken: ""
rpcPort: #rpc服务端口不建议修改端口由脚本读取后传入程序如启动多个程序只需要填入多个端口用逗号隔开如 [10110, 10111]
# RPC service ports
# 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:
openImUserPort: [ 10110 ]
openImFriendPort: [ 10120 ]
openImMessagePort: [ 10130 ]
@ -105,7 +161,8 @@ rpcPort: #rpc服务端口不建议修改端口由脚本读取后传入程
openImConversationPort: [ 10180 ]
openImThirdPort: [ 10190 ]
rpcRegisterName: #rpc注册服务名不建议修改
# RPC service names for registration, it's not recommended to modify these
rpcRegisterName:
openImUserName: User
openImFriendName: Friend
openImMsgName: Msg
@ -116,78 +173,132 @@ rpcRegisterName: #rpc注册服务名不建议修改
openImConversationName: Conversation
openImThirdName: Third
# Log configuration
#
# Storage directory
# Log rotation time
# Maximum number of logs to retain
# Log level, 6 means all levels
# Whether to output to stdout
# Whether to output in json format
# Whether to include stack trace in logs
log:
storageLocation: ../../../../../logs/ #存放目录
rotationTime: 24 #日志旋转时间
remainRotationCount: 2 #日志数量
remainLogLevel: 6 #日志级别 6表示全都打印
isStdout: false
isJson: false
storageLocation: ../../../../../logs/
rotationTime: 24
remainRotationCount: 2
remainLogLevel: 6
isStdout: false
isJson: false
withStack: false
# Long connection server configuration
#
# Websocket port for msg_gateway
# Maximum number of websocket connections
# Maximum length of websocket request package
# Websocket connection handshake timeout
longConnSvr:
openImWsPort: [ 10001 ] #msg_gateway的websocket端口
websocketMaxConnNum: 100000 #websocket最大连接数
websocketMaxMsgLen: 4096 #websocket请求包最大长度
websocketTimeout: 10 #websocket连接握手超时时间
openImWsPort: [ 10001 ]
websocketMaxConnNum: 100000
websocketMaxMsgLen: 4096
websocketTimeout: 10
# Push notification service configuration
#
# Use GeTui for push notifications
# GeTui offline push configuration
# FCM offline push configuration
# Account file, place it in the config directory
# JPush configuration, modify these after applying in JPush backend
push:
enable: getui
geTui: #个推离线推送
geTui:
pushUrl: "https://restapi.getui.com/v2/$appId"
masterSecret: ""
appKey: ""
intent: ""
channelID: ""
channelName: ""
fcm: #fcm离线推送
serviceAccount: "x.json" #帐号文件,并放在 config目录下
jpns: #极光推送 在极光后台申请后,修改以下四项
fcm:
serviceAccount: "x.json"
jpns:
appKey:
masterSecret:
pushUrl:
pushIntent:
# App manager configuration
#
# Built-in app manager user IDs
# Built-in app manager nicknames
manager:
userID: [ "openIM123456","openIM654321","openIMAdmin" ] #内置的app管理员userID
nickname: [ "system1","system2", "system3" ] #内置的app管理员nickname
userID: [ "openIM123456","openIM654321","openIMAdmin" ]
nickname: [ "system1","system2", "system3" ]
# Multi-platform login policy
# For each platform(Android, iOS, Windows, Mac, web), only one can be online at a time
multiLoginPolicy: 1
# Whether to store messages in MySQL, messages in MySQL are only used for management background
chatPersistenceMysql: true
# Message cache timeout in seconds, it's not recommended to modify
msgCacheTimeout: 86400
# Whether to enable read receipts for group chat
groupMessageHasReadReceiptEnable: true
multiLoginPolicy: 1 #多平台登录Android、iOS、Windows、Mac、web 每种平台只能有一个在线
# Whether to enable read receipts for single chat
singleMessageHasReadReceiptEnable: true
# MongoDB offline message retention period in days
retainChatRecords: 365
chatPersistenceMysql: true #消息是否存入mysqlmysql中的消息仅用于管理后台使用
msgCacheTimeout: 86400 #信消息缓存时间秒,不建议修改
groupMessageHasReadReceiptEnable: true #群聊已读是否开启
singleMessageHasReadReceiptEnable: true #单聊已读是否开启
# Schedule to clear expired messages(older than retainChatRecords days) in MongoDB every Wednesday at 2am
# This deletion is just for cleaning up disk usage according to previous configuration retainChatRecords, no notification will be sent
chatRecordsClearTime: "0 2 * * 3"
retainChatRecords: 365 #mongo保存离线消息时间
chatRecordsClearTime: "0 2 * * 3" #每周三凌晨2点清理mongo中的过期超过retainChatRecords时间消息这个删除是为了清理满足上个配置retainChatRecords的过期消息不会发送通知仅仅作为清理磁盘使用
msgDestructTime: "0 2 * * *" #消息自动删除时间每天凌晨2点删除过期消息这个删除是为了删除保留时间超过超过会话字段msg_destruct_time的消息。
# Schedule to auto delete messages every day at 2am
# This deletion is for messages that have been retained for more than msg_destruct_time (seconds) in the conversation field
msgDestructTime: "0 2 * * *"
# Secret key
secret: openIM123
# Token policy
#
# Token expiration period in days
tokenPolicy:
expire: 90 #过期时间(天)
expire: 90
# Message verification policy
#
# Whether to verify friendship when sending messages
messageVerify:
friendVerify: false #发送消息时是否验证好友关系
friendVerify: false
#ios系统推送声音以及标记计数
# iOS push notification configuration
#
# iOS push notification sound
# Whether to count badge
# Whether it's production environment
iosPush:
pushSound: "xxx"
badgeCount: true
production: false
# Callback configuration
#
# Callback URL
# Whether to enable this callback event
# Timeout in seconds
# Whether to continue execution if callback fails
callback:
# 回调callback
url:
beforeSendSingleMsg:
enable: false #是否启用此回调事件
timeout: 5 #超时时间(秒)
failedContinue: true #如回调失败是否继续往后执行
enable: false
timeout: 5
failedContinue: true
afterSendSingleMsg:
enable: false
timeout: 5
@ -244,8 +355,11 @@ callback:
timeout: 5
failedContinue: true
prometheus: #prometheus每个服务的端口数量需要和rpcPort保持对应
###################### Prometheus ######################
# Prometheus configuration
# The number of Prometheus ports per service needs to correspond to rpcPort
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
prometheus:
enable: false
userPrometheusPort: [ 20110 ]
friendPrometheusPort: [ 20120 ]
@ -257,4 +371,4 @@ prometheus: #prometheus每个服务的端口数量需要和rpcPort保持对应
conversationPrometheusPort: [ 20230 ]
rtcPrometheusPort: [ 21300 ]
thirdPrometheusPort: [ 21301 ]
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] #端口数量需要和script/path_info.sh中的msg_transfer_service_num保持一致
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ]

@ -65,7 +65,7 @@ cmd/*
config/* @skiffer-git
# db directory
db/sdk @BanTanger @cubxxw @Gordon
db/sdk @cubxxw @FGadvancer
# internal directory
internal/ @openimsdk/openim @skiffer-git @FGadvancer

@ -0,0 +1,9 @@
## OpenIM Project Development Standards
- [Code Standards](https://chat.openai.com/go_code.md)
- [Directory Standards](https://chat.openai.com/directory.md)
- [Commit Standards](https://chat.openai.com/commit.md)
- [Versioning Standards](https://chat.openai.com/version.md)
- [Interface Standards](https://chat.openai.com/api.md)
- [Log Standards](https://chat.openai.com/log.md)
- [Error Code Standards](https://chat.openai.com/error_code.md)

@ -0,0 +1,5 @@
## Interface Standards
Our project, OpenIM, adheres to the [OpenAPI 3.0](https://spec.openapis.org/oas/latest.html) interface standards.
> Chinese translation: [OpenAPI Specification Chinese Translation](https://fishead.gitbook.io/openapi-specification-zhcn-translation/3.0.0.zhcn)

@ -0,0 +1,9 @@
## Commit Standards
Our project, OpenIM, follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0) standards.
> Chinese translation: [Conventional Commits: A Specification Making Commit Logs More Human and Machine-friendly](https://tool.lu/en_US/article/2ac/preview)
In addition to adhering to these standards, we encourage all contributors to the OpenIM project to ensure that their commit messages are clear and descriptive. This helps in maintaining a clean and meaningful project history. Each commit message should succinctly describe the changes made and, where necessary, the reasoning behind those changes.
To facilitate a streamlined process, we also recommend using appropriate commit type based on Conventional Commits guidelines such as `fix:` for bug fixes, `feat:` for new features, and so forth. Understanding and using these conventions helps in generating automatic release notes, making versioning easier, and improving overall readability of commit history.

@ -0,0 +1,3 @@
## Catalog Service Interface Specification
+ [https://github.com/kubecub/go-project-layout](https://github.com/kubecub/go-project-layout)

@ -0,0 +1,22 @@
## Error Code Standards
Error codes are one of the important means for users to locate and solve problems. When an application encounters an exception, users can quickly locate and resolve the problem based on the error code and the description and solution of the error code in the documentation.
### Error Code Naming Standards
- Follow CamelCase notation;
- Error codes are divided into two levels. For example, `InvalidParameter.BindError`, separated by a `.`. The first-level error code is platform-level, and the second-level error code is resource-level, which can be customized according to the scenario;
- The second-level error code can only use English letters or numbers ([a-zA-Z0-9]), and should use standard English word spelling, standard abbreviations, RFC term abbreviations, etc.;
- The error code should avoid multiple definitions of the same semantics, for example: `InvalidParameter.ErrorBind`, `InvalidParameter.BindError`.
### First-Level Common Error Codes
| Error Code | Error Description | Error Type |
| ---------------- | ------------------------------------------------------------ | ---------- |
| InternalError | Internal error | 1 |
| InvalidParameter | Parameter error (including errors in parameter type, format, value, etc.) | 0 |
| AuthFailure | Authentication / Authorization error | 0 |
| ResourceNotFound | Resource does not exist | 0 |
| FailedOperation | Operation failed | 2 |
> Error Type: 0 represents the client, 1 represents the server, 2 represents both the client / server.

@ -0,0 +1,901 @@
## Go 代码开发规范
在Go 项目开发中,一个好的编码规范可以极大的提高代码质量。为了帮你节省时间和精力,这里我整理了一份清晰、可直接套用的 Go 编码规范,供你参考。
这份规范,是我参考了 Go 官方提供的编码规范,以及 Go 社区沉淀的一些比较合理的规范之后加入自己的理解总结出的它比很多公司内部的规范更全面你掌握了以后在面试大厂的时候或者在大厂里写代码的时候都会让人高看你一眼觉得你code很专业。
这份编码规范中包含代码风格、命名规范、注释规范、类型、控制结构、函数、GOPATH 设置规范、依赖管理和最佳实践九类规范。如果你觉得这些规范内容太多了,看完一遍也记不住,这完全没关系。你可以多看几遍,也可以在用到时把它翻出来,在实际应用中掌握。这篇特别放送的内容,更多是作为写代码时候的一个参考手册。
## 1. 代码风格
### 1.1 代码格式
- 代码都必须用 `gofmt` 进行格式化。
- 运算符和操作数之间要留空格。
- 建议一行代码不超过120个字符超过部分请采用合适的换行方式换行。但也有些例外场景例如import行、工具自动生成的代码、带tag的struct字段。
- 文件长度不能超过800行。
- 函数长度不能超过80行。
- import规范
- 代码都必须用`goimports`进行格式化建议将代码Go代码编辑器设置为保存时运行 `goimports`)。
- 不要使用相对路径引入包,例如 `import ../util/net`
- 包名称与导入路径的最后一个目录名不匹配时,或者多个相同包名冲突时,则必须使用导入别名。
```go
// bad
"github.com/dgrijalva/jwt-go/v4"
//good
jwt "github.com/dgrijalva/jwt-go/v4"
```
- 导入的包建议进行分组,匿名包的引用使用一个新的分组,并对匿名包引用进行说明。
```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"
)
```
### 1.2 声明、初始化和定义
当函数中需要使用到多个变量时,可以在函数开始处使用`var`声明。在函数外部声明必须使用 `var` ,不要采用 `:=` ,容易踩到变量的作用域的问题。
```go
var (
Width int
Height int
)
```
- 在初始化结构引用时,请使用`&T{}`代替`new(T)`,以使其与结构体初始化一致。
```go
// bad
sptr := new(T)
sptr.Name = "bar"
// good
sptr := &T{Name: "bar"}
```
- struct 声明和初始化格式采用多行,定义如下。
```go
type User struct{
Username string
Email string
}
user := User{
Username: "belm",
Email: "nosbelm@qq.com",
}
```
- 相似的声明放在一组,同样适用于常量、变量和类型声明。
```go
// bad
import "a"
import "b"
// good
import (
"a"
"b"
)
```
- 尽可能指定容器容量,以便为容器预先分配内存,例如:
```go
v := make(map[int]string, 4)
v := make([]string, 0, 4)
```
- 在顶层使用标准var关键字。请勿指定类型除非它与表达式的类型不同。
```go
// bad
var _s string = F()
func F() string { return "A" }
// good
var _s = F()
// 由于 F 已经明确了返回一个字符串类型因此我们没有必要显式指定_s 的类型
// 还是那种类型
func F() string { return "A" }
```
- 对于未导出的顶层常量和变量,使用`_`作为前缀。
```go
// bad
const (
defaultHost = "127.0.0.1"
defaultPort = 8080
)
// good
const (
_defaultHost = "127.0.0.1"
_defaultPort = 8080
)
```
- 嵌入式类型(例如 mutex应位于结构体内的字段列表的顶部并且必须有一个空行将嵌入式字段与常规字段分隔开。
```go
// bad
type Client struct {
version int
http.Client
}
// good
type Client struct {
http.Client
version int
}
```
### 1.3 错误处理
- `error`作为函数的值返回,必须对`error`进行处理,或将返回值赋值给明确忽略。对于`defer xx.Close()`可以不用显式处理。
```go
func load() error {
// normal code
}
// bad
load()
// good
_ = load()
```
- `error`作为函数的值返回且有多个返回值的时候,`error`必须是最后一个参数。
```go
// bad
func load() (error, int) {
// normal code
}
// good
func load() (int, error) {
// normal code
}
```
- 尽早进行错误处理,并尽早返回,减少嵌套。
```go
// bad
if err != nil {
// error code
} else {
// normal code
}
// good
if err != nil {
// error handling
return err
}
// normal code
```
- 如果需要在 if 之外使用函数调用的结果,则应采用下面的方式。
```go
// bad
if v, err := foo(); err != nil {
// error handling
}
// good
v, err := foo()
if err != nil {
// error handling
}
```
- 错误要单独判断,不与其他逻辑组合判断。
```go
// bad
v, err := foo()
if err != nil || v == nil {
// error handling
return err
}
// good
v, err := foo()
if err != nil {
// error handling
return err
}
if v == nil {
// error handling
return errors.New("invalid value v")
}
```
- 如果返回值需要初始化,则采用下面的方式。
```go
v, err := f()
if err != nil {
// error handling
return // or continue.
}
```
- 错误描述建议
- 错误描述用小写字母开头,结尾不要加标点符号,例如:
```go
// bad
errors.New("Redis connection failed")
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)`
### 1.4 panic处理
- 在业务逻辑处理中禁止使用panic。
- 在main包中只有当程序完全不可运行时使用panic例如无法打开文件、无法连接数据库导致程序无法正常运行。
- 在main包中使用 `log.Fatal` 来记录错误这样就可以由log来结束程序或者将panic抛出的异常记录到日志文件中方便排查问题。
- 可导出的接口一定不能有panic。
- 包内建议采用error而不是panic来传递错误。
### 1.5 单元测试
- 单元测试文件名命名规范为 `example_test.go`
- 每个重要的可导出函数都要编写测试用例。
- 因为单元测试文件内的函数都是不对外的,所以可导出的结构体、函数等可以不带注释。
- 如果存在 `func (b *Bar) Foo` ,单测函数可以为 `func TestBar_Foo`
### 1.6 类型断言失败处理
- type assertion 的单个返回值针对不正确的类型将产生 panic。请始终使用 “comma ok”的惯用法。
```go
// bad
t := n.(int)
// good
t, ok := n.(int)
if !ok {
// error handling
}
```
## 2. 命名规范
命名规范是代码规范中非常重要的一部分一个统一的、短小的、精确的命名规范可以大大提高代码的可读性也可以借此规避一些不必要的Bug。
### 2.1 包命名
- 包名必须和目录名一致,尽量采取有意义、简短的包名,不要和标准库冲突。
- 包名全部小写,没有大写或下划线,使用多级目录来划分层级。
- 项目名可以通过中划线来连接多个单词。
- 包名以及包所在的目录名,不要使用复数,例如,是`net/url`,而不是`net/urls`。
- 不要用 common、util、shared 或者 lib 这类宽泛的、无意义的包名。
- 包名要简单明了,例如 net、time、log。
### 2.2 函数命名
- 函数名采用驼峰式,首字母根据访问控制决定使用大写或小写,例如:`MixedCaps`或者`mixedCaps`。
- 代码生成工具自动生成的代码(如`xxxx.pb.go`)和为了对相关测试用例进行分组,而采用的下划线(如`TestMyFunction_WhatIsBeingTested`)排除此规则。
### 2.3 文件命名
- 文件名要简短有意义。
- 文件名应小写,并使用下划线分割单词。
### 2.4 结构体命名
- 采用驼峰命名方式,首字母根据访问控制决定使用大写或小写,例如`MixedCaps`或者`mixedCaps`。
- 结构体名不应该是动词,应该是名词,比如 `Node`、`NodeSpec`。
- 避免使用Data、Info这类无意义的结构体名。
- 结构体的声明和初始化应采用多行,例如:
```go
// User 多行声明
type User struct {
Name string
Email string
}
// 多行初始化
u := User{
UserName: "belm",
Email: "nosbelm@qq.com",
}
```
### 2.5 接口命名
- 接口命名的规则,基本和结构体命名规则保持一致:
- 单个函数的接口名以 “er"”作为后缀例如ReaderWriter有时候可能导致蹩脚的英文但是没关系。
- 两个函数的接口名以两个函数名命名例如ReadWriter。
- 三个以上函数的接口名,类似于结构体名。
例如:
```
// 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)
}
// ReadWriter is the interface that groups the basic Read and Write methods.
type ReadWriter interface {
Reader
Writer
}
```
### 2.6 变量命名
- 变量名必须遵循驼峰式,首字母根据访问控制决定使用大写或小写。
- 在相对简单(对象数量少、针对性强)的环境中,可以将一些名称由完整单词简写为单个字母,例如:
- user 可以简写为 u
- userID 可以简写 uid。
- 特有名词时,需要遵循以下规则:
- 如果变量为私有,且特有名词为首个单词,则使用小写,如 apiClient。
- 其他情况都应当使用该名词原有的写法,如 APIClient、repoID、UserID。
下面列举了一些常见的特有名词。
```
// 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类型则名称应以HasIsCan或Allow开头例如
```go
var hasConflict bool
var isExist bool
var canManage bool
var allowGitHook bool
```
- 局部变量应当尽可能短小比如使用buf指代buffer使用i指代index。
- 代码生成工具自动生成的代码可排除此规则(如`xxx.pb.go`里面的Id)
### 2.7 常量命名
- 常量名必须遵循驼峰式,首字母根据访问控制决定使用大写或小写。
- 如果是枚举类型的常量,需要先创建相应类型:
```go
// Code defines an error code type.
type Code int
// Internal errors.
const (
// ErrUnknown - 0: An unknown error occurred.
ErrUnknown Code = iota
// ErrFatal - 1: An fatal error occurred.
ErrFatal
)
```
### 2.8 Error的命名
- Error类型应该写成FooError的形式。
```go
type ExitError struct {
// ....
}
```
- Error变量写成ErrFoo的形式。
```go
var ErrFormat = errors.New("unknown format")
```
## 3. 注释规范
- 每个可导出的名字都要有注释,该注释对导出的变量、函数、结构体、接口等进行简要介绍。
- 全部使用单行注释,禁止使用多行注释。
- 和代码的规范一样,单行注释不要过长,禁止超过 120 字符,超过的请使用换行展示,尽量保持格式优雅。
- 注释必须是完整的句子,以需要注释的内容作为开头,句点作为结尾,`格式为 // 名称 描述.`。例如:
```go
// bad
// logs the flags in the flagset.
func PrintFlags(flags *pflag.FlagSet) {
// normal code
}
// good
// PrintFlags logs the flags in the flagset.
func PrintFlags(flags *pflag.FlagSet) {
// normal code
}
```
- 所有注释掉的代码在提交code review前都应该被删除否则应该说明为什么不删除并给出后续处理建议。
- 在多段注释之间可以使用空行分隔加以区分,如下所示:
```go
// Package superman implements methods for saving the world.
//
// Experience has shown that a small number of procedures can prove
// helpful when attempting to save the world.
package superman
```
### 3.1 包注释
- 每个包都有且仅有一个包级别的注释。
- 包注释统一用 // 进行注释,格式为 `// Package 包名 包描述`,例如:
```go
// Package genericclioptions contains flags which can be added to you command, bound, completed, and produce
// useful helper functions.
package genericclioptions
```
### 3.2 变量/常量注释
- 每个可导出的变量/常量都必须有注释说明,`格式为// 变量名 变量描述`,例如:
```go
// ErrSigningMethod defines invalid signing method error.
var ErrSigningMethod = errors.New("Invalid signing method")
```
- 出现大块常量或变量定义时,可在前面注释一个总的说明,然后在每一行常量的前一行或末尾详细注释该常量的定义,例如:
```go
// Code must start with 1xxxxx.
const (
// ErrSuccess - 200: OK.
ErrSuccess int = iota + 100001
// ErrUnknown - 500: Internal server error.
ErrUnknown
// ErrBind - 400: Error occurred while binding the request body to the struct.
ErrBind
// ErrValidation - 400: Validation failed.
ErrValidation
)
```
### 3.3 结构体注释
- 每个需要导出的结构体或者接口都必须有注释说明,格式为 `// 结构体名 结构体描述.`
- 结构体内的可导出成员变量名,如果意义不明确,必须要给出注释,放在成员变量的前一行或同一行的末尾。例如:
```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"`
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 方法注释
每个需要导出的函数或者方法都必须有注释,格式为// 函数名 函数描述.,例如:
```go
// BeforeUpdate run before update database record.
func (p *Policy) BeforeUpdate() (err error) {
// normal code
return nil
}
```
### 3.5 类型注释
- 每个需要导出的类型定义和类型别名都必须有注释说明,格式为 `// 类型名 类型描述.`,例如:
```go
// Code defines an error code type.
type Code int
```
## 4. 类型
### 4.1 字符串
- 空字符串判断。
```go
// bad
if s == "" {
// normal code
}
// good
if len(s) == 0 {
// normal code
}
```
- `[]byte`/`string`相等比较。
```go
// bad
var s1 []byte
var s2 []byte
...
bytes.Equal(s1, s2) == 0
bytes.Equal(s1, s2) != 0
// good
var s1 []byte
var s2 []byte
...
bytes.Compare(s1, s2) == 0
bytes.Compare(s1, s2) != 0
```
- 复杂字符串使用raw字符串避免字符转义。
```go
// bad
regexp.MustCompile("\\.")
// good
regexp.MustCompile(`\.`)
```
### 4.2 切片
- 空slice判断。
```go
// bad
if len(slice) = 0 {
// normal code
}
// good
if slice != nil && len(slice) == 0 {
// normal code
}
```
上面判断同样适用于map、channel。
- 声明slice。
```go
// bad
s := []string{}
s := make([]string, 0)
// good
var s []string
```
- slice复制。
```go
// bad
var b1, b2 []byte
for i, v := range b1 {
b2[i] = v
}
for i := range b1 {
b2[i] = b1[i]
}
// good
copy(b2, b1)
```
- slice新增。
```go
// bad
var a, b []int
for _, v := range a {
b = append(b, v)
}
// good
var a, b []int
b = append(b, a...)
```
### 4.3 结构体
- struct初始化。
struct以多行格式初始化。
```go
type user struct {
Id int64
Name string
}
u1 := user{100, "Colin"}
u2 := user{
Id: 200,
Name: "Lex",
}
```
## 5. 控制结构
### 5.1 if
- if 接受初始化语句,约定如下方式建立局部变量。
```go
if err := loadConfig(); err != nil {
// error handling
return err
}
```
- if 对于bool类型的变量应直接进行真假判断。
```go
var isAllow bool
if isAllow {
// normal code
}
```
### 5.2 for
- 采用短声明建立局部变量。
```go
sum := 0
for i := 0; i < 10; i++ {
sum += 1
}
```
- 不要在 for 循环里面使用 deferdefer只有在函数退出时才会执行。
```go
// bad
for file := range files {
fd, err := os.Open(file)
if err != nil {
return err
}
defer fd.Close()
// normal code
}
// good
for file := range files {
func() {
fd, err := os.Open(file)
if err != nil {
return err
}
defer fd.Close()
// normal code
}()
}
```
### 5.3 range
- 如果只需要第一项key就丢弃第二个。
```go
for key := range keys {
// normal code
}
```
- 如果只需要第二项,则把第一项置为下划线。
```go
sum := 0
for _, value := range array {
sum += value
}
```
### 5.4 switch
- 必须要有default。
```go
switch os := runtime.GOOS; os {
case "linux":
fmt.Println("Linux.")
case "darwin":
fmt.Println("OS X.")
default:
fmt.Printf("%s.\n", os)
}
```
### 5.5 goto
- 业务代码禁止使用 goto 。
- 框架或其他底层源码尽量不用。
## 6. 函数
- 传入变量和返回变量以小写字母开头。
- 函数参数个数不能超过5个。
- 函数分组与顺序
- 函数应按粗略的调用顺序排序。
- 同一文件中的函数应按接收者分组。
- 尽量采用值传递,而非指针传递。
- 传入参数是 map、slice、chan、interface ,不要传递指针。
### 6.1 函数参数
- 如果函数返回相同类型的两个或三个参数,或者如果从上下文中不清楚结果的含义,使用命名返回,其他情况不建议使用命名返回,例如:
```go
func coordinate() (x, y float64, err error) {
// normal code
}
```
- 传入变量和返回变量都以小写字母开头。
- 尽量用值传递,非指针传递。
- 参数数量均不能超过5个。
- 多返回值最多返回三个,超过三个请使用 struct。
### 6.2 defer
- 当存在资源创建时应紧跟defer释放资源(可以大胆使用deferdefer在Go1.14版本中性能大幅提升defer的性能损耗即使在性能敏感型的业务中也可以忽略)。
- 先判断是否错误再defer释放资源例如
```go
rep, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
```
### 6.3 方法的接收器
- 推荐以类名第一个英文首字母的小写作为接收器的命名。
- 接收器的命名在函数超过20行的时候不要用单字符。
- 接收器的命名不能采用me、this、self这类易混淆名称。
### 6.4 嵌套
- 嵌套深度不能超过4层。
### 6.5 变量命名
- 变量声明尽量放在变量第一次使用的前面,遵循就近原则。
- 如果魔法数字出现超过两次,则禁止使用,改用一个常量代替,例如:
```go
// PI ...
const Prise = 3.14
func getAppleCost(n float64) float64 {
return Prise * n
}
func getOrangeCost(n float64) float64 {
return Prise * n
}
```
## 7. GOPATH 设置规范
- Go 1.11 之后,弱化了 GOPATH 规则已有代码很多库肯定是在1.11之前建立的)肯定符合这个规则,建议保留 GOPATH 规则,便于维护代码。
- 建议只使用一个 GOPATH不建议使用多个 GOPATH。如果使用多个GOPATH编译生效的 bin 目录是在第一个 GOPATH 下。
## 8. 依赖管理
- Go 1.11 以上必须使用 Go Modules。
- 使用Go Modules作为依赖管理的项目时不建议提交vendor目录。
- 使用Go Modules作为依赖管理的项目时必须提交go.sum文件。
### 9. 最佳实践
- 尽量少用全局变量,而是通过参数传递,使每个函数都是“无状态”的。这样可以减少耦合,也方便分工和单元测试。
- 在编译时验证接口的符合性,例如:
```go
type LogHandler struct {
h http.Handler
log *zap.Logger
}
var _ http.Handler = LogHandler{}
```
- 服务器处理请求时应该创建一个context保存该请求的相关信息如requestID并在函数调用链中传递。
### 9.1 性能
- string 表示的是不可变的字符串变量,对 string 的修改是比较重的操作,基本上都需要重新申请内存。所以,如果没有特殊需要,需要修改时多使用 []byte。
- 优先使用 strconv 而不是 fmt。
### 9.2 注意事项
- append 要小心自动分配内存append 返回的可能是新分配的地址。
- 如果要直接修改 map 的 value 值,则 value 只能是指针,否则要覆盖原来的值。
- map 在并发中需要加锁。
- 编译过程无法检查 interface{} 的转换,只能在运行时检查,小心引起 panic。
## 总结
这里向你介绍了九类常用的编码规范。但今天的最后,我要在这里提醒你一句:规范是人定的,你也可以根据需要,制定符合你项目的规范,但同时我也建议你采纳这些业界沉淀下来的规范,并通过工具来确保规范的执行。

@ -0,0 +1,20 @@
## Log Standards
### Log Standards
- The unified log package `github.com/OpenIMSDK/Open-IM-Server/internal/pkg/log` should be used for all logging;
- Use structured logging formats: `log.Infow`, `log.Warnw`, `log.Errorw`, etc. For example: `log.Infow("Update post function called")`;
- All logs should start with an uppercase letter and should not end with a `.`. For example: `log.Infow("Update post function called")`;
- Use past tense. For example, use `Could not delete B` instead of `Cannot delete B`;
- Adhere to log level standards:
- Debug level logs use `log.Debugw`;
- Info level logs use `log.Infow`;
- Warning level logs use `log.Warnw`;
- Error level logs use `log.Errorw`;
- Panic level logs use `log.Panicw`;
- Fatal level logs use `log.Fatalw`.
- Log settings:
- Development and test environments: The log level is set to `debug`, the log format can be set to `console` / `json` as needed, and caller is enabled;
- Production environment: The log level is set to `info`, the log format is set to `json`, and caller is enabled. (**Note**: In the early stages of going online, to facilitate troubleshooting, the log level can be set to `debug`)
- When logging, avoid outputting sensitive information, such as passwords, keys, etc.
- If you are calling a logging function in a function/method with a `context.Context` parameter, it is recommended to use `log.L(ctx).Infow()` for logging.

@ -0,0 +1,57 @@
# OpenIM Branch Management and Versioning
Our project, OpenIM, follows the [Semantic Versioning 2.0.0](https://semver.org/lang/zh-CN/) standards.
## OpenIM version
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.
In the OpenIM repository, the versioning adheres to the `MAJOR.MINOR.PATCH` format, where:
- `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.
## Milestones and Branching
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.
## Dealing with Major Bugs
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.
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.
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.
## Git Workflow Example
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
git checkout release-v3.1
# Create a new branch for the bug fix
git checkout -b bug/bug-name
# ... Make changes, commit your work ...
# Push the branch to your remote repository
git push origin bug/bug-name
# After the pull request is merged into the release-v3.1 branch,
# checkout and update your main branch
git checkout main
git pull origin main
# Merge or rebase the changes from release-v3.1 into main
git merge release-v3.1
# Push the updates to the main branch
git push origin main
```
Remember, communication with your team is key throughout this process, keeping everyone up-to-date with the changes being made.

@ -38,7 +38,7 @@ require github.com/google/uuid v1.3.0
require (
github.com/OpenIMSDK/protocol v0.0.1
github.com/OpenIMSDK/tools v0.0.4
github.com/OpenIMSDK/tools v0.0.5
github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0

@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OpenIMSDK/protocol v0.0.1 h1:Q6J1jCU00dfqmguxw2XI+IGcVfBAkb5Tz8LgvyeNkk0=
github.com/OpenIMSDK/protocol v0.0.1/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/tools v0.0.4 h1:aSC5FWO/0ccxuLHs+E1Eeyj+XWL/2CzLy1XGmQgpaU4=
github.com/OpenIMSDK/tools v0.0.4/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
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/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=

@ -0,0 +1,560 @@
#!/bin/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.
#
# https://gist.github.com/cubxxw/28f997f2c9aff408630b072f010c1d64
#
set -e
set -o pipefail
############### OpenIM Github ###############
# ... rest of the script ...
# TODO
# You can configure this script in three ways.
# 1. First, set the variables in this column with more comments.
# 2. The second is to pass an environment variable via a flag such as --help.
# 3. The third way is to set the variable externally, or pass it in as an environment variable
# Default configuration for OpenIM Repo
# The OpenIM Repo settings can be customized according to your needs.
# OpenIM Repo owner, by default it's set to "OpenIMSDK". If you're using a different owner, replace accordingly.
OWNER="OpenIMSDK"
# The repository name, by default it's "Open-IM-Server". If you're using a different repository, replace accordingly.
REPO="Open-IM-Server"
# Version of Go you want to use, make sure it is compatible with your OpenIM-Server requirements.
# Default is 1.18, if you want to use a different version, replace accordingly.
GO_VERSION="1.18"
# Default HTTP_PORT is 80. If you want to use a different port, uncomment and replace the value.
# HTTP_PORT=80
# CPU core number for concurrent execution. By default it's determined automatically.
# Uncomment the next line if you want to set it manually.
# CPU=$(grep -c ^processor /proc/cpuinfo)
# By default, the script uses the latest tag from OpenIM-Server releases.
# If you want to use a specific tag, uncomment and replace "v3.0.0" with the desired tag.
# LATEST_TAG=v3.0.0
# Default OpenIM install directory is /tmp. If you want to use a different directory, uncomment and replace "/test".
# DOWNLOAD_OPENIM_DIR="/test"
# GitHub proxy settings. If you are using a proxy, uncomment and replace the empty field with your proxy URL.
PROXY=
# If you have a GitHub token, replace the empty field with your token.
GITHUB_TOKEN=
# Default user is "root". If you need to modify it, uncomment and replace accordingly.
# USER=root
# Default password for redis, mysql, mongo, as well as accessSecret in config/config.yaml.
# Remember, it should be a combination of 8 or more numbers and letters. If you want to set a different password, uncomment and replace "openIM123".
# PASSWORD=openIM123
# Default endpoint for minio's external service IP and port. If you want to use a different endpoint, uncomment and replace.
# ENDPOINT=http://127.0.0.1:10005
# Default API_URL, replace if necessary.
# API_URL=http://127.0.0.1:10002/object/
# Default data directory. If you want to specify a different directory, uncomment and replace "./".
# DATA_DIR=./
############### OpenIM Functions ###############
# Install horizon of the script
#
# Pre-requisites:
# - git
# - make
# - jq
# - docker
# - docker-compose
# - go
#
# Check if the script is run as root
function check_isroot() {
if [ "$EUID" -ne 0 ]; then
fatal "Please run the script as root or use sudo."
fi
}
# check if the current directory is a OpenIM git repository
function check_git_repo() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# Inside a git repository
for remote in $(git remote); do
repo_url=$(git remote get-url $remote)
if [[ $repo_url == "https://github.com/OpenIMSDK/Open-IM-Server.git" || \
$repo_url == "https://github.com/OpenIMSDK/Open-IM-Server" || \
$repo_url == "git@github.com:OpenIMSDK/Open-IM-Server.git" ]]; then
# If it's OpenIMSDK repository
info "Current directory is OpenIMSDK git repository."
info "Executing installation directly."
install_openim
exit 0
fi
debug "Remote: $remote, URL: $repo_url"
done
# If it's not OpenIMSDK repository
debug "Current directory is not OpenIMSDK git repository."
fi
info "Current directory is not a git repository."
}
# Function to update and install necessary tools
function install_tools() {
info "Checking and installing necessary tools, about git, make, jq, docker, docker-compose."
local tools=("git" "make" "jq" "docker" "docker-compose")
local install_cmd update_cmd os
if grep -qEi "debian|buntu|mint" /etc/os-release; then
os="Ubuntu"
install_cmd="sudo apt install -y"
update_cmd="sudo apt update"
elif grep -qEi "fedora|rhel" /etc/os-release; then
os="CentOS"
install_cmd="sudo yum install -y"
update_cmd="sudo yum update"
else
fatal "Unsupported OS, please use Ubuntu or CentOS."
fi
debug "Detected OS: $os"
info "Updating system package repositories..."
$update_cmd
for tool in "${tools[@]}"; do
if ! command -v $tool &> /dev/null; then
warn "$tool is not installed. Installing now..."
$install_cmd $tool
success "$tool has been installed successfully."
else
info "$tool is already installed."
fi
done
}
# Function to check if Docker and Docker Compose are installed
function check_docker() {
if ! command -v docker &> /dev/null; then
fatal "Docker is not installed. Please install Docker first."
fi
if ! command -v docker-compose &> /dev/null; then
fatal "Docker Compose is not installed. Please install Docker Compose first."
fi
}
# Function to download and install Go if it's not already installed
function install_go() {
command -v go >/dev/null 2>&1
# Determines if GO_VERSION is defined
if [ -z "$GO_VERSION" ]; then
GO_VERSION="1.18"
fi
if [[ $? -ne 0 ]]; then
warn "Go is not installed. Installing now..."
curl -LO "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz"
if [ $? -ne 0 ]; then
fatal "Download failed! Please check your network connectivity."
fi
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
source ~/.bashrc
success "Go has been installed successfully."
else
info "Go is already installed."
fi
}
function download_source_code() {
# If LATEST_TAG was not defined outside the function, get it here example: v3.0.1-beta.1
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG=$(curl -s "https://api.github.com/repos/$OWNER/$REPO/tags" | jq -r '.[0].name')
fi
# If LATEST_TAG is still empty, set a default value
local DEFAULT_TAG="v3.0.0"
LATEST_TAG="${LATEST_TAG:-$DEFAULT_TAG}"
debug "DEFAULT_TAG: $DEFAULT_TAG"
info "Use OpenIM Version LATEST_TAG: $LATEST_TAG"
# If MODIFIED_TAG was not defined outside the function, modify it here,example: 3.0.1-beta.1
if [ -z "$MODIFIED_TAG" ]; then
MODIFIED_TAG=$(echo $LATEST_TAG | sed 's/v//')
fi
# If MODIFIED_TAG is still empty, set a default value
local DEFAULT_MODIFIED_TAG="${DEFAULT_TAG#v}"
MODIFIED_TAG="${MODIFIED_TAG:-$DEFAULT_MODIFIED_TAG}"
debug "MODIFIED_TAG: $MODIFIED_TAG"
# Construct the tarball URL
TARBALL_URL="${PROXY}https://github.com/$OWNER/$REPO/archive/refs/tags/$LATEST_TAG.tar.gz"
info "Downloaded OpenIM TARBALL_URL: $TARBALL_URL"
info "Starting the OpenIM automated one-click deployment script."
# Set the download and extract directory to /tmp
if [ -z "$DOWNLOAD_OPENIM_DIR" ]; then
DOWNLOAD_OPENIM_DIR="/tmp"
fi
# Check if /tmp directory exists
if [ ! -d "$DOWNLOAD_OPENIM_DIR" ]; then
warn "$DOWNLOAD_OPENIM_DIR does not exist. Creating it..."
mkdir -p "$DOWNLOAD_OPENIM_DIR"
fi
info "Downloading OpenIM source code from $TARBALL_URL to $DOWNLOAD_OPENIM_DIR"
curl -L -o "${DOWNLOAD_OPENIM_DIR}/${MODIFIED_TAG}.tar.gz" $TARBALL_URL
tar -xzvf "${DOWNLOAD_OPENIM_DIR}/${MODIFIED_TAG}.tar.gz" -C "$DOWNLOAD_OPENIM_DIR"
cd "$DOWNLOAD_OPENIM_DIR/$REPO-$MODIFIED_TAG"
git init && git add . && git commit -m "init" --no-verify
success "Source code downloaded and extracted to $REPO-$MODIFIED_TAG"
}
function set_openim_env() {
warn "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."
# Set default values for user input
# If the USER environment variable is not set, it defaults to 'root'
if [ -z "$USER" ]; then
USER="root"
debug "USER is not set. Defaulting to 'root'."
fi
# If the PASSWORD environment variable is not set, it defaults to 'openIM123'
# This password applies to redis, mysql, mongo, as well as accessSecret in config/config.yaml
if [ -z "$PASSWORD" ]; then
PASSWORD="openIM123"
debug "PASSWORD is not set. Defaulting to 'openIM123'."
fi
# If the ENDPOINT environment variable is not set, it defaults to 'http://127.0.0.1:10005'
# This is minio's external service IP and port, or it could be a domain like storage.xx.xx
# The app must be able to access this IP and port or domain
if [ -z "$ENDPOINT" ]; then
ENDPOINT="http://127.0.0.1:10005"
debug "ENDPOINT is not set. Defaulting to 'http://127.0.0.1:10005'."
fi
# If the API_URL environment variable is not set, it defaults to 'http://127.0.0.1:10002/object/'
# The app must be able to access this IP and port or domain
if [ -z "$API_URL" ]; then
API_URL="http://127.0.0.1:10002/object/"
debug "API_URL is not set. Defaulting to 'http://127.0.0.1:10002/object/'."
fi
# If the DATA_DIR environment variable is not set, it defaults to the current directory './'
# This can be set to a directory with large disk space
if [ -z "$DATA_DIR" ]; then
DATA_DIR="./"
debug "DATA_DIR is not set. Defaulting to './'."
fi
}
function install_openim() {
info "Installing OpenIM"
make -j${CPU} install V=1
info "Checking installation"
make check
success "OpenIM installation completed successfully. Happy chatting!"
}
############### OpenIM Help ###############
# Function to display help message
function cmd_help() {
openim_color
color_echo ${BRIGHT_GREEN_PREFIX} "Usage: $0 [options]"
color_echo ${BRIGHT_GREEN_PREFIX} "Options:"
echo
color_echo ${BLUE_PREFIX} "-i, --install ${CYAN_PREFIX}Execute the installation logic of the script${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-u, --user ${CYAN_PREFIX}set user (default: root)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-p, --password ${CYAN_PREFIX}set password (default: openIM123)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-e, --endpoint ${CYAN_PREFIX}set endpoint (default: http://127.0.0.1:10005)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-a, --api ${CYAN_PREFIX}set API URL (default: http://127.0.0.1:10002/object/)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-d, --directory ${CYAN_PREFIX}set directory for large disk space (default: ./)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-h, --help ${CYAN_PREFIX}display this help message and exit${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-cn, --china ${CYAN_PREFIX}set to use the Chinese domestic proxy${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-t, --tag ${CYAN_PREFIX}specify the tag (default option, set to latest if not specified)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-r, --release ${CYAN_PREFIX}specify the release branch (cannot be used with the tag option)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-gt, --github-token ${CYAN_PREFIX}set the GITHUB_TOKEN (default: not set)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "-g, --go-version ${CYAN_PREFIX}set the Go language version (default: GO_VERSION=\"1.18\")${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "--install-dir ${CYAN_PREFIX}set the OpenIM installation directory (default: /tmp)${COLOR_SUFFIX}"
color_echo ${BLUE_PREFIX} "--cpu ${CYAN_PREFIX}set the number of concurrent processes${COLOR_SUFFIX}"
echo
color_echo ${RED_PREFIX} "Note: Only one of the -t/--tag or -r/--release options can be used at a time.${COLOR_SUFFIX}"
color_echo ${RED_PREFIX} "If both are used or none of them are used, the -t/--tag option will be prioritized.${COLOR_SUFFIX}"
echo
exit 1
}
function parseinput() {
# set default values
# USER=root
# PASSWORD=openIM123
# ENDPOINT=http://127.0.0.1:10005
# API=http://127.0.0.1:10002/object/
# DIRECTORY=./
# CHINA=false
# TAG=latest
# RELEASE=""
# GO_VERSION=1.18
# INSTALL_DIR=/tmp
# GITHUB_TOKEN=""
# CPU=$(nproc)
if [ $# -eq 0 ]; then
cmd_help
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
cmd_help
exit
;;
-u|--user)
shift
USER=$1
;;
-p|--password)
shift
PASSWORD=$1
;;
-e|--endpoint)
shift
ENDPOINT=$1
;;
-a|--api)
shift
API=$1
;;
-d|--directory)
shift
DIRECTORY=$1
;;
-cn|--china)
CHINA=true
;;
-t|--tag)
shift
TAG=$1
;;
-r|--release)
shift
RELEASE=$1
;;
-g|--go-version)
shift
GO_VERSION=$1
;;
--install-dir)
shift
INSTALL_DIR=$1
;;
-gt|--github-token)
shift
GITHUB_TOKEN=$1
;;
--cpu)
shift
CPU=$1
;;
-i|--install)
openim_main
exit
;;
*)
echo "Unknown option: $1"
cmd_help
exit 1
;;
esac
shift
done
}
############### OpenIM LOGO ###############
# Set text color to cyan for header and URL
print_with_delay() {
text="$1"
delay="$2"
for i in $(seq 0 $((${#text}-1))); do
printf "${text:$i:1}"
sleep $delay
done
printf "\n"
}
print_progress() {
total="$1"
delay="$2"
printf "["
for i in $(seq 1 $total); do
printf "#"
sleep $delay
done
printf "]\n"
}
# Function for colored echo
color_echo() {
COLOR=$1
shift
echo -e "${COLOR} $* ${COLOR_SUFFIX}"
}
# Color definitions
function openim_color() {
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=> " "$@"
}
function openim_logo() {
# Set text color to cyan for header and URL
echo -e "\033[0;36m"
# Display fancy ASCII Art logo
# look http://patorjk.com/software/taag/#p=display&h=1&v=1&f=Doh&t=OpenIM
print_with_delay '
OOOOOOOOO IIIIIIIIIIMMMMMMMM MMMMMMMM
OO:::::::::OO I::::::::IM:::::::M M:::::::M
OO:::::::::::::OO I::::::::IM::::::::M M::::::::M
O:::::::OOO:::::::O II::::::IIM:::::::::M M:::::::::M
O::::::O O::::::Oppppp ppppppppp eeeeeeeeeeee nnnn nnnnnnnn I::::I M::::::::::M M::::::::::M
O:::::O O:::::Op::::ppp:::::::::p ee::::::::::::ee n:::nn::::::::nn I::::I M:::::::::::M M:::::::::::M
O:::::O O:::::Op:::::::::::::::::p e::::::eeeee:::::een::::::::::::::nn I::::I M:::::::M::::M M::::M:::::::M
O:::::O O:::::Opp::::::ppppp::::::pe::::::e e:::::enn:::::::::::::::n I::::I M::::::M M::::M M::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe:::::::eeeee::::::e n:::::nnnn:::::n I::::I M::::::M M::::M::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe:::::::::::::::::e n::::n n::::n I::::I M::::::M M:::::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe::::::eeeeeeeeeee n::::n n::::n I::::I M::::::M M:::::M M::::::M
O::::::O O::::::O p:::::p p::::::pe:::::::e n::::n n::::n I::::I M::::::M MMMMM M::::::M
O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII::::::IIM::::::M M::::::M
OO:::::::::::::OO p::::::::::::::::p e::::::::eeeeeeee n::::n n::::nI::::::::IM::::::M M::::::M
OO:::::::::OO p::::::::::::::pp ee:::::::::::::e n::::n n::::nI::::::::IM::::::M M::::::M
OOOOOOOOO p::::::pppppppp eeeeeeeeeeeeee nnnnnn nnnnnnIIIIIIIIIIMMMMMMMM MMMMMMMM
p:::::p
p:::::p
p:::::::p
p:::::::p
p:::::::p
ppppppppp
' 0.0001
# Display product URL
print_with_delay "Discover more and contribute at: https://github.com/OpenIMSDK/Open-IM-Server" 0.01
# Reset text color back to normal
echo -e "\033[0m"
# Set text color to green for product description
echo -e "\033[1;32m"
print_with_delay "Open-IM-Server: Reinventing Instant Messaging" 0.01
print_progress 50 0.02
print_with_delay "Open-IM-Server is not just a product; it's a revolution. It's about bringing the power of seamless, real-time messaging to your fingertips. And it's about joining a global community of developers, dedicated to pushing the boundaries of what's possible." 0.01
print_progress 50 0.02
# Reset text color back to normal
echo -e "\033[0m"
# Set text color to yellow for the Slack link
echo -e "\033[1;33m"
print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg" 0.01
# Reset text color back to normal
echo -e "\033[0m"
}
# Main function to run the script
function openim_main() {
check_git_repo
check_isroot
openim_color
install_tools
check_docker
install_go
download_source_code
set_openim_env
install_openim
openim_logo
}
parseinput "$@"

@ -44,6 +44,10 @@ func (o *FriendApi) GetFriendApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.Client, c)
}
func (o *FriendApi) GetDesignatedFriendsApply(c *gin.Context) {
a2r.Call(friend.FriendClient.GetDesignatedFriendsApply, o.Client, c)
}
func (o *FriendApi) GetSelfApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.Client, c)
}
@ -52,6 +56,10 @@ func (o *FriendApi) GetFriendList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriends, o.Client, c)
}
func (o *FriendApi) GetDesignatedFriends(c *gin.Context) {
a2r.Call(friend.FriendClient.GetDesignatedFriends, o.Client, c)
}
func (o *FriendApi) SetFriendRemark(c *gin.Context) {
a2r.Call(friend.FriendClient.SetFriendRemark, o.Client, c)
}

@ -60,6 +60,10 @@ func (o *GroupApi) GetUserReqGroupApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetUserReqApplicationList, o.Client, c)
}
func (o *GroupApi) GetGroupUsersReqApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupUsersReqApplicationList, o.Client, c)
}
func (o *GroupApi) GetGroupsInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupsInfo, o.Client, c)
}

@ -86,8 +86,10 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
f := NewFriendApi(*friendRpc)
friendRouterGroup.POST("/delete_friend", f.DeleteFriend)
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList)
friendRouterGroup.POST("/get_designated_friend_apply", f.GetDesignatedFriendsApply)
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList)
friendRouterGroup.POST("/get_friend_list", f.GetFriendList)
friendRouterGroup.POST("/get_designated_friends", f.GetDesignatedFriends)
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend)
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply)
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark)
@ -108,6 +110,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner)
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList)
groupRouterGroup.POST("/get_user_req_group_applicationList", g.GetUserReqGroupApplicationList)
groupRouterGroup.POST("/get_group_users_req_application_list", g.GetGroupUsersReqApplicationList)
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo)
groupRouterGroup.POST("/kick_group", g.KickGroupMember)
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo)

@ -107,7 +107,7 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
if err != nil {
return nil, err
}
_ = c.conversationNotificationSender.ConversationChangeNotification(ctx, req.Conversation.OwnerUserID)
_ = c.conversationNotificationSender.ConversationChangeNotification(ctx, req.Conversation.OwnerUserID, []string{req.Conversation.ConversationID})
resp := &pbConversation.SetConversationResp{}
return resp, nil
}
@ -170,7 +170,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
return nil, err
}
for _, userID := range req.UserIDs {
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value)
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value, req.Conversation.ConversationID)
}
}
if req.Conversation.BurnDuration != nil {
@ -181,7 +181,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
return nil, err
}
for _, v := range req.UserIDs {
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
}
return &pbConversation.SetConversationsResp{}, nil
}

@ -83,11 +83,6 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
return nil
}
func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context, req *pbfriend.GetDesignatedFriendsApplyReq) (*pbfriend.GetDesignatedFriendsApplyResp, error) {
//TODO implement me
panic("implement me")
}
// ok.
func (s *friendServer) ApplyToAddFriend(
ctx context.Context,
@ -245,6 +240,19 @@ func (s *friendServer) GetDesignatedFriends(
return resp, nil
}
func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context, req *pbfriend.GetDesignatedFriendsApplyReq) (resp *pbfriend.GetDesignatedFriendsApplyResp, err error) {
friendRequests, err := s.friendDatabase.FindBothFriendRequests(ctx, req.FromUserID, req.ToUserID)
if err != nil {
return nil, err
}
resp = &pbfriend.GetDesignatedFriendsApplyResp{}
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
if err != nil {
return nil, err
}
return resp, nil
}
// ok 获取接收到的好友申请(即别人主动申请的).
func (s *friendServer) GetPaginationFriendsApplyTo(
ctx context.Context,
@ -303,7 +311,6 @@ func (s *friendServer) IsFriend(
return resp, nil
}
// ok.
func (s *friendServer) GetPaginationFriends(
ctx context.Context,
req *pbfriend.GetPaginationFriendsReq,

@ -95,11 +95,6 @@ type groupServer struct {
msgRpcClient rpcclient.MessageRpcClient
}
func (s *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req *pbGroup.GetGroupUsersReqApplicationListReq) (*pbGroup.GetGroupUsersReqApplicationListResp, error) {
//TODO implement me
panic("implement me")
}
func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error {
if !authverify.IsAppManagerUid(ctx) {
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, groupID, mcontext.GetOpUserID(ctx))
@ -1445,3 +1440,46 @@ func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbGroup.
})
return resp, nil
}
func (s *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req *pbGroup.GetGroupUsersReqApplicationListReq) (*pbGroup.GetGroupUsersReqApplicationListResp, error) {
resp := &pbGroup.GetGroupUsersReqApplicationListResp{}
total, requests, err := s.GroupDatabase.FindGroupRequests(ctx, req.GroupID, req.UserIDs)
if err != nil {
return nil, err
}
if len(requests) == 0 {
return resp, nil
}
groupIDs := utils.Distinct(utils.Slice(requests, func(e *relationTb.GroupRequestModel) string {
return e.GroupID
}))
groups, err := s.GroupDatabase.FindGroup(ctx, groupIDs)
if err != nil {
return nil, err
}
groupMap := utils.SliceToMap(groups, func(e *relationTb.GroupModel) string {
return e.GroupID
})
if ids := utils.Single(groupIDs, utils.Keys(groupMap)); len(ids) > 0 {
return nil, errs.ErrGroupIDNotFound.Wrap(strings.Join(ids, ","))
}
owners, err := s.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
ownerMap := utils.SliceToMap(owners, func(e *relationTb.GroupMemberModel) string {
return e.GroupID
})
if ids := utils.Single(groupIDs, utils.Keys(ownerMap)); len(ids) > 0 {
return nil, errs.ErrData.Wrap("group no owner", strings.Join(ids, ","))
}
groupMemberNum, err := s.GroupDatabase.MapGroupMemberNum(ctx, groupIDs)
if err != nil {
return nil, err
}
resp.GroupRequests = utils.Slice(requests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest {
return convert.Db2PbGroupRequest(e, nil, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID])))
})
resp.Total = total
return resp, nil
}

@ -21,6 +21,8 @@ import (
"strings"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
@ -246,3 +248,7 @@ func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDR
}
return &pbuser.GetAllUserIDResp{UserIDs: userIDs}, nil
}
func (s *userServer) SubscribeOrCancelUsersStatus(ctx context.Context, req *pbuser.SubscribeOrCancelUsersStatusReq) (resp *pbuser.SubscribeOrCancelUsersStatusResp, err error) {
panic("implement me")
}

@ -33,7 +33,7 @@ type SendMsg struct {
}
type SendMsgReq struct {
RecvID string `json:"recvID" binding:"required_if" message:"recvID is required if sessionType is SingleChatType or NotificationChatType"`
RecvID string `json:"recvID" binding:"required_if" message:"recvID is required if sessionType is SingleChatType or NotificationChatType"`
SendMsg
}

@ -24,6 +24,7 @@ import (
"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"
@ -75,6 +76,7 @@ type FriendDatabase interface {
friendUserIDs []string,
) (friends []*relation.FriendModel, err error)
FindFriendUserIDs(ctx context.Context, ownerUserID string) (friendUserIDs []string, err error)
FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error)
}
type friendDatabase struct {
@ -221,6 +223,7 @@ func (f *friendDatabase) AgreeFriendRequest(
friendRequest *relation.FriendRequestModel,
) (err error) {
return f.tx.Transaction(func(tx any) error {
defer log.ZDebug(ctx, "return line")
now := time.Now()
fr, err := f.friendRequest.NewTx(tx).Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
if err != nil {
@ -246,7 +249,7 @@ func (f *friendDatabase) AgreeFriendRequest(
if err != nil {
return err
}
} else if errs.Unwrap(err) != gorm.ErrRecordNotFound {
} else if err != nil && errs.Unwrap(err) != gorm.ErrRecordNotFound {
return err
}
@ -363,3 +366,7 @@ func (f *friendDatabase) FindFriendUserIDs(
) (friendUserIDs []string, err error) {
return f.cache.GetFriendIDs(ctx, ownerUserID)
}
func (f *friendDatabase) FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error) {
return f.friendRequest.FindBothFriendRequests(ctx, fromUserID, toUserID)
}

@ -110,6 +110,7 @@ type GroupDatabase interface {
// GroupRequest
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationTb.GroupRequestModel, error)
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationTb.GroupRequestModel, error)
PageGroupRequestUser(
ctx context.Context,
userID string,
@ -576,3 +577,7 @@ func (g *groupDatabase) CountTotal(ctx context.Context, before *time.Time) (coun
func (g *groupDatabase) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
return g.groupDB.CountRangeEverydayTotal(ctx, start, end)
}
func (g *groupDatabase) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationTb.GroupRequestModel, error) {
return g.groupRequestDB.FindGroupRequests(ctx, groupID, userIDs)
}

@ -147,3 +147,14 @@ func (f *FriendRequestGorm) FindFromUserID(
)
return
}
func (f *FriendRequestGorm) FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error) {
err = utils.Wrap(
f.db(ctx).
Where("(from_user_id = ? AND to_user_id = ?) OR (from_user_id = ? AND to_user_id = ?)", fromUserID, toUserID, toUserID, fromUserID).
Find(&friends).
Error,
"",
)
return
}

@ -110,3 +110,8 @@ func (g *GroupRequestGorm) PageGroup(
showNumber,
)
}
func (g *GroupRequestGorm) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (total int64, groupRequests []*relation.GroupRequestModel, err error) {
err = g.DB.WithContext(ctx).Where("group_id = ? and user_id in ?", groupID, userIDs).Find(&groupRequests).Error
return int64(len(groupRequests)), groupRequests, utils.Wrap(err, utils.GetSelfFuncName())
}

@ -61,6 +61,6 @@ type FriendRequestModelInterface interface {
fromUserID string,
pageNumber, showNumber int32,
) (friendRequests []*FriendRequestModel, total int64, err error)
FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*FriendRequestModel, err error)
NewTx(tx any) FriendRequestModelInterface
}

@ -47,6 +47,7 @@ type GroupRequestModelInterface interface {
Delete(ctx context.Context, groupID string, userID string) (err error)
UpdateHandler(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32) (err error)
Take(ctx context.Context, groupID string, userID string) (groupRequest *GroupRequestModel, err error)
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*GroupRequestModel, error)
Page(
ctx context.Context,
userID string,

@ -31,23 +31,22 @@ func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient)
}
// SetPrivate调用.
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(
ctx context.Context,
sendID, recvID string,
isPrivateChat bool,
) error {
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string,
isPrivateChat bool, conversationID string) error {
tips := &sdkws.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
ConversationID: conversationID,
}
return c.Notification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
}
// 会话改变.
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) error {
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string, conversationIDs []string) error {
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
UserID: userID,
ConversationIDList: conversationIDs,
}
return c.Notification(ctx, userID, userID, constant.ConversationChangeNotification, tips)
}

@ -1,4 +1,72 @@
# `/scripts`
# OpenIM Scripts Directory Structure
This document outlines the directory structure for scripts in the OpenIM Server project. These scripts play a critical role in various areas like building, deploying, running and managing the services of OpenIM.
```bash
scripts/
├── LICENSE # License related files
│ ├── LICENSE # The license file
│ └── LICENSE_TEMPLATES # Template for license file
├── README.md # Readme file for scripts directory
├── advertise.sh # Script for advertisement services
├── batch_start_all.sh # Script to start all services in batch
├── build.cmd # Windows build command script
├── build_all_service.sh # Script to build all services
├── build_push_k8s_images.sh # Script to build and push images for Kubernetes
├── check_all.sh # Script to check status of all services
├── common.sh # Contains common functions used by other scripts
├── coverage.awk # AWK script for coverage report generation
├── coverage.sh # Script for generating coverage reports
├── docker_check_service.sh # Docker specific service check script
├── docker_start_all.sh # Script to start all services in a docker environment
├── ensure_tag.sh # Script to ensure proper tagging of docker images
├── enterprise # Scripts specific to enterprise version
│ ├── check_all.sh # Check status of all enterprise services
│ ├── function.sh # Functions specific to enterprise version
│ └── path_info.cfg # Path information configuration for enterprise version
├── env_check.sh # Script to check the environment
├── function.sh # Contains functions used by other scripts
├── githooks # Git hook scripts
│ ├── commit-msg # Script to validate commit message
│ ├── pre-commit # Script to run before each commit
│ └── pre-push # Script to run before each push
├── init_pwd.sh # Script to initialize password
├── install_im_compose.sh # Script to install IM with Docker Compose
├── install_im_server.sh # Script to install IM server
├── lib # Library scripts
│ ├── color.sh # Script for console color manipulation
│ ├── golang.sh # Script for golang related utility functions
│ ├── init.sh # Script for initialization tasks
│ ├── logging.sh # Script for logging related utility functions
│ ├── release.sh # Script for release related utility functions
│ ├── util.sh # Script for generic utility functions
│ └── version.sh # Script for versioning related tasks
├── make-rules # Makefile rules
│ ├── common.mk # Common Make rules
│ ├── copyright.mk # Copyright related Make rules
│ ├── dependencies.mk # Dependencies related Make rules
│ ├── gen.mk # Make rules for code generation
│ ├── golang.mk # Golang specific Make rules
│ ├── image.mk # Make rules for image building
│ ├── release.mk # Make rules for release process
│ ├── swagger.mk # Make rules for swagger documentation
│ └── tools.mk # Make rules for tools and utilities
├── mongo-init.sh # Script to initialize MongoDB
├── msg_gateway_start.sh # Script to start message gateway service
├── msg_transfer_start.sh # Script to start message transfer service
├── path_info.sh # Script containing path information
├── push_start.sh # Script to start push service
├── release.sh # Script to perform release process
├── start_all.sh # Script to start all services
├── start_cron.sh # Script to start cron jobs
├── start_rpc_service.sh # Script to start RPC service
├── stop_all.sh # Script to stop all services
└── style_info.sh # Script containing style related information
```
The purpose of having a structured scripts directory like this is to make the operations of OpenIM Server clear and easy to manage. Each script has its own responsibility, making it easier to maintain and update. It's also helpful for newcomers who can easily understand what each part of the system is doing by just looking at this directory structure.
Each directory and script in the structure should be understood as a part of a larger whole. All scripts work together to ensure the smooth operation and maintenance of the OpenIM Server.
## Supported platforms

@ -0,0 +1,122 @@
#!/bin/bash
set -e
set -o pipefail
trap 'echo "Script interrupted."; exit 1' INT
# Function for colored echo
function color_echo() {
COLOR=$1
shift
echo -e "${COLOR}===> $* ${COLOR_SUFFIX}"
}
# Color definitions
function openim_color() {
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
CYAN_PREFIX="\033[0;36m" # Cyan prefix
}
function print_with_delay() {
text="$1"
delay="$2"
color="$3"
for i in $(seq 0 $((${#text}-1))); do
printf "${color}${text:$i:1}${COLOR_SUFFIX}"
sleep $delay
done
printf "\n"
}
function print_progress() {
total="$1"
delay="$2"
color="$3"
printf "${color}["
for i in $(seq 1 $total); do
printf "#"
sleep $delay
done
printf "]${COLOR_SUFFIX}\n"
}
function openim_logo() {
# Set text color to cyan for header and URL
echo -e "\033[0;36m"
# Display fancy ASCII Art logo
# look http://patorjk.com/software/taag/#p=display&h=1&v=1&f=Doh&t=OpenIM
print_with_delay '
OOOOOOOOO IIIIIIIIIIMMMMMMMM MMMMMMMM
OO:::::::::OO I::::::::IM:::::::M M:::::::M
OO:::::::::::::OO I::::::::IM::::::::M M::::::::M
O:::::::OOO:::::::O II::::::IIM:::::::::M M:::::::::M
O::::::O O::::::Oppppp ppppppppp eeeeeeeeeeee nnnn nnnnnnnn I::::I M::::::::::M M::::::::::M
O:::::O O:::::Op::::ppp:::::::::p ee::::::::::::ee n:::nn::::::::nn I::::I M:::::::::::M M:::::::::::M
O:::::O O:::::Op:::::::::::::::::p e::::::eeeee:::::een::::::::::::::nn I::::I M:::::::M::::M M::::M:::::::M
O:::::O O:::::Opp::::::ppppp::::::pe::::::e e:::::enn:::::::::::::::n I::::I M::::::M M::::M M::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe:::::::eeeee::::::e n:::::nnnn:::::n I::::I M::::::M M::::M::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe:::::::::::::::::e n::::n n::::n I::::I M::::::M M:::::::M M::::::M
O:::::O O:::::O p:::::p p:::::pe::::::eeeeeeeeeee n::::n n::::n I::::I M::::::M M:::::M M::::::M
O::::::O O::::::O p:::::p p::::::pe:::::::e n::::n n::::n I::::I M::::::M MMMMM M::::::M
O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII::::::IIM::::::M M::::::M
OO:::::::::::::OO p::::::::::::::::p e::::::::eeeeeeee n::::n n::::nI::::::::IM::::::M M::::::M
OO:::::::::OO p::::::::::::::pp ee:::::::::::::e n::::n n::::nI::::::::IM::::::M M::::::M
OOOOOOOOO p::::::pppppppp eeeeeeeeeeeeee nnnnnn nnnnnnIIIIIIIIIIMMMMMMMM MMMMMMMM
p:::::p
p:::::p
p:::::::p
p:::::::p
p:::::::p
ppppppppp
' 0.0001
# Display product URL
print_with_delay "Discover more and contribute at: https://github.com/OpenIMSDK/Open-IM-Server" 0.01
# Reset text color back to normal
echo -e "\033[0m"
# Set text color to green for product description
echo -e "\033[1;32m"
print_with_delay "Open-IM-Server: Reinventing Instant Messaging" 0.01
print_progress 50 0.02
print_with_delay "Open-IM-Server is not just a product; it's a revolution. It's about bringing the power of seamless, real-time messaging to your fingertips. And it's about joining a global community of developers, dedicated to pushing the boundaries of what's possible." 0.01
print_progress 50 0.02
# Reset text color back to normal
echo -e "\033[0m"
# Set text color to yellow for the Slack link
echo -e "\033[1;33m"
print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg" 0.01
# Reset text color back to normal
echo -e "\033[0m"
}
function main() {
openim_logo
}
main "$@"

@ -60,6 +60,7 @@ endif
ifeq ($(origin VERSION), undefined)
# VERSION := $(shell git describe --abbrev=0 --dirty --always --tags | sed 's/-/./g') #v2.3.3.dirty
# git describe --tags --always --match="v*" --dirty
VERSION := $(shell git describe --tags --always --match="v*" --dirty | sed 's/-/./g') #v2.3.3.631.g00abdc9b.dirty
# v2.3.3: git tag
endif
@ -110,13 +111,16 @@ else
IMAGE_PLAT := $(PLATFORM)
endif
# Protobuf file storage path
APIROOT=$(ROOT_DIR)/pkg/proto
# Linux command settings
# TODO: Whether you need to join utils?
FIND := find . ! -path './utils/*' ! -path './vendor/*'
XARGS := xargs -r
FIND := find . ! -path './utils/*' ! -path './vendor/*' ! -path './third_party/*'
XARGS := xargs -r --no-run-if-empty
# Linux command settings-CODE DIRS Copyright
CODE_DIRS := $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd $(ROOT_DIR)/config $(ROOT_DIR)/db $(ROOT_DIR)/.docker-compose_cfg $(ROOT_DIR)/internal $(ROOT_DIR)/scripts $(ROOT_DIR)/test
CODE_DIRS := $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd $(ROOT_DIR)/config $(ROOT_DIR)/db $(ROOT_DIR)/.docker-compose_cfg $(ROOT_DIR)/internal $(ROOT_DIR)/scripts $(ROOT_DIR)/test $(ROOT_DIR)/.github $(ROOT_DIR)/build $(ROOT_DIR)/build $(ROOT_DIR)/deployments
FINDS := find $(CODE_DIRS)
# Makefile settings: Select different behaviors by determining whether V option is set

@ -51,6 +51,12 @@ copyright.add: tools.verify.addlicense
# -y string
# copyright year(s) (default "2023")
## copyright.advertise: Advertise the license of the project
.PHONY: copyright.advertise
copyright.advertise:
@chmod +x $(ROOT_DIR)/scripts/advertise.sh
@$(ROOT_DIR)/scripts/advertise.sh
## copyright.help: Show copyright help
.PHONY: copyright.help
copyright.help: scripts/make-rules/copyright.mk

@ -137,6 +137,12 @@ go.install:
@echo "===========> Installing deployment openim"
@$(ROOT_DIR)/scripts/install_im_server.sh
## go.check: Check OpenIM deployment
.PHONY: go.check
go.check:
@echo "===========> Checking OpenIM deployment"
@$(ROOT_DIR)/scripts/check_all.sh
## go.multiarch: Build multi-arch binaries
.PHONY: go.build.multiarch
go.build.multiarch: go.build.verify $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))
@ -173,9 +179,9 @@ go.test.cover: go.test.junit-report
.PHONY: go.format
go.format: tools.verify.golines tools.verify.goimports
@echo "===========> Formating codes"
@$(FIND) -type f -name '*.go' | $(XARGS) gofmt -s -w
@$(FIND) -type f -name '*.go' | $(XARGS) $(TOOLS_DIR)/goimports -w -local $(ROOT_PACKAGE)
@$(FIND) -type f -name '*.go' | $(XARGS) $(TOOLS_DIR)/golines -w --max-len=200 --reformat-tags --shorten-comments --ignore-generated .
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) gofmt -s -w
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) $(TOOLS_DIR)/goimports -w -local $(ROOT_PACKAGE)
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) $(TOOLS_DIR)/golines -w --max-len=200 --reformat-tags --shorten-comments --ignore-generated .
@$(GO) mod edit -fmt
## imports: task to automatically handle import packages in Go files using goimports tool

@ -28,6 +28,8 @@ 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

Loading…
Cancel
Save