From 98e7c77d282c76a80e332053adf226b2064dc1fc Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw)" <3293172751nss@gmail.com> Date: Tue, 7 Nov 2023 14:23:41 +0800 Subject: [PATCH] fix: Fixed some unused scripts and some names Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --- .env | 4 +- .github/workflows/api-test.yml | 14 +++ .github/workflows/create_branch_on_tag.yml | 14 +++ CHANGELOG/CHANGELOG.md | 2 +- CONTRIBUTING.md | 8 +- Makefile | 2 +- README-zh_CN.md | 14 +-- README.md | 59 +++++------ build/images/Dockerfile | 14 +++ config/config.yaml | 6 +- deployments/README.md | 2 +- .../templates/deployment.yaml | 14 +++ docker-compose.yml | 4 +- docs/README.md | 52 ++++----- docs/{conversions => contrib}/README.md | 4 +- docs/{conversions => contrib}/api.md | 0 docs/{conversions => contrib}/bash_log.md | 0 docs/{conversions => contrib}/cicd_actions.md | 0 ...ode_conventions.md => code-conventions.md} | 0 docs/{conversions => contrib}/commit.md | 0 docs/{conversions => contrib}/directory.md | 0 .../error_code.md => contrib/error-code.md} | 0 .../{git_workflow.md => git-workflow.md.md} | 0 .../{git_cherry-pick.md => gitcherry-pick.md} | 0 .../github-workflow.md | 2 +- .../go_code.md => contrib/go-code.md} | 12 +++ docs/{conversions => contrib}/images.md | 0 .../{init_config.md => init-config.md} | 0 .../{install_docker.md => install-docker.md} | 0 ...ux_development.md => linux-development.md} | 0 .../{local_actions.md => local-actions.md} | 0 docs/{conversions => contrib}/logging.md | 0 docs/contrib/offline-deployment.md | 4 +- .../{protoc_tools.md => protoc-tools.md} | 0 docs/contrib/test.md | 2 +- docs/contrib/{util_go.md => util-go.md} | 0 .../{util_makefile.md => util-makefile.md} | 0 .../{util_scripts.md => util-scripts.md} | 0 docs/{conversions => contrib}/version.md | 2 +- go.mod | 2 + go.sum | 3 + install_guide.sh | 2 +- pkg/common/cmd/api_test.go | 100 ++++++++++++++++++ pkg/common/cmd/msg_gateway_test.go | 51 +++++++++ scripts/README.md | 6 +- scripts/batch_start_all.sh | 84 --------------- scripts/build.cmd | 13 --- scripts/cherry-pick.sh | 6 +- scripts/{create_topic.sh => create-topic.sh} | 0 scripts/genconfig.sh | 2 +- scripts/init-config.sh | 2 +- scripts/{init_pwd.sh => init-pwd.sh} | 0 scripts/install/environment.sh | 2 +- scripts/install_im_compose.sh | 66 ------------ scripts/make-rules/image.mk | 2 +- scripts/start.bat | 12 --- scripts/template/head.md.tmpl | 4 +- 57 files changed, 323 insertions(+), 269 deletions(-) rename docs/{conversions => contrib}/README.md (77%) rename docs/{conversions => contrib}/api.md (100%) rename docs/{conversions => contrib}/bash_log.md (100%) rename docs/{conversions => contrib}/cicd_actions.md (100%) rename docs/contrib/{code_conventions.md => code-conventions.md} (100%) rename docs/{conversions => contrib}/commit.md (100%) rename docs/{conversions => contrib}/directory.md (100%) rename docs/{conversions/error_code.md => contrib/error-code.md} (100%) rename docs/contrib/{git_workflow.md => git-workflow.md.md} (100%) rename docs/contrib/{git_cherry-pick.md => gitcherry-pick.md} (100%) rename docs/{conversions => contrib}/github-workflow.md (99%) rename docs/{conversions/go_code.md => contrib/go-code.md} (96%) rename docs/{conversions => contrib}/images.md (100%) rename docs/contrib/{init_config.md => init-config.md} (100%) rename docs/contrib/{install_docker.md => install-docker.md} (100%) rename docs/contrib/{linux_development.md => linux-development.md} (100%) rename docs/contrib/{local_actions.md => local-actions.md} (100%) rename docs/{conversions => contrib}/logging.md (100%) rename docs/contrib/{protoc_tools.md => protoc-tools.md} (100%) rename docs/contrib/{util_go.md => util-go.md} (100%) rename docs/contrib/{util_makefile.md => util-makefile.md} (100%) rename docs/contrib/{util_scripts.md => util-scripts.md} (100%) rename docs/{conversions => contrib}/version.md (99%) create mode 100644 pkg/common/cmd/api_test.go create mode 100644 pkg/common/cmd/msg_gateway_test.go delete mode 100755 scripts/batch_start_all.sh delete mode 100644 scripts/build.cmd rename scripts/{create_topic.sh => create-topic.sh} (100%) rename scripts/{init_pwd.sh => init-pwd.sh} (100%) delete mode 100755 scripts/install_im_compose.sh delete mode 100644 scripts/start.bat diff --git a/.env b/.env index bcfc0722a..d77763a3d 100644 --- a/.env +++ b/.env @@ -30,11 +30,11 @@ MINIO_ENDPOINT=http://172.28.0.1:10005 # Base URL for the application programming interface (API). # Default: API_URL=http://172.28.0.1:10002 -API_URL=http://172.28.0.1:10002 +API_URL=http://14.155.59.99:10002 # Directory path for storing data files or related information. # Default: DATA_DIR=./ -DATA_DIR=./ +DATA_DIR=/root/workspaces/openim/open-im-server # Choose the appropriate image address, the default is GITHUB image, # you can choose docker hub, for Chinese users can choose Ali Cloud diff --git a/.github/workflows/api-test.yml b/.github/workflows/api-test.yml index d03f0a139..0bbc86619 100644 --- a/.github/workflows/api-test.yml +++ b/.github/workflows/api-test.yml @@ -1,3 +1,17 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: OpenIM API TEST on: diff --git a/.github/workflows/create_branch_on_tag.yml b/.github/workflows/create_branch_on_tag.yml index 0d8b0d91a..b6b9eb8e8 100644 --- a/.github/workflows/create_branch_on_tag.yml +++ b/.github/workflows/create_branch_on_tag.yml @@ -1,3 +1,17 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Create Branch on Tag on: diff --git a/CHANGELOG/CHANGELOG.md b/CHANGELOG/CHANGELOG.md index 2358b5fb8..f5d62ab24 100644 --- a/CHANGELOG/CHANGELOG.md +++ b/CHANGELOG/CHANGELOG.md @@ -20,7 +20,7 @@ All notable changes to this project will be documented in this file. ## OpenIM versioning policy -+ [OpenIM Version](../docs/conversions/version.md) ++ [OpenIM Version](../docs/contrib/version.md) ## command diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afa8b35d4..ee275e7ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,12 @@ If you are familiar with [Makefile](./Makefile) , you can easily see the clever The [Makefile](./Makefile) is for every developer, even if you don't know how to use the Makefile tool, don't worry, we provide two great commands to get you up to speed with the Makefile architecture, `make help` and `make help-all`, it can reduce problems of the developing environment. +In accordance with the naming conventions adopted by OpenIM and drawing reference from the Google Naming Conventions as per the guidelines available at https://google.github.io/styleguide/go/, the following expectations for naming practices within the project are set forth: + ++ https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md ++ https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md + + ## Code of ConductCode of Conduct #### Code and doc contribution @@ -270,7 +276,7 @@ You can find some very formal PR in [RFC](https://github.com/openimsdk/open-im-s **🈴 Reviewing PRs:** + Be respectful and constructive -+ Assign yourself to the PR ++ Assign yourself to the PR (comment `/assign`) + Check if all checks are passing + Suggest changes instead of simply commenting on found issues + If you are unsure about something, ask the author diff --git a/Makefile b/Makefile index a4964cb3e..42d82274e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ## all: Run tidy, gen, add-copyright, format, lint, cover, build ✨ .PHONY: all -all: tidy gen add-copyright verify lint cover restart +all: tidy gen add-copyright verify test-api lint cover restart # ============================================================================== # Build set diff --git a/README-zh_CN.md b/README-zh_CN.md index f24ee4739..230a59c44 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -86,22 +86,22 @@ OpenIM 我们的目标是建立一个顶级的开源社区。我们有一套标 在开始之前,请确保你的更改是有需求的。最好的方法是创建一个[新的讨论](https://github.com/openimsdk/open-im-server/discussions/new/choose) 或 [Slack 通信](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q),或者如果你发现一个问题,首先[报告它](https://github.com/openimsdk/open-im-server/issues/new/choose)。 -+ [代码标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/go_code.md) ++ [代码标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md) -+ [Docker 镜像标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) ++ [Docker 镜像标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) -+ [目录标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/directory.md) ++ [目录标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/directory.md) -+ [提交标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/commit.md) ++ [提交标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/commit.md) -+ [版本控制标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md) ++ [版本控制标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md) -+ [接口标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/interface.md) ++ [接口标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/interface.md) + [OpenIM配置和环境变量设置](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md) > **Note** -> 针对中国的用户,阅读我们的 [Docker 镜像标准](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) 以便使用国内 aliyun 的镜像地址。OpenIM 也有针对中国的 gitee 同步仓库,你可以在 [gitee.com](https://gitee.com/openimsdk) 上找到它。 +> 针对中国的用户,阅读我们的 [Docker 镜像标准](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) 以便使用国内 aliyun 的镜像地址。OpenIM 也有针对中国的 gitee 同步仓库,你可以在 [gitee.com](https://gitee.com/openimsdk) 上找到它。 ## :link: 链接 diff --git a/README.md b/README.md index 0a569af6e..1e9f98adb 100644 --- a/README.md +++ b/README.md @@ -4,30 +4,27 @@

-

- ⭐️ Open source Instant Messaging Server ⭐️
-

+
+[![Stars](https://img.shields.io/github/stars/openimsdk/open-im-server?style=for-the-badge&logo=github&colorB=ff69b4)](https://github.com/openimsdk/open-im-server/stargazers) +[![Forks](https://img.shields.io/github/forks/openimsdk/open-im-server?style=for-the-badge&logo=github&colorB=blue)](https://github.com/openimsdk/open-im-server/network/members) +[![Codecov](https://img.shields.io/codecov/c/github/openimsdk/open-im-server?style=for-the-badge&logo=codecov&colorB=orange)](https://app.codecov.io/gh/openimsdk/open-im-server) +[![Go Report Card](https://goreportcard.com/badge/github.com/openimsdk/open-im-server?style=for-the-badge)](https://goreportcard.com/report/github.com/openimsdk/open-im-server) +[![Go Reference](https://img.shields.io/badge/Go%20Reference-blue.svg?style=for-the-badge&logo=go&logoColor=white)](https://pkg.go.dev/github.com/openimsdk/open-im-server/v3) +[![License](https://img.shields.io/badge/license-Apache--2.0-green?style=for-the-badge)](https://github.com/openimsdk/open-im-server/blob/main/LICENSE) +[![Slack](https://img.shields.io/badge/Slack-500%2B-blueviolet?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) +[![Best Practices](https://img.shields.io/badge/Best%20Practices-purple?style=for-the-badge)](https://www.bestpractices.dev/projects/8045) +[![Good First Issues](https://img.shields.io/github/issues/openimsdk/open-im-server/good%20first%20issue?style=for-the-badge&logo=github)](https://github.com/openimsdk/open-im-server/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22good+first+issue%22) +[![Language](https://img.shields.io/badge/Language-Go-blue.svg?style=for-the-badge&logo=go&logoColor=white)](https://golang.org/) -

-A+ -good first - - - - -Go Reference -

+[**English**](./README.md) • +[**简体中文**](./README-zh_CN.md) • +[**Docs**](https://openim.io/en) + +

-

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

- -

## Ⓜ️ About OpenIM @@ -118,7 +115,7 @@ It is recommended to use Docker Compose for deployment, which can easily and qui > **Note** > -> If you don't know OpenIM's versioning policy, 📚Read our release policy: https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md +> If you don't know OpenIM's versioning policy, 📚Read our release policy: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md @@ -133,7 +130,7 @@ Ur need `Go 1.20` or higher version, and `make`. go version && make --version || echo "Error: One of the commands failed." ``` -Version Details: https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md +Version Details: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md You can get the version number from the command below or from [github releases](https://github.com/openimsdk/open-im-server/tags). @@ -141,7 +138,7 @@ You can get the version number from the command below or from [github releases]( $ curl --silent "https://api.github.com/repos/openimsdk/open-im-server/releases" | jq -r '.[].tag_name' ``` -We have our own version management policy, if you are interested in our version management, I recommend reading [📚 OpenIM Version](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md), We recommend using stable versions such as `v3.3.0` and `v3.2.0` whenever possible. `v3.1.1-alpha.3` as well as `v3.3.0-beta.0` and `v3.2.0-rc.0` are pre-release or beta versions and are not recommended. +We have our own version management policy, if you are interested in our version management, I recommend reading [📚 OpenIM Version](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md), We recommend using stable versions such as `v3.3.0` and `v3.2.0` whenever possible. `v3.1.1-alpha.3` as well as `v3.3.0-beta.0` and `v3.2.0-rc.0` are pre-release or beta versions and are not recommended. Set `OPENIM_VERSION` environment variables for the latest `OPENIM_VERSION` number, or replace the `OPENIM_VERSION` for you to install the OpenIM-Server `OPENIM_VERSION`: @@ -199,20 +196,22 @@ Delve into the heart of Open-IM-Server's functionality with our architecture dia ## :hammer_and_wrench: To start developing OpenIM +[![Open in Dev Container](https://img.shields.io/static/v1?label=Dev%20Container&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/github/openimsdk/open-im-server) + OpenIM Our goal is to build a top-level open source community. We have a set of standards, in the [Community repository](https://github.com/OpenIMSDK/community). If you'd like to contribute to this Open-IM-Server repository, please read our [contributor documentation](https://github.com/openimsdk/open-im-server/blob/main/CONTRIBUTING.md). Before you start, please make sure your changes are in demand. The best for that is to create a [new discussion](https://github.com/openimsdk/open-im-server/discussions/new/choose) OR [Slack Communication](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q), or if you find an issue, [report it](https://github.com/openimsdk/open-im-server/issues/new/choose) first. -- [Code Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/go_code.md) -- [Docker Images Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) -- [Directory Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/directory.md) -- [Commit Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/commit.md) -- [Versioning Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md) -- [Interface Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/api.md) -- [Log Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/logging.md) -- [Error Code Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/error_code.md) +- [Code Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md) +- [Docker Images Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) +- [Directory Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/directory.md) +- [Commit Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/commit.md) +- [Versioning Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md) +- [Interface Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/api.md) +- [Log Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md) +- [Error Code Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/error-code.md) - [OpenIM configuration and environment variable Settings](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md) diff --git a/build/images/Dockerfile b/build/images/Dockerfile index 518de78b1..51fe94e1c 100644 --- a/build/images/Dockerfile +++ b/build/images/Dockerfile @@ -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. + FROM BASE_IMAGE WORKDIR ${SERVER_WORKDIR} diff --git a/config/config.yaml b/config/config.yaml index e375118f7..0c001e548 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -135,14 +135,14 @@ api: # minio.signEndpoint is minio public network address object: enable: "minio" - apiURL: "http://127.0.0.1:10002" + apiURL: "http://14.155.59.99:10002" minio: bucket: "openim" endpoint: "http://172.28.0.1:10005" accessKeyID: "root" secretAccessKey: "openIM123" sessionToken: '' - signEndpoint: "http://127.0.0.1:10005" + signEndpoint: "http://14.155.59.99:10005" publicRead: false cos: bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com @@ -198,7 +198,7 @@ rpcRegisterName: # Whether to output in json format # Whether to include stack trace in logs log: - storageLocation: ../logs/ + storageLocation: /root/workspaces/openim/open-im-server/logs/ rotationTime: 24 remainRotationCount: 2 remainLogLevel: 6 diff --git a/deployments/README.md b/deployments/README.md index a36ab4cdb..e952830ea 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -106,7 +106,7 @@ $ helm repo add brigade https://openimsdk.github.io/openim-charts ### OpenIM Image Strategy -Automated offerings include aliyun, ghcr, docker hub: [Image Documentation](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) +Automated offerings include aliyun, ghcr, docker hub: [Image Documentation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) **Local Test Build Method:** diff --git a/deployments/charts/openim-msggateway/templates/deployment.yaml b/deployments/charts/openim-msggateway/templates/deployment.yaml index bc2f45a33..679c7b792 100644 --- a/deployments/charts/openim-msggateway/templates/deployment.yaml +++ b/deployments/charts/openim-msggateway/templates/deployment.yaml @@ -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. + apiVersion: apps/v1 kind: Deployment metadata: diff --git a/docker-compose.yml b/docker-compose.yml index 4f8983660..8271b943c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -89,11 +89,11 @@ services: ports: - "${KAFKA_PORT}:9094" volumes: - - ./scripts/create_topic.sh:/opt/bitnami/kafka/create_topic.sh + - ./scripts/create-topic.sh:/opt/bitnami/kafka/create-topic.sh - ${DATA_DIR}/components/kafka:/bitnami/kafka command: > bash -c " - /opt/bitnami/scripts/kafka/run.sh & sleep 5; /opt/bitnami/kafka/create_topic.sh; wait + /opt/bitnami/scripts/kafka/run.sh & sleep 5; /opt/bitnami/kafka/create-topic.sh; wait " environment: - TZ=Asia/Shanghai diff --git a/docs/README.md b/docs/README.md index f9d045c49..75f56e847 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,7 +5,7 @@ Welcome to the OpenIM Documentation hub! This center provides a comprehensive ra ## Table of Contents 1. [Contrib](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib) - Guidance on contributing and configurations for developers -2. [Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions) - Coding conventions, logging policies, and other transformation tools +2. [Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib) - Coding conventions, logging policies, and other transformation tools ------ @@ -13,34 +13,34 @@ Welcome to the OpenIM Documentation hub! This center provides a comprehensive ra This section offers developers a detailed guide on how to contribute code, set up their environment, and follow the associated processes. -- [Code Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code_conventions.md) - Rules and conventions for writing code in OpenIM. +- [Code Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md) - Rules and conventions for writing code in OpenIM. - [Development Guide](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/development.md) - A guide on how to carry out development within OpenIM. -- [Git Cherry Pick](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git_cherry-pick.md) - Guidelines on cherry-picking operations. -- [Git Workflow](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git_workflow.md) - The git workflow in OpenIM. -- [Initialization Configurations](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init_config.md) - Guidance on setting up and initializing OpenIM. -- [Docker Installation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install_docker.md) - How to install Docker on your machine. -- [Linux Development Environment](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/linux_development.md) - Guide to set up the development environment on Linux. -- [Local Actions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/local_actions.md) - Guidelines on how to carry out certain common actions locally. +- [Git Cherry Pick](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/gitcherry-pick.md) - Guidelines on cherry-picking operations. +- [Git Workflow](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git-workflow.md) - The git workflow in OpenIM. +- [Initialization Configurations](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init-config.md) - Guidance on setting up and initializing OpenIM. +- [Docker Installation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md) - How to install Docker on your machine. +- [Linux Development Environment](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/linux-development.md) - Guide to set up the development environment on Linux. +- [Local Actions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/local-actions.md) - Guidelines on how to carry out certain common actions locally. - [Offline Deployment](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/offline-deployment.md) - Methods of deploying OpenIM offline. -- [Protoc Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/protoc_tools.md) - Guide on using protoc tools. -- [Go Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util_go.md) - Tools and libraries in OpenIM for Go. -- [Makefile Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util_makefile.md) - Best practices and tools for Makefile. -- [Script Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util_scripts.md) - Best practices and tools for scripts. +- [Protoc Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/protoc-tools.md) - Guide on using protoc tools. +- [Go Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-go.md) - Tools and libraries in OpenIM for Go. +- [Makefile Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-makefile.md) - Best practices and tools for Makefile. +- [Script Tools](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md) - Best practices and tools for scripts. ## Conversions This section introduces various conventions and policies within OpenIM, encompassing code, logs, versions, and more. -- [API Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/api.md) - Guidelines and methods for API conversions. -- [Logging Policy](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/bash_log.md) - Logging policies and conventions in OpenIM. -- [CI/CD Actions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/cicd_actions.md) - Procedures and conventions for CI/CD. -- [Commit Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/commit.md) - Conventions for code commits in OpenIM. -- [Directory Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/directory.md) - Directory structure and conventions within OpenIM. -- [Error Codes](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/error_code.md) - List and descriptions of error codes. -- [Go Code Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/go_code.md) - Conventions and conversions for Go code. -- [Docker Image Strategy](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) - Management strategies for OpenIM Docker images, spanning multiple architectures and image repositories. -- [Logging Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/logging.md) - Further detailed conventions on logging. -- [Version Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md) - Naming and management strategies for OpenIM versions. +- [API Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/api.md) - Guidelines and methods for API conversions. +- [Logging Policy](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/bash_log.md) - Logging policies and conventions in OpenIM. +- [CI/CD Actions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/cicd_actions.md) - Procedures and conventions for CI/CD. +- [Commit Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/commit.md) - Conventions for code commits in OpenIM. +- [Directory Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/directory.md) - Directory structure and conventions within OpenIM. +- [Error Codes](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/error-code.md) - List and descriptions of error codes. +- [Go Code Conversions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md) - Conventions and conversions for Go code. +- [Docker Image Strategy](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) - Management strategies for OpenIM Docker images, spanning multiple architectures and image repositories. +- [Logging Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md) - Further detailed conventions on logging. +- [Version Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md) - Naming and management strategies for OpenIM versions. ## For Developers, Contributors, and Community Maintainers @@ -49,7 +49,7 @@ This section introduces various conventions and policies within OpenIM, encompas If you're a developer or someone keen on contributing: -- Familiarize yourself with our [Code Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code_conventions.md) and [Git Workflow](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git_workflow.md) to ensure smooth contributions. +- Familiarize yourself with our [Code Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md) and [Git Workflow](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git-workflow.md) to ensure smooth contributions. - Dive into the [Development Guide](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/development.md) to get a hang of the development practices in OpenIM. ### Community Maintainers @@ -57,11 +57,11 @@ If you're a developer or someone keen on contributing: As a community maintainer: - Ensure that contributions align with the standards outlined in our documentation. -- Regularly review the [Logging Policy](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/bash_log.md) and [Error Codes](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/error_code.md) to stay updated. +- Regularly review the [Logging Policy](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/bash_log.md) and [Error Codes](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/error-code.md) to stay updated. ## For Users Users should pay particular attention to: -- [Docker Installation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install_docker.md) - Necessary if you're planning to use Docker images of OpenIM. -- [Docker Image Strategy](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) - To understand the different images available and how to choose the right one for your architecture. \ No newline at end of file +- [Docker Installation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md) - Necessary if you're planning to use Docker images of OpenIM. +- [Docker Image Strategy](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) - To understand the different images available and how to choose the right one for your architecture. \ No newline at end of file diff --git a/docs/conversions/README.md b/docs/contrib/README.md similarity index 77% rename from docs/conversions/README.md rename to docs/contrib/README.md index e8532728c..1148318dc 100644 --- a/docs/conversions/README.md +++ b/docs/contrib/README.md @@ -1,10 +1,10 @@ ## OpenIM Project Development Standards -- [Code Standards](./go_code.md) +- [Code Standards](./go-code.md) - [Docker Images Standards](./images.md) - [Directory Standards](./directory.md) - [Commit Standards](./commit.md) - [Versioning Standards](./version.md) - [Interface Standards](./api.md) - [Log Standards](./log.md) -- [Error Code Standards](./error_code.md) +- [Error Code Standards](./error-code.md) diff --git a/docs/conversions/api.md b/docs/contrib/api.md similarity index 100% rename from docs/conversions/api.md rename to docs/contrib/api.md diff --git a/docs/conversions/bash_log.md b/docs/contrib/bash_log.md similarity index 100% rename from docs/conversions/bash_log.md rename to docs/contrib/bash_log.md diff --git a/docs/conversions/cicd_actions.md b/docs/contrib/cicd_actions.md similarity index 100% rename from docs/conversions/cicd_actions.md rename to docs/contrib/cicd_actions.md diff --git a/docs/contrib/code_conventions.md b/docs/contrib/code-conventions.md similarity index 100% rename from docs/contrib/code_conventions.md rename to docs/contrib/code-conventions.md diff --git a/docs/conversions/commit.md b/docs/contrib/commit.md similarity index 100% rename from docs/conversions/commit.md rename to docs/contrib/commit.md diff --git a/docs/conversions/directory.md b/docs/contrib/directory.md similarity index 100% rename from docs/conversions/directory.md rename to docs/contrib/directory.md diff --git a/docs/conversions/error_code.md b/docs/contrib/error-code.md similarity index 100% rename from docs/conversions/error_code.md rename to docs/contrib/error-code.md diff --git a/docs/contrib/git_workflow.md b/docs/contrib/git-workflow.md.md similarity index 100% rename from docs/contrib/git_workflow.md rename to docs/contrib/git-workflow.md.md diff --git a/docs/contrib/git_cherry-pick.md b/docs/contrib/gitcherry-pick.md similarity index 100% rename from docs/contrib/git_cherry-pick.md rename to docs/contrib/gitcherry-pick.md diff --git a/docs/conversions/github-workflow.md b/docs/contrib/github-workflow.md similarity index 99% rename from docs/conversions/github-workflow.md rename to docs/contrib/github-workflow.md index 64b530740..0afbae144 100644 --- a/docs/conversions/github-workflow.md +++ b/docs/contrib/github-workflow.md @@ -83,7 +83,7 @@ You may now edit files on the `myfeature` branch. ### Building open-im-server -This workflow is process-specific. For quick-start build instructions for [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util_makefile.md) +This workflow is process-specific. For quick-start build instructions for [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-makefile.md) ## 4. Keep your branch in sync diff --git a/docs/conversions/go_code.md b/docs/contrib/go-code.md similarity index 96% rename from docs/conversions/go_code.md rename to docs/contrib/go-code.md index c0b49bb8a..1de448da7 100644 --- a/docs/conversions/go_code.md +++ b/docs/contrib/go-code.md @@ -312,6 +312,18 @@ The naming convention is a very important part of the code specification. A unif - The function name is in camel case, and the first letter is uppercase or lowercase according to the access control decision,For example: `MixedCaps` or `mixedCaps`. - Code automatically generated by code generation tools (such as `xxxx.pb.go`) and underscores used to group related test cases (such as `TestMyFunction_WhatIsBeingTested`) exclude this rule. +In accordance with the naming conventions adopted by OpenIM and drawing reference from the Google Naming Conventions as per the guidelines available at https://google.github.io/styleguide/go/, the following expectations for naming practices within the project are set forth: + +1. **File Names:** + + Both hyphens (`-`) and underscores (`_`) are permitted when naming files. + + A preference is established for the use of underscores (`_`), suggesting it as the best practice in general scenarios. +2. **Script and Markdown Files:** + + For shell scripts (bash files) and Markdown (`.md`) documents, the use of hyphens (`-`) is recommended. + + This recommendation is based on the improved searchability and compatibility in web browsers when hyphens are used in names. +3. **Directories:** + + A consistent approach is mandated for naming directories, exclusively using hyphens (`-`) to separate words within directory names. + + ### 2.3 File Naming - Keep the filename short and meaningful. diff --git a/docs/conversions/images.md b/docs/contrib/images.md similarity index 100% rename from docs/conversions/images.md rename to docs/contrib/images.md diff --git a/docs/contrib/init_config.md b/docs/contrib/init-config.md similarity index 100% rename from docs/contrib/init_config.md rename to docs/contrib/init-config.md diff --git a/docs/contrib/install_docker.md b/docs/contrib/install-docker.md similarity index 100% rename from docs/contrib/install_docker.md rename to docs/contrib/install-docker.md diff --git a/docs/contrib/linux_development.md b/docs/contrib/linux-development.md similarity index 100% rename from docs/contrib/linux_development.md rename to docs/contrib/linux-development.md diff --git a/docs/contrib/local_actions.md b/docs/contrib/local-actions.md similarity index 100% rename from docs/contrib/local_actions.md rename to docs/contrib/local-actions.md diff --git a/docs/conversions/logging.md b/docs/contrib/logging.md similarity index 100% rename from docs/conversions/logging.md rename to docs/contrib/logging.md diff --git a/docs/contrib/offline-deployment.md b/docs/contrib/offline-deployment.md index f5083ad12..39fc3598e 100644 --- a/docs/contrib/offline-deployment.md +++ b/docs/contrib/offline-deployment.md @@ -26,11 +26,11 @@ docker pull minio/minio ## 2. OpenIM & Chat Images -**For detailed understanding of version management and storage of OpenIM and Chat**: [version.md](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/version.md) +**For detailed understanding of version management and storage of OpenIM and Chat**: [version.md](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md) ### OpenIM Image -- Get image version info: [images.md](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md) +- Get image version info: [images.md](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md) - Depending on the required version, execute the following command: ```bash diff --git a/docs/contrib/protoc_tools.md b/docs/contrib/protoc-tools.md similarity index 100% rename from docs/contrib/protoc_tools.md rename to docs/contrib/protoc-tools.md diff --git a/docs/contrib/test.md b/docs/contrib/test.md index 3fe03b767..37c1792cf 100644 --- a/docs/contrib/test.md +++ b/docs/contrib/test.md @@ -6,6 +6,7 @@ This document serves as a comprehensive guide to understanding and utilizing the For some complex, bulky functional tests, performance tests, and various e2e tests, We are all in the current warehouse to https://github.com/OpenIMSDK/Open-IM-Server/tree/main/test or https://github.com/openim-sigs/test-infra directory In the. ++ About OpenIM Feature [Test Docs](https://docs.google.com/spreadsheets/d/1zELWkwxgOOZ7u5pmYCqqaFnvZy2SVajv/edit?usp=sharing&ouid=103266350914914783293&rtpof=true&sd=true) ## Usage @@ -180,4 +181,3 @@ By following the guidelines and instructions outlined in this document, you can | `openim::test::get_user_req_group_applicationList` | Get User Requested Group Application List API | Retrieves the list of group applications requested by a user to validate tracking of user's applications. | | `openim::test::mute_group_member` | Mute Group Member API | Tests the ability to mute a specific member within a group, disabling their ability to send messages. | | `openim::test::get_group_users_req_application_list` | Get Group Users Request Application List API | Retrieves a list of user requests for group applications to validate group request management. | - diff --git a/docs/contrib/util_go.md b/docs/contrib/util-go.md similarity index 100% rename from docs/contrib/util_go.md rename to docs/contrib/util-go.md diff --git a/docs/contrib/util_makefile.md b/docs/contrib/util-makefile.md similarity index 100% rename from docs/contrib/util_makefile.md rename to docs/contrib/util-makefile.md diff --git a/docs/contrib/util_scripts.md b/docs/contrib/util-scripts.md similarity index 100% rename from docs/contrib/util_scripts.md rename to docs/contrib/util-scripts.md diff --git a/docs/conversions/version.md b/docs/contrib/version.md similarity index 99% rename from docs/conversions/version.md rename to docs/contrib/version.md index 95f736be4..0e03b8d8b 100644 --- a/docs/conversions/version.md +++ b/docs/contrib/version.md @@ -212,4 +212,4 @@ Throughout this process, active communication within the team is pivotal to main ## Docker Images Version Management -For more details on managing Docker image versions, visit [OpenIM Docker Images Administration](https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md). +For more details on managing Docker image versions, visit [OpenIM Docker Images Administration](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md). diff --git a/go.mod b/go.mod index 31f067693..c754d45ca 100644 --- a/go.mod +++ b/go.mod @@ -73,6 +73,7 @@ require ( github.com/go-zookeeper/zk v1.0.3 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.1 // indirect @@ -139,6 +140,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect + gotest.tools v2.2.0+incompatible // indirect ) require ( diff --git a/go.sum b/go.sum index 2fa9b872c..99d272692 100644 --- a/go.sum +++ b/go.sum @@ -144,6 +144,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= @@ -531,6 +532,8 @@ gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/install_guide.sh b/install_guide.sh index f42e65b9d..b10ab2edd 100755 --- a/install_guide.sh +++ b/install_guide.sh @@ -147,7 +147,7 @@ EOF cd scripts; chmod +x *.sh; - ./init_pwd.sh; + ./init-pwd.sh; ./env_check.sh; cd ..; docker-compose up -d; diff --git a/pkg/common/cmd/api_test.go b/pkg/common/cmd/api_test.go new file mode 100644 index 000000000..74847ba2b --- /dev/null +++ b/pkg/common/cmd/api_test.go @@ -0,0 +1,100 @@ +// Copyright © 2023 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "testing" + + "github.com/OpenIMSDK/protocol/constant" +) + +func TestApiCmd_AddApi(t *testing.T) { + type fields struct { + RootCmd *RootCmd + } + type args struct { + f func(port int) error + } + tests := []struct { + name string + fields fields + args args + // No 'want' field here since we're testing side effects, not return values. + }{ + { + name: "adds API with valid function", + fields: fields{ + RootCmd: &RootCmd{ + // setup RootCmd properties as needed for the test + }, + }, + args: args{ + f: func(port int) error { + // implement a mock function or check side effects + return nil + }, + }, + }, + // Add more test cases as needed. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := &ApiCmd{ + RootCmd: tt.fields.RootCmd, + } + a.AddApi(tt.args.f) + // Test the side effects or behavior of AddApi here. + }) + } +} + +func TestApiCmd_GetPortFromConfig(t *testing.T) { + type fields struct { + RootCmd *RootCmd + } + type args struct { + portType string + } + tests := []struct { + name string + fields fields + args args + want int + }{ + { + name: "gets API port from config", + fields: fields{ + RootCmd: &RootCmd{ + // setup RootCmd properties as needed for the test + }, + }, + args: args{ + portType: constant.FlagPort, + }, + want: 8080, // This should be the expected port number according to your configuration + }, + // Add more test cases for different portTypes and expected results. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := &ApiCmd{ + RootCmd: tt.fields.RootCmd, + } + if got := a.GetPortFromConfig(tt.args.portType); got != tt.want { + t.Errorf("ApiCmd.GetPortFromConfig() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/common/cmd/msg_gateway_test.go b/pkg/common/cmd/msg_gateway_test.go new file mode 100644 index 000000000..c0ea2b057 --- /dev/null +++ b/pkg/common/cmd/msg_gateway_test.go @@ -0,0 +1,51 @@ +// Copyright © 2023 OpenIM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "testing" + + "github.com/OpenIMSDK/protocol/constant" + "github.com/stretchr/testify/mock" + "gotest.tools/assert" +) + +// MockRootCmd is a mock type for the RootCmd type +type MockRootCmd struct { + mock.Mock +} + +func (m *MockRootCmd) Execute() error { + args := m.Called() + return args.Error(0) +} + +func TestMsgGatewayCmd_GetPortFromConfig(t *testing.T) { + msgGatewayCmd := &MsgGatewayCmd{RootCmd: &RootCmd{}} + tests := []struct { + portType string + want int + }{ + {constant.FlagWsPort, 8080}, // Replace 8080 with the expected port from the config + {constant.FlagPort, 8081}, // Replace 8081 with the expected port from the config + {"invalid", 0}, + } + for _, tt := range tests { + t.Run(tt.portType, func(t *testing.T) { + got := msgGatewayCmd.GetPortFromConfig(tt.portType) + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/scripts/README.md b/scripts/README.md index bb35a3622..b19717fd9 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -51,7 +51,7 @@ scripts/ ├── golangci.yml # Configuration for GolangCI linting. ├── init-config.sh # Initialize configurations. ├── init-env.sh # Initialize the environment. -├── init_pwd.sh # Initialize or set password. +├── init-pwd.sh # Initialize or set password. ├── install # Installation scripts directory. │ ├── README.md # Installation documentation. │ ├── common.sh # Common utilities for installation. @@ -123,7 +123,7 @@ Each directory and script in the structure should be understood as a part of a l **PATH:** `scripts/lib/logging.sh` -+ [log details](../docs/conversions/bash_log.md) ++ [log details](../docs/contrib/bash_log.md) ## Supported platforms @@ -154,7 +154,7 @@ $ make demo More about `make` read: -+ [makefile](../docs/conversions/go_code.md) ++ [makefile](../docs/contrib/go-code.md) Instructions for producing the demo movie: diff --git a/scripts/batch_start_all.sh b/scripts/batch_start_all.sh deleted file mode 100755 index 5836144aa..000000000 --- a/scripts/batch_start_all.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env bash -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#fixme This scripts is the total startup scripts -#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array - -set -o errexit -set -o nounset -set -o pipefail - -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "${OPENIM_ROOT}/scripts/lib/init.sh" - -trap 'openim::util::onCtrlC' INT - -need_to_start_server_shell=( - "oepnim-api.sh" - "openim-rpc.sh" - "openim-msggateway.sh" - "openim-push.sh" - "openim-msgtransfer.sh" -) - -time=$(date +"%Y-%m-%d %H:%M:%S") - -for _ in {1..3}; do - echo "==========================================================" >> $OPENIM_ROOT/logs/openIM.log 2>&1 -done - -echo "==========server start time:${time}===========" >> $OPENIM_ROOT/logs/openIM.log 2>&1 - -for _ in {1..3}; do - echo "==========================================================" >> $OPENIM_ROOT/logs/openIM.log 2>&1 -done - -build_pid_array=() -idx=0 -for i in ${need_to_start_server_shell[*]}; do - chmod +x $i - ./$i & - build_pid=$! - echo "build_pid " $build_pid - build_pid_array[idx]=$build_pid - let idx=idx+1 -done - -echo "wait all start finish....." - -exit 0 - -success_num=0 -for ((i = 0; i < ${#need_to_start_server_shell[*]}; i++)); do - echo "wait pid: " ${build_pid_array[i]} ${need_to_start_server_shell[$i]} - wait ${build_pid_array[i]} - stat=$? - echo ${build_pid_array[i]} " " $stat - if [ $stat == 0 ] - then - # echo -e "${GREEN_PREFIX}${need_to_start_server_shell[$i]} successfully be built ${COLOR_SUFFIX}\n" - let success_num=$success_num+1 - - else - #echo -e "${RED_PREFIX}${need_to_start_server_shell[$i]} build failed ${COLOR_SUFFIX}\n" - exit -1 - fi -done - -echo "success_num" $success_num "service num:" ${#need_to_start_server_shell[*]} -if [ $success_num == ${#need_to_start_server_shell[*]} ] -then - echo -e ${BACKGROUND_GREEN}"all services build success"${COLOR_SUFFIX} -fi diff --git a/scripts/build.cmd b/scripts/build.cmd deleted file mode 100644 index d153e6d9e..000000000 --- a/scripts/build.cmd +++ /dev/null @@ -1,13 +0,0 @@ -@echo off -set output_dir=%~dp0..\_output\bin\platforms\windows - -set "rpc_apps=auth conversation friend group msg third user" -set "other_apps=api push msgtransfer msggateway" - -for %%a in (%rpc_apps%) do ( - go build -o %output_dir%\%%a.exe ../cmd/openim-rpc/openim-rpc-%%a/main.go -) - -for %%a in (%other_apps%) do ( - go build -o %output_dir%\%%a.exe ../cmd/openim-%%a/main.go -) diff --git a/scripts/cherry-pick.sh b/scripts/cherry-pick.sh index 200ee8ed8..5f13ef0e4 100755 --- a/scripts/cherry-pick.sh +++ b/scripts/cherry-pick.sh @@ -14,7 +14,7 @@ # limitations under the License. -# Usage Instructions: https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/git_cherry-pick.md +# Usage Instructions: https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md # Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How # meta.) Assumes you care about pulls from remote "upstream" and @@ -68,7 +68,7 @@ if [[ "$#" -lt 2 ]]; then echo " Set UPSTREAM_REMOTE (default: upstream) and FORK_REMOTE (default: origin)" echo " to override the default remote names to what you have locally." echo - echo " For merge process info, see https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/git_cherry-pick.md" + echo " For merge process info, see https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md" exit 2 fi @@ -145,7 +145,7 @@ Cherry pick of ${PULLSUBJ} on ${rel}. ${numandtitle} -For details on the cherry pick process, see the [cherry pick requests](https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/git_cherry-pick.md) page. +For details on the cherry pick process, see the [cherry pick requests](https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md) page. \`\`\`release-note diff --git a/scripts/create_topic.sh b/scripts/create-topic.sh similarity index 100% rename from scripts/create_topic.sh rename to scripts/create-topic.sh diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index 2d3e6313d..9c5f39a11 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -15,7 +15,7 @@ # 本脚本功能:根据 scripts/environment.sh 配置,生成 OPENIM 组件 YAML 配置文件。 # 示例:./scripts/genconfig.sh scripts/install/environment.sh scripts/template/config.yaml -# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init_config.md +# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init-config.md env_file="$1" template_file="$2" diff --git a/scripts/init-config.sh b/scripts/init-config.sh index d38436129..9da84fb21 100755 --- a/scripts/init-config.sh +++ b/scripts/init-config.sh @@ -14,7 +14,7 @@ # limitations under the License. # This script automatically initializes the various configuration files -# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init_config.md +# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init-config.md set -o errexit set -o nounset diff --git a/scripts/init_pwd.sh b/scripts/init-pwd.sh similarity index 100% rename from scripts/init_pwd.sh rename to scripts/init-pwd.sh diff --git a/scripts/install/environment.sh b/scripts/install/environment.sh index 01e531f9f..26c9141e0 100755 --- a/scripts/install/environment.sh +++ b/scripts/install/environment.sh @@ -15,7 +15,7 @@ # This is a file that initializes variables for the automation script that initializes the config file # You need to supplement the script according to the specification. -# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init_config.md +# Read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/init-config.md # 格式化 bash 注释:https://tool.lu/shell/ # 配置中心文档:https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md diff --git a/scripts/install_im_compose.sh b/scripts/install_im_compose.sh deleted file mode 100755 index 06a573424..000000000 --- a/scripts/install_im_compose.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash - -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "${OPENIM_ROOT}/scripts/lib/init.sh" -source "${OPENIM_ROOT}/scripts/install/environment.sh" - -openim::util::onCtrlC - -docker_compose_file_name="docker-compose.yaml" - -# Load environment variables from .env file -load_env() { - source "${OPENIM_ROOT}"/.env -} - -# Replace local IP with public IP in .env -replace_ip() { - if [ "$API_URL" == "http://127.0.0.1:10002/object/" ]; then - sed -i "s/127.0.0.1/${internet_ip}/" "${OPENIM_ROOT}"/.env - fi - - if [ "$MINIO_ENDPOINT" == "http://127.0.0.1:10005" ]; then - sed -i "s/127.0.0.1/${internet_ip}/" "${OPENIM_ROOT}"/.env - fi - - openim::log::info "Your minio endpoint is ${MINIO_ENDPOINT}" -} - -# Execute necessary scripts -execute_scripts() { - chmod +x "${OPENIM_ROOT}"/scripts/*.sh - openim::log::info "Executing init_pwd.sh" - "${OPENIM_ROOT}"/scripts/init_pwd.sh - - openim::log::info "Executing env_check.sh" - "${OPENIM_ROOT}"/scripts/env_check.sh -} - -openim::util::check_docker_and_compose_versions - -main() { - load_env - openim::util::get_server_ip - replace_ip - execute_scripts - start_docker_compose - openim::log::success "Script executed successfully" -} - -# Run the main function -main \ No newline at end of file diff --git a/scripts/make-rules/image.mk b/scripts/make-rules/image.mk index fa7f8ee9c..14a4b2c31 100644 --- a/scripts/make-rules/image.mk +++ b/scripts/make-rules/image.mk @@ -22,7 +22,7 @@ DOCKER := docker -# read: https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md +# read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md REGISTRY_PREFIX ?= registry.cn-hangzhou.aliyuncs.com/openimsdk # REGISTRY_PREFIX ?= ghcr.io/openimsdk diff --git a/scripts/start.bat b/scripts/start.bat deleted file mode 100644 index 8054acdc4..000000000 --- a/scripts/start.bat +++ /dev/null @@ -1,12 +0,0 @@ -cd %~p0../_output/bin/platforms/windows -start api.exe -p 10002 -start auth.exe -p 10060 -start conversation.exe -p 10080 -start friend.exe -p 10020 -start group.exe -p 10050 -start msg.exe -p 10030 -start msggateway.exe -p 10040 -w 10001 -start msgtransfer.exe -start third.exe -p 10090 -start push.exe -p 10070 -start user.exe -p 10010 \ No newline at end of file diff --git a/scripts/template/head.md.tmpl b/scripts/template/head.md.tmpl index 41dac30ef..e024ab4ab 100644 --- a/scripts/template/head.md.tmpl +++ b/scripts/template/head.md.tmpl @@ -6,9 +6,9 @@ Learn more about versions of OpenIM: + We release logs are recorded on [✨CHANGELOG](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/CHANGELOG/CHANGELOG.md) -+ For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/conversions/version.md) ++ For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/contrib/version.md) -+ If you wish to use mirroring, read OpenIM's [🤲image management policy](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/conversions/images.md) ++ If you wish to use mirroring, read OpenIM's [🤲image management policy](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/contrib/images.md) **Want to be one of them 😘?**