mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-04 03:12:19 +08:00
feat: set openim lint
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
1bb1292460
commit
668b73c0d7
@ -1,15 +0,0 @@
|
|||||||
# Version logging for OpenIM
|
|
||||||
|
|
||||||
<!-- BEGIN MUNGE: GENERATED_TOC -->
|
|
||||||
|
|
||||||
<!-- END MUNGE: GENERATED_TOC -->
|
|
||||||
|
|
||||||
<a name="unreleased"></a>
|
|
||||||
## [Unreleased]
|
|
||||||
|
|
||||||
|
|
||||||
<a name="v3.5.0+5.950e970"></a>
|
|
||||||
## [v3.5.0+5.950e970] - 2024-01-12
|
|
||||||
|
|
||||||
[Unreleased]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+5.950e970...HEAD
|
|
||||||
[v3.5.0+5.950e970]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+2.e0bd54f...v3.5.0+5.950e970
|
|
||||||
@ -129,8 +129,8 @@ function openim::release::upload_tarballs() {
|
|||||||
${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/${file##*/}"
|
${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/${file##*/}"
|
||||||
${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/latest/${file##*/}"
|
${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/latest/${file##*/}"
|
||||||
else
|
else
|
||||||
${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/"
|
coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/"
|
||||||
${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/"
|
coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -641,7 +641,6 @@ function openim::release::github_release() {
|
|||||||
--user ${OPENIM_GITHUB_ORG} \
|
--user ${OPENIM_GITHUB_ORG} \
|
||||||
--repo ${OPENIM_GITHUB_REPO} \
|
--repo ${OPENIM_GITHUB_REPO} \
|
||||||
--tag ${OPENIM_GIT_VERSION} \
|
--tag ${OPENIM_GIT_VERSION} \
|
||||||
--label "openim-${OPENIM_GIT_VERSION}" \
|
|
||||||
--name "${filename}" \
|
--name "${filename}" \
|
||||||
--file "${file}"
|
--file "${file}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -146,7 +146,7 @@ install.github-release:
|
|||||||
# amd64
|
# amd64
|
||||||
.PHONY: install.coscli
|
.PHONY: install.coscli
|
||||||
install.coscli:
|
install.coscli:
|
||||||
@wget -q https://ghproxy.com/https://github.com/tencentyun/coscli/releases/download/v0.13.0-beta/coscli-linux -O ${TOOLS_DIR}/coscli
|
@wget -q https://github.com/tencentyun/coscli/releases/download/v0.19.0-beta/coscli-linux -O ${TOOLS_DIR}/coscli
|
||||||
@chmod +x ${TOOLS_DIR}/coscli
|
@chmod +x ${TOOLS_DIR}/coscli
|
||||||
|
|
||||||
## install.coscmd: Install coscmd, used to upload files to cos
|
## install.coscmd: Install coscmd, used to upload files to cos
|
||||||
|
|||||||
@ -33,8 +33,8 @@ import (
|
|||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -43,9 +43,12 @@ const (
|
|||||||
// defaultCfgPath is the default path of the configuration file.
|
// defaultCfgPath is the default path of the configuration file.
|
||||||
defaultCfgPath = "../../../../../config/config.yaml"
|
defaultCfgPath = "../../../../../config/config.yaml"
|
||||||
minioHealthCheckDuration = 1
|
minioHealthCheckDuration = 1
|
||||||
maxRetry = 100
|
maxRetry = 10
|
||||||
componentStartErrCode = 6000
|
componentStartErrCode = 6000
|
||||||
configErrCode = 6001
|
configErrCode = 6001
|
||||||
|
mongoConnTimeout = 10 * time.Second
|
||||||
|
|
||||||
|
redisConnTimeout = 5 * time.Second // Connection timeout for Redis
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -56,7 +59,6 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file")
|
cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file")
|
||||||
|
|
||||||
ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr")
|
ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr")
|
||||||
ErrConfig = errs.NewCodeError(configErrCode, "Config file is incorrect")
|
ErrConfig = errs.NewCodeError(configErrCode, "Config file is incorrect")
|
||||||
)
|
)
|
||||||
@ -141,22 +143,38 @@ func getEnv(key, fallback string) string {
|
|||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkMongo checks the MongoDB connection
|
// checkMongo checks the MongoDB connection with retries and timeout
|
||||||
func checkMongo() (string, error) {
|
func checkMongo() (string, error) {
|
||||||
// Use environment variables or fallback to config
|
|
||||||
uri := getEnv("MONGO_URI", buildMongoURI())
|
uri := getEnv("MONGO_URI", buildMongoURI())
|
||||||
|
var client *mongo.Client
|
||||||
|
var err error
|
||||||
|
|
||||||
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
for attempt := 0; attempt <= maxRetry; attempt++ {
|
||||||
str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",")
|
ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
client, err = mongo.Connect(ctx, options.Client().ApplyURI(uri))
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if attempt < maxRetry {
|
||||||
|
fmt.Printf("Failed to connect to MongoDB, retrying: %s\n", err)
|
||||||
|
time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff
|
||||||
|
}
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errs.Wrap(errStr(err, str))
|
return "", err // Wrap or handle the error as needed
|
||||||
}
|
}
|
||||||
defer client.Disconnect(context.TODO())
|
defer client.Disconnect(context.Background())
|
||||||
|
|
||||||
if err = client.Ping(context.TODO(), nil); err != nil {
|
ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout)
|
||||||
return "", errs.Wrap(errStr(err, str))
|
defer cancel()
|
||||||
|
|
||||||
|
if err = client.Ping(ctx, nil); err != nil {
|
||||||
|
return "", err // Wrap or handle the error as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str := "The addr is: " + strings.Join(config.Config.Mongo.Address, ",")
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,8 +240,8 @@ func checkMinio() (string, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if minioClient.IsOffline() {
|
if minioClient.IsOffline() {
|
||||||
// str := fmt.Sprintf("Minio server is offline;%s", str)
|
str := fmt.Sprintf("Minio server is offline;%s", str)
|
||||||
// return "", ErrComponentStart.Wrap(str)
|
return "", ErrComponentStart.Wrap(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for localhost in API URL and Minio SignEndpoint
|
// Check for localhost in API URL and Minio SignEndpoint
|
||||||
@ -234,9 +252,8 @@ func checkMinio() (string, error) {
|
|||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkRedis checks the Redis connection
|
// checkRedis checks the Redis connection with retries and timeout
|
||||||
func checkRedis() (string, error) {
|
func checkRedis() (string, error) {
|
||||||
// Prioritize environment variables
|
|
||||||
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
|
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
|
||||||
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
|
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
|
||||||
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
|
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
|
||||||
@ -245,6 +262,9 @@ func checkRedis() (string, error) {
|
|||||||
redisAddresses := strings.Split(address, ",")
|
redisAddresses := strings.Split(address, ",")
|
||||||
|
|
||||||
var redisClient redis.UniversalClient
|
var redisClient redis.UniversalClient
|
||||||
|
var err error
|
||||||
|
|
||||||
|
for attempt := 0; attempt <= maxRetry; attempt++ {
|
||||||
if len(redisAddresses) > 1 {
|
if len(redisAddresses) > 1 {
|
||||||
// Use cluster client for multiple addresses
|
// Use cluster client for multiple addresses
|
||||||
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
||||||
@ -260,15 +280,26 @@ func checkRedis() (string, error) {
|
|||||||
Password: password,
|
Password: password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
defer redisClient.Close()
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), redisConnTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
// Ping Redis to check connectivity
|
// Ping Redis to check connectivity
|
||||||
_, err := redisClient.Ping(context.Background()).Result()
|
_, err = redisClient.Ping(ctx).Result()
|
||||||
str := "the addr is:" + strings.Join(redisAddresses, ",")
|
if err == nil {
|
||||||
if err != nil {
|
break
|
||||||
return "", errs.Wrap(errStr(err, str))
|
|
||||||
}
|
}
|
||||||
|
if attempt < maxRetry {
|
||||||
|
fmt.Printf("Failed to connect to Redis, retrying: %s\n", err)
|
||||||
|
time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err // Wrap or handle the error as needed
|
||||||
|
}
|
||||||
|
defer redisClient.Close()
|
||||||
|
|
||||||
|
str := "The addr is: " + strings.Join(redisAddresses, ",")
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user