### Start Kafka with Docker Compose Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/kafka.md Use this command to install and start Kafka using the provided Docker Compose script. ```bash docker compose up -d ``` -------------------------------- ### Start OpenIM Chat from Source Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Start the openim-chat service after configuring it. ```bash make start ``` -------------------------------- ### Install OpenIM Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Run the installation script to deploy all OpenIM components. Use either the short or long flag for installation. ```bash ./scripts/install/install.sh -i ``` ```bash ./scripts/install/install.sh --install ``` -------------------------------- ### Install Go using Homebrew Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Installs the Go programming language using Homebrew. Ensure the installed version is compatible with OpenIM requirements. ```shell brew install go ``` -------------------------------- ### Install Kafka Client Tools Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/kafka.md Install the `kafkactl` command-line tool for easier Kafka management if you used OpenIM's Docker Compose for installation. ```bash make install.kafkactl ``` -------------------------------- ### Test Docker Installation Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md Verifies the Docker installation by running the 'hello-world' container. ```bash $ docker run hello-world ``` -------------------------------- ### Install act Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/local-actions.md Installs the 'act' tool by downloading and executing an installation script. Ensure you have curl installed. ```bash curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash ``` -------------------------------- ### Handle HTTP Requests With Context (Correct) Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md This example shows how to use `context.Context` with an HTTP GET request, enabling cancellation and deadline management. The `main` function sets a 5-second timeout. ```go package main import ( "context" "io/ioutil" "net/http" "log" "time" ) // FetchDataWithContext makes an HTTP GET request to the specified URL using the provided context. // This allows the request to be cancelled or timed out according to the context's deadline. func FetchDataWithContext(ctx context.Context, url string) (string, error) { req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return "", err } resp, err := http.DefaultClient.Do(req) if err != nil { return "", err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } return string(body), nil } func main() { // Create a context with a 5-second timeout ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() data, err := FetchDataWithContext(ctx, "http://example.com") if err != nil { log.Fatalf("Failed to fetch data: %v", err) } log.Println(data) } ``` -------------------------------- ### Start Docker Service Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md Starts the Docker service using systemctl. ```bash $ systemctl start docker ``` -------------------------------- ### Logging Info Level Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Demonstrates how to initialize a logger with a name and log an informational message with key-value pairs. ```go func main() { logger := log.NewLogger().WithName("MyService") ctx := context.Background() logger.Info(ctx, "Service started", "port", "8080") } ``` -------------------------------- ### Install Docker Compose Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md Downloads and installs Docker Compose to the system. Ensure you have sudo privileges. ```bash $ sudo curl -L "https://github.com/docker/compose/releases/download/latest/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose ``` -------------------------------- ### Start and Enable OpenIM Systemd Services Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Reload the systemd daemon, enable the services to start on boot, and then restart them to apply the new configurations. ```bash for service in "${services[@]}" do sudo systemctl daemon-reload sudo systemctl enable $service sudo systemctl restart $service done ``` -------------------------------- ### Start OpenIM Server from Source Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Starts the OpenIM server application after configuration changes have been applied. ```shell make start ``` -------------------------------- ### Install Golang CI Lint Locally Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Use this command for local development to install Golang CI Lint. ```bash make lint ``` -------------------------------- ### Go Commenting: Function Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Illustrates the correct format for function comments in Go. Comments should start with the function name, be a complete sentence, and not exceed 120 characters per line. ```go // PrintFlags logs the flags in the flagset. func PrintFlags(flags *pflag. FlagSet) { // normal code } ``` -------------------------------- ### Install Docker Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md Installs Docker using a curl script, specifying the Aliyun mirror for faster downloads. ```bash $ curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun ``` -------------------------------- ### Handle HTTP Requests Without Context (Incorrect) Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md This example demonstrates an HTTP GET request that does not utilize context, making it impossible to cancel or set a deadline. This can lead to wasted resources. ```go package main import ( "io/ioutil" "net/http" "log" ) // FetchData makes an HTTP GET request to the specified URL and returns the response body. // This function does not use context, making it impossible to cancel the request or set a deadline. func FetchData(url string) (string, error) { resp, err := http.Get(url) // Incorrect: Ignoring context if err != nil { return "", err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } return string(body), nil } func main() { data, err := FetchData("http://example.com") if err != nil { log.Fatalf("Failed to fetch data: %v", err) } log.Println(data) } ``` -------------------------------- ### Install Git using Homebrew Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Installs the Git version control system using the Homebrew package manager. ```shell brew install git ``` -------------------------------- ### Install gotests Tool Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Install the gotests tool, which is used for automatically generating test cases. ```bash make install.gotests ``` -------------------------------- ### Enable or Disable Services on Boot with systemctl Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Control whether services automatically start when the system boots up. Use 'enable' to start at boot and 'disable' to prevent it. ```bash systemctl enable ``` ```bash systemctl disable ``` -------------------------------- ### Install Latest Git Version Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/linux-development.md Compile and install a recent version of Git from source. This ensures compatibility with newer Git commands and features. It involves downloading, extracting, configuring, compiling, and installing Git. ```bash $ cd /tmp $ wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.36.1.tar.gz $ tar -xvzf git-2.36.1.tar.gz $ cd git-2.36.1/ $ ./configure $ make $ sudo make install $ git --version ``` -------------------------------- ### Go Doc Command Examples Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-doc.md Demonstrates various ways to use the `go doc` command to retrieve documentation for Go entities. Specify identifiers to tailor output, or use flags like `-u` and `-all` to include unexported or all program entities. ```go go doc sync.WaitGroup.Add ``` ```go go doc -u -all sync.WaitGroup ``` ```go go doc -u sync ``` -------------------------------- ### Start and Stop OpenIM Services Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Control the operation of individual OpenIM services using 'systemctl start' to begin a service or 'systemctl stop' to halt it. ```bash systemctl start openim-api.service ``` ```bash systemctl stop openim-api.service ``` -------------------------------- ### Test Docker Compose Installation Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-docker.md Checks the installed version of Docker Compose. ```bash $ docker-compose --version ``` -------------------------------- ### Install godoc Tool Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-doc.md Install the `godoc` command-line tool for viewing Go documentation locally in a web format, especially useful in environments without internet access. This command is not part of the Go compiler suite post-Go 1.12. ```shell go get -u -v golang.org/x/tools/cmd/godoc ``` -------------------------------- ### JSON User Data Example Source: https://github.com/openimsdk/open-im-server/blob/main/test/testdata/README.md This JSON snippet provides an example of mock user data, including user ID, username, and password. ```json "users": [ { "id": 1, "username": "user1", "password": "password1" }, { "id": 2, "username": "user2", "password": "password2" } ] ``` -------------------------------- ### Start OpenIM with Docker Compose Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/prometheus-grafana.md Start the OpenIM service using Docker Compose after cloning the repository. This command downloads images and launches the services in detached mode. ```bash docker-compose up -d ``` -------------------------------- ### Basic systemctl Commands for Service Management Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Learn essential systemctl commands to manage the lifecycle of your services. Use these for starting, stopping, and restarting services as needed. ```bash systemctl start systemctl stop systemctl restart ``` -------------------------------- ### Example: Dynamic Key-Value Pairs from Context Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Shows how to use WrapMsg with dynamic variables from the runtime context, such as user IDs and operation details, to enrich error messages. ```go // Define some context variables userID := "user123" operation := "update profile" errorCode := 500 requestURL := "webhook://example.com/updateProfile" // Create a new error err := errors.New("original error") // Wrap the error, including dynamic key-value pairs from the context wrappedErr := errs.WrapMsg(err, "operation failed", "user", userID, "action", operation, "code", errorCode, "url", requestURL) // wrappedErr will contain the original error, call stack, and "operation failed user=user123, action=update profile, code=500, url=http://example.com/updateProfile" ``` -------------------------------- ### Start s3convert Tool Source: https://github.com/openimsdk/open-im-server/blob/main/tools/s3/README.md Execute the s3convert tool to perform data conversion. Provide the path to the configuration directory and the name of the old S3 storage. ```shell ./s3convert -config -name # ./s3convert -config ./../../config -name minio ``` -------------------------------- ### Golang CI Lint Configuration Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md Example YAML configuration for Golang CI Lint, specifying which linters to enable and disable. It prioritizes specific linters for code quality checks and formatting. ```yaml linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint # enable-all: true disable-all: true enable: - typecheck # Basic type checking - gofmt # Format check - govet # Go's standard linting tool - gosimple # Suggestions for simplifying code - misspell # Spelling mistakes - staticcheck # Static analysis - unused # Checks for unused code - goimports # Checks if imports are correctly sorted and formatted - godot # Checks for comment punctuation - bodyclose # Ensures HTTP response body is closed - errcheck # Checks for missed error returns fast: true ``` -------------------------------- ### Golang CI Lint Configuration Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Example configuration for golangci-lint, specifying enabled linters and runtime options. This configuration disables all linters by default and then enables a specific set, including type checking, formatting, and static analysis tools. It also sets the 'fast' option to true for quicker checks. ```yaml linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint # enable-all: true disable-all: true enable: - typecheck # Basic type checking - gofmt # Format check - govet # Go's standard linting tool - gosimple # Suggestions for simplifying code - misspell # Spelling mistakes - staticcheck # Static analysis - unused # Checks for unused code - goimports # Checks if imports are correctly sorted and formatted - godot # Checks for comment punctuation - bodyclose # Ensures HTTP response body is closed - errcheck # Checks for missed error returns fast: true ``` -------------------------------- ### Go Structure Annotation Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md Provides an example of annotating exported structures and their members in Go. Ensure structures and their fields have clear, concise comments. ```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"` } ``` -------------------------------- ### Install OpenIM Project Dependencies Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/linux-development.md Install essential development tools and libraries required for the OpenIM project using the apt package manager. This includes build tools, libraries for curl, zlib, expat, and SSL. ```bash $ sudo apt-get update $ sudo apt-get install build-essential autoconf automake cmake perl libcurl4-gnutls-dev libtool gcc g++ glibc-doc-reference zlib1g-dev git-lfs telnet lrzsz jq libexpat1-dev libssl-dev $ sudo apt install libcurl4-openssl-dev ``` -------------------------------- ### Setting Up OpenIM Git Repository Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/git-workflow.md Steps to fork the OpenIM repository, clone it locally, add the upstream remote, and configure push restrictions. Ensures proper contribution setup. ```sh ## Clone fork to local storage export user="your github profile name" git clone https://github.com/$user/OpenIM.git # or: git clone git@github.com:$user/OpenIM.git ## Add OpenIM as upstream to your fork cd OpenIM git remote add upstream https://github.com/openimsdk/open-im-server.git # or: git remote add upstream git@github.com:openimsdk/open-im-server.git ## Ensure to never push to upstream directly git remote set-url --push upstream no_push ## Confirm that your remotes make sense: git remote -v ``` -------------------------------- ### Clone and Deploy OpenIM using Docker Compose Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Clone the openim-docker repository, set the OpenIM IP, initialize, and start the services using Docker Compose. ```bash git clone https://github.com/openimsdk/openim-docker cd openim-docker export OPENIM_IP="Your IP" make init docker compose up -d docker compose logs -f openim-server docker compose logs -f openim-chat ``` -------------------------------- ### Copy OpenIM Binaries to Install Directory Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Place the OpenIM API and crontask executable files into the designated bin directory after sourcing environment variables. ```bash source ./environment.sh mkdir -p ${OPENIM_INSTALL_DIR}/bin cp openim-api openim-crontask ${OPENIM_INSTALL_DIR}/bin ``` -------------------------------- ### Check OpenIM Server Startup Status Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Verifies if the OpenIM server has started successfully. It's recommended to wait a few minutes before running this command. ```shell make check ``` -------------------------------- ### Deploy OpenIM using Docker Compose Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/offline-deployment.md Commands to initialize configuration, set the OpenIM IP address, and start the OpenIM services using docker compose. Ensure you are in the openim-docker directory. ```bash export OPENIM_IP="your ip" # Set Ip make init # Init config docker compose up -d # Deployment docker compose ps # Verify ``` -------------------------------- ### Cherry-Pick Example: Apply Commit to Main Branch Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/gitcherry-pick.md Demonstrates switching to the 'main' branch and then cherry-picking a specific commit from the 'release-v3.1' branch. ```bash # Switch to main branch $ git checkout main # Perform cherry-pick $ git cherry-pick f ``` -------------------------------- ### Get Ginkgo Help Information Source: https://github.com/openimsdk/open-im-server/blob/main/test/e2e/README.md Displays help information for the Ginkgo test runner, useful for understanding available flags and options. ```bash ginkgo --help --focus value If set, ginkgo will only run specs that match this regular expression. Can be specified multiple times, values are ORed. ``` -------------------------------- ### Go Import Alias Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Use import aliases when package names conflict or do not match the last directory name in the import path. ```go // bad "github.com/dgrijalva/jwt-go/v4" //good jwt "github.com/dgrijalva/jwt-go/v4" ``` -------------------------------- ### OpenIM Release Script Help Information Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/release.md Display the help message for the OpenIM release script to understand available options for environment setup, prerequisite verification, building, packaging, uploading, and GitHub release. ```bash $ ./scripts/release.sh --help Usage: release.sh [options] Options: -h, --help Display this help message -se, --setup-env Execute environment setup -vp, --verify-prereqs Execute prerequisite verification -bc, --build-command Execute build command -bi, --build-image Execute build image (default is not executed) -pt, --package-tarballs Execute tarball packaging -ut, --upload-tarballs Execute tarball upload -gr, --github-release Execute GitHub release -gc, --generate-changelog Execute changelog generation ``` -------------------------------- ### Example: WrapMsg with Message and Key-Value Pairs Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Illustrates using WrapMsg to add both a message string and structured key-value data to an error, providing rich context. ```go // "github.com/openimsdk/tools/errs" err := errors.New("original error") wrappedErr := errs.WrapMsg(err, "problem occurred", "code", 404, "url", "webhook://example.com") // wrappedErr will contain the original error, call stack, and "problem occurred code=404, url=http://example.com" ``` -------------------------------- ### Go Commenting: Package Annotation Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Shows the required format for package-level comments. It should start with `// Package ` followed by the package description. ```go // Package genericclioptions contains flags which can be added to you command, bound, completed, and produce // useful helper functions. package genericclioptions ``` -------------------------------- ### Check OpenIM Chat Processes Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Verify that the required four processes for openim-chat have started successfully. ```bash make check ``` -------------------------------- ### Interactive Rebase Commit List Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/github-workflow.md Example of the interactive rebase editor interface, showing available commands for commit manipulation. ```bash pick 2ebe926 Original commit pick 31f33e9 Address feedback pick b0315fe Second unit of work # Rebase 7c34fc9..b0315ff onto 7c34fc9 (3 commands) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message ... ``` -------------------------------- ### Go Commenting: Variable/Constant Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Demonstrates how to comment exported variables and constants. Each should have a descriptive comment following the `// name description.` format. For blocks, a general description can precede detailed line comments. ```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 ) ``` -------------------------------- ### Print Startup Information in Go Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Log key entry parameters and process information at program startup for better understanding of the initial state and configuration. ```go package main import ( "fmt" "os" ) func main() { fmt.Println("Program startup, version: 1.0.0") fmt.Printf("Connecting to database: %s\n", os.Getenv("DATABASE_URL")) } ``` -------------------------------- ### Example: WrapMsg with No Additional Information Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Demonstrates using WrapMsg to add only the call stack to an original error when no message or key-value pairs are provided. ```go // "github.com/openimsdk/tools/errs" err := errors.New("original error") wrappedErr := errs.WrapMsg(err, "") // wrappedErr will contain the original error and its call stack ``` -------------------------------- ### Setup SSH Key Copy Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md Copies SSH keys to remote hosts. Requires a file with host IPs and credentials to be provided. ```bash #1. Write IPs in a file, one IP per line. Let's name it hosts-file. #2. Modify the default username and password in the script. hosts-file-path="path/to/your/hosts/file" openim:util::setup_ssh_key_copy "$hosts-file-path" "root" "123" ``` -------------------------------- ### Display Help Info for Image Build Source: https://github.com/openimsdk/open-im-server/blob/main/build/README.md Run this command to see the available help information for building images. ```bash $ make image.help ``` -------------------------------- ### Create and Use CodeError Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Example of creating a CodeError with a specific code and message, adding details, and then type asserting to access its methods. ```go package main import ( "fmt" "github.com/openimsdk/tools/errs" ) func main() { err := errs.New(404, "Resource not found") err = err.WithDetail(" More details") if e, ok := err.(errs.CodeError); ok { fmt.Println(e.Code(), e.Msg(), e.Detail()) } } ``` -------------------------------- ### Require jq Installation Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md Checks if the `jq` command-line JSON processor is installed. If not, it prompts the user to install it. ```bash openim::util::require-jq ``` -------------------------------- ### Example: WrapMsg with Key-Value Pairs Only Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Demonstrates using WrapMsg to attach key-value pairs to an error when no primary message text is needed, useful for adding specific context. ```go // "github.com/openimsdk/tools/errs" err := errors.New("original error") wrappedErr := errs.WrapMsg(err, "", "user", "john_doe", "action", "login") // wrappedErr will contain the original error, call stack, and "user=john_doe, action=login" ``` -------------------------------- ### Prepare and Run test.sh Script Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Navigate to the script directory, make the test.sh script executable, and then run the entire test suite. ```bash cd ./scripts/install/ chmod +x test.sh ``` -------------------------------- ### Specify OpenIM Configuration Path via Command-line Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md Use the `-c` or `--config_folder_path` argument to set the directory for OpenIM's configuration files when starting the server. ```bash _output/bin/platforms/linux/amd64/openim-api --config_folder_path="/your/config/folder/path" ``` -------------------------------- ### unused: Detect unused functions Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Shows an example of an unused function and how to either implement its logic or ensure it is called. Unused code can lead to confusion and bloat. ```go package main func helper() {} func main() {} ``` ```go package main // If the helper function is indeed needed, ensure it's used properly. func helper() { // Implement the function's functionality or ensure it's called elsewhere } func main() { helper() } ``` -------------------------------- ### Struct Initialization in Go Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Demonstrates multi-line struct initialization with and without field names. ```go type user struct { Id int64 name string } u1 := user{100, "Colin"} u2 := user{ Id: 200, Name: "Lex", } ``` -------------------------------- ### Go Variable/Constant Comment Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md Shows how to comment exported variables and constants in Go. For individual items, use '// variable name description.'. For blocks, provide a general description followed by specific comments. ```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 ) ``` -------------------------------- ### Declare and Initialize Structs in Go Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Demonstrates the multi-line format for declaring and initializing a struct in Go. ```go type User struct{ Username string Email string } user := User{ Username: "belm", Email: "nosbelm@qq.com", } ``` -------------------------------- ### Clone and Initialize OpenIM Chat from Source Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Clone the openim-chat repository and initialize configuration files using make. ```bash git clone https://github.com/openimsdk/chat cd chat make init # Generates configuration files ``` -------------------------------- ### Consume Messages from Kafka Topic Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/kafka.md Use this command to consume messages from a Kafka topic. The `--from-beginning` flag allows starting consumption from the earliest message in the topic. ```bash kafkactl consume your_topic_name --from-beginning ``` -------------------------------- ### Copy Systemd Unit Templates to Systemd Configuration Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Install the generated systemd unit template files into the systemd configuration directory, making them available for service management. Requires root privileges. ```bash for service in "${services[@]}" do sudo cp $service.service.template /etc/systemd/system/$service.service done ... ``` -------------------------------- ### Create New Extension and Update Workspace Source: https://github.com/openimsdk/open-im-server/blob/main/tools/README.md Use these commands to create a new extension directory, initialize a Go module, and update the Go workspace configuration. Remember to replace '' with your desired extension name. ```bash # edit the CRD_NAME and CRD_GROUP to your own export OPENIM_TOOLS_NAME= # copy and paste to create a new CRD and Controller mkdir tools/${OPENIM_TOOLS_NAME} cd tools/${OPENIM_TOOLS_NAME} go mod init github.com/openimsdk/open-im-server/tools/${OPENIM_TOOLS_NAME} go mod tidy go work use -r . cd ../.. ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Installs the Homebrew package manager, essential for managing software on macOS. ```shell /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### View All Resources Source: https://github.com/openimsdk/open-im-server/blob/main/deployments/Readme.md This command provides a comprehensive overview of all resources within the current namespace. ```bash kubectl get all ``` -------------------------------- ### Install GNU Utils on macOS Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/development.md Install core GNU utilities required for shell scripts on macOS. Ensure these are available before running build or test scripts. ```sh brew install coreutils findutils gawk gnu-sed gnu-tar grep make ``` -------------------------------- ### Log Task Processing Start and End Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/logging.md Log the start and completion of a task to monitor its execution flow. Ensure logs include relevant identifiers like taskID. ```go // Log the start of task processing log.Printf("Starting task processing: %s", taskID) // Suppose this is where the task is processed // Log after the task is completed log.Printf("Task processing completed: %s", taskID) ``` ```go func main() { // Example task ID taskID := "task123" processTask(taskID) } ``` -------------------------------- ### Go ReadWriter Interface Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Example of a Go interface named ReadWriter, which groups Read and Write methods. Interfaces with two functions are named after their function names. ```go // ReadWriter is the interface that groups the basic Read and Write methods. type ReadWriter interface { reader Writer } ``` -------------------------------- ### Initialize AlertManager Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/prometheus-grafana.md Run the `make init` command after setting environment variables to initialize AlertManager with the specified configuration. ```bash make init ``` -------------------------------- ### Go Seeker Interface Example Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Example of a Go interface named Seeker, which defines a Seek method. Interface names for more than three functions should follow structure naming rules. ```go // Seeking to an offset before the start of the file is an error. // Seeking to any positive offset is legal, but the behavior of subsequent // I/O operations on the underlying object are implementation-dependent. type Seeker interface { Seek(offset int64, whence int) (int64, error) } ``` -------------------------------- ### Generate Test Cases Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Prepare the environment by setting the test template and then generate test cases for a specific function. Uses the 'testify' template. ```bash export GOTESTS_TEMPLATE=testify gotests -i -w -only keyFunc . ``` -------------------------------- ### Create OpenIM Data Directories Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Set up the necessary directory structure for OpenIM data, including directories for API and crontask services. ```bash mkdir -p ${OPENIM_DATA_DIR}/{openim-api,openim-crontask} ``` -------------------------------- ### Get Blacklist API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Retrieves the blacklist for a test user. ```APIDOC ## openim::test::get_black_list ### Description Retrieves the blacklist for a test user. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Get CPU Information Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md Retrieves and displays information about the system's CPU. ```bash openim::util::gencpu ``` -------------------------------- ### Makefile Help Command Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/cicd-actions.md Displays available targets and options for the Makefile. Use this to understand the various build and utility commands. ```bash root@PS2023EVRHNCXG:~/workspaces/openim/Open-IM-Server# make help ๐Ÿ˜Š Usage: make ... Targets: all Run tidy, gen, add-copyright, format, lint, cover, build ๐Ÿš€ build Build binaries by default ๐Ÿ› ๏ธ multiarch Build binaries for multiple platforms. See option PLATFORMS. ๐ŸŒ tidy tidy go.mod โœจ vendor vendor go.mod ๐Ÿ“ฆ style code style -> fmt,vet,lint ๐Ÿ’… fmt Run go fmt against code. โœจ vet Run go vet against code. โœ… lint Check syntax and styling of go sources. โœ”๏ธ format Gofmt (reformat) package sources (exclude vendor dir if existed). ๐Ÿ”„ test Run unit test. ๐Ÿงช cover Run unit test and get test coverage. ๐Ÿ“Š updates Check for updates to go.mod dependencies ๐Ÿ†• imports task to automatically handle import packages in Go files using goimports tool ๐Ÿ“ฅ clean Remove all files that are created by building. ๐Ÿ—‘๏ธ image Build docker images for host arch. ๐Ÿณ image.multiarch Build docker images for multiple platforms. See option PLATFORMS. ๐ŸŒ๐Ÿณ push Build docker images for host arch and push images to registry. ๐Ÿ“ค๐Ÿณ push.multiarch Build docker images for multiple platforms and push images to registry. ๐ŸŒ๐Ÿ“ค๐Ÿณ tools Install dependent tools. ๐Ÿงฐ gen Generate all necessary files. ๐Ÿงฉ swagger Generate swagger document. ๐Ÿ“– serve-swagger Serve swagger spec and docs. ๐Ÿš€๐Ÿ“š verify-copyright Verify the license headers for all files. โœ… add-copyright Add copyright ensure source code files have license headers. ๐Ÿ“„ release release the project ๐ŸŽ‰ help Show this help info. โ„น๏ธ help-all Show all help details info. โ„น๏ธ๐Ÿ“š Options: DEBUG Whether or not to generate debug symbols. Default is 0. โ“ BINS Binaries to build. Default is all binaries under cmd. ๐Ÿ› ๏ธ This option is available when using: make {build}(.multiarch) ๐Ÿงฐ Example: make build BINS="openim-api openim_cms_api". PLATFORMS Platform to build for. Default is linux_arm64 and linux_amd64. ๐ŸŒ This option is available when using: make {build}.multiarch ๐ŸŒ Example: make multiarch PLATFORMS="linux_s390x linux_mips64 linux_mips64le darwin_amd64 windows_amd64 linux_amd64 linux_arm64". V Set to 1 enable verbose build. Default is 0. ๐Ÿ“ ``` -------------------------------- ### Clone and Initialize OpenIM Server Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Clones the OpenIM server repository and initializes configuration files. Requires setting OPENIM_IP if on a cloud server. ```shell git clone https://github.com/openimsdk/open-im-server cd open-im-server export OPENIM_IP="Your IP" # If it's a cloud server, setting might not be needed make init # Generates configuration files ``` -------------------------------- ### Get Relative Paths Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md Returns paths that are relative to the current script's location. ```bash openim::util::run::relative ``` -------------------------------- ### Go Struct Declaration and Initialization Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Demonstrates multi-line declaration and initialization for Go structs. Ensure struct names are nouns and avoid meaningless names like Data or Info. ```go // User multi-line declaration type User struct { name string Email string } // multi-line initialization u := User{ UserName: "belm", Email: "nosbelm@qq.com", } ``` -------------------------------- ### Verify Kafka Container Status Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/kafka.md Check if the Kafka container is running after starting it with Docker Compose. ```bash docker ps | grep kafka ``` -------------------------------- ### Get Group Members Information API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Obtains detailed information for members of a specified group. ```APIDOC ## openim::test::get_group_members_info ### Description Obtains detailed information for members of a specified group. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Get Public IP Address Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/util-scripts.md Retrieves the public IP address of the machine from an external service. ```bash openim::util::get-public-ip ``` -------------------------------- ### Get Group Information API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Retrieves information for specified groups to validate group query functionality. ```APIDOC ## openim::test::get_groups_info ### Description Retrieves information for specified groups to validate group query functionality. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Check for Failed Services with systemctl Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Quickly identify any services that have encountered errors and failed to start or run correctly. ```bash systemctl --failed ``` -------------------------------- ### Release Script Main Logic Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/release.md This script outlines the main steps for releasing the OpenIM server. It includes setup, verification, building, packaging, and uploading steps. Some operations like building images, GitHub releases, and changelog generation are commented out and can be enabled as needed. ```bash openim::golang::setup_env openim::build::verify_prereqs openim::release::verify_prereqs #openim::build::build_image openim::build::build_command openim::release::package_tarballs openim::release::upload_tarballs git push origin ${VERSION} #openim::release::github_release #openim::release::generate_changelog ``` -------------------------------- ### Start Interactive Rebase Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/github-workflow.md Initiate an interactive rebase to modify commit history, specifying the number of commits to include. ```bash git rebase -i HEAD~3 ``` -------------------------------- ### Error Variable Naming Convention in Go Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code1.md Error variables should be named using the `ErrFoo` convention, for example, `ErrFormat`. ```go var ErrFormat = errors. New("unknown format") ``` -------------------------------- ### Default Behavior of Release Script Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/release.md Illustrates the default behavior of the release script when no options are provided, enabling all operations except for building the image. ```bash # If no options are provided, enable all operations by default if [ "$#" -eq 0 ]; then perform_setup_env=true perform_verify_prereqs=true perform_build_command=true perform_package_tarballs=true perform_upload_tarballs=true perform_github_release=true perform_generate_changelog=true # TODO: Defaultly not enable build_image # perform_build_image=true fi ``` -------------------------------- ### Basic Protoc Command Structure Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/protoc-tools.md This is the general command structure for using the protoc tool. Specify options and the proto files you want to process. ```bash ./protoc [OPTION] PROTO_FILES ``` -------------------------------- ### Get Group Member List API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Retrieves a list of members for a given group to ensure member listing is functional. ```APIDOC ## openim::test::get_group_member_list ### Description Retrieves a list of members for a given group to ensure member listing is functional. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Navigate to Parent Directory Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/mac-developer-deployment-guide.md Navigate to the parent directory before proceeding with the deployment steps. ```bash cd .. ``` -------------------------------- ### Execute End-to-End (E2E) Tests Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Simulate real-user scenarios from start to finish to ensure the application performs as expected in real-world situations. ```bash make test-e2e ``` -------------------------------- ### Create a New Kafka Topic using kafkactl Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/kafka.md Create a new topic with specified partitions and replication factor using the `kafkactl` tool. ```bash kafkactl create topic your_topic_name --partitions 1 --replication-factor 1 ``` -------------------------------- ### Get Received Group Application List API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Retrieves the list of group applications received by a user to validate application management. ```APIDOC ## openim::test::get_recv_group_applicationList ### Description Retrieves the list of group applications received by a user to validate application management. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Get Joined Group List API Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/test.md Retrieves a list of groups that a user has joined to validate user's group memberships. ```APIDOC ## openim::test::get_joined_group_list ### Description Retrieves a list of groups that a user has joined to validate user's group memberships. ### Method (Not specified, assumed to be a function call) ### Endpoint (Not specified) ### Parameters (Not specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Release Process for OpenIM v3.2.0 Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md Outlines the step-by-step process for publishing a new official release, including alpha, release candidate, and final tags, along with handling urgent bug fixes post-release. ```text Publishing v3.2.0: A Step-by-Step Guide (1) Create the tag v3.2.0-alpha.0 from the main branch. (2) Bugs are fixed on the main branch. Once the bugs are resolved, tag the main branch as v3.2.0-rc.0. (3) After further testing, if v3.2.0-rc.0 is deemed stable, create a branch named release-v3.2 from the tag v3.2.0-rc.0. (4) From the release-v3.2 branch, create the tag v3.2.0. At this point, the official release of v3.2.0 is complete. After the release of v3.2.0, if urgent bugs are discovered, fix them on the release-v3.2 branch. Then, submit two pull requests (PRs) to both the main and release-v3.2 branches. Tag the release-v3.2 branch as v3.2.1. ``` -------------------------------- ### Release Verification Targets Makefile Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/release.md Specifies targets for verifying and installing necessary tools for the release process, such as git-chglog, github-release, coscmd, and coscli. ```makefile ## release.verify: Check if a tool is installed and install it .PHONY: release.verify release.verify: tools.verify.git-chglog tools.verify.github-release tools.verify.coscmd tools.verify.coscli ``` -------------------------------- ### Check OpenIM Service Status Source: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/install-openim-linux-system.md Verify if all OpenIM services are running correctly after installation using the systemctl status command for the main target. ```bash systemctl status openim.target ```