mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 19:02:31 +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}/latest/${file##*/}"
|
||||
else
|
||||
${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/"
|
||||
${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/"
|
||||
coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/"
|
||||
coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -641,7 +641,6 @@ function openim::release::github_release() {
|
||||
--user ${OPENIM_GITHUB_ORG} \
|
||||
--repo ${OPENIM_GITHUB_REPO} \
|
||||
--tag ${OPENIM_GIT_VERSION} \
|
||||
--label "openim-${OPENIM_GIT_VERSION}" \
|
||||
--name "${filename}" \
|
||||
--file "${file}"
|
||||
fi
|
||||
|
||||
@ -146,7 +146,7 @@ install.github-release:
|
||||
# amd64
|
||||
.PHONY: 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
|
||||
|
||||
## install.coscmd: Install coscmd, used to upload files to cos
|
||||
|
||||
@ -33,19 +33,22 @@ import (
|
||||
|
||||
"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/redis/go-redis/v9"
|
||||
"gopkg.in/yaml.v3"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
// defaultCfgPath is the default path of the configuration file.
|
||||
defaultCfgPath = "../../../../../config/config.yaml"
|
||||
minioHealthCheckDuration = 1
|
||||
maxRetry = 100
|
||||
maxRetry = 10
|
||||
componentStartErrCode = 6000
|
||||
configErrCode = 6001
|
||||
mongoConnTimeout = 10 * time.Second
|
||||
|
||||
redisConnTimeout = 5 * time.Second // Connection timeout for Redis
|
||||
)
|
||||
|
||||
const (
|
||||
@ -55,8 +58,7 @@ const (
|
||||
)
|
||||
|
||||
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")
|
||||
ErrConfig = errs.NewCodeError(configErrCode, "Config file is incorrect")
|
||||
)
|
||||
@ -141,22 +143,38 @@ func getEnv(key, fallback string) string {
|
||||
return fallback
|
||||
}
|
||||
|
||||
// checkMongo checks the MongoDB connection
|
||||
// checkMongo checks the MongoDB connection with retries and timeout
|
||||
func checkMongo() (string, error) {
|
||||
// Use environment variables or fallback to config
|
||||
uri := getEnv("MONGO_URI", buildMongoURI())
|
||||
var client *mongo.Client
|
||||
var err error
|
||||
|
||||
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",")
|
||||
for attempt := 0; attempt <= maxRetry; attempt++ {
|
||||
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 {
|
||||
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 {
|
||||
return "", errs.Wrap(errStr(err, str))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout)
|
||||
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
|
||||
}
|
||||
|
||||
@ -222,8 +240,8 @@ func checkMinio() (string, error) {
|
||||
defer cancel()
|
||||
|
||||
if minioClient.IsOffline() {
|
||||
// str := fmt.Sprintf("Minio server is offline;%s", str)
|
||||
// return "", ErrComponentStart.Wrap(str)
|
||||
str := fmt.Sprintf("Minio server is offline;%s", str)
|
||||
return "", ErrComponentStart.Wrap(str)
|
||||
}
|
||||
|
||||
// Check for localhost in API URL and Minio SignEndpoint
|
||||
@ -234,9 +252,8 @@ func checkMinio() (string, error) {
|
||||
return str, nil
|
||||
}
|
||||
|
||||
// checkRedis checks the Redis connection
|
||||
// checkRedis checks the Redis connection with retries and timeout
|
||||
func checkRedis() (string, error) {
|
||||
// Prioritize environment variables
|
||||
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
|
||||
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
|
||||
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
|
||||
@ -245,30 +262,44 @@ func checkRedis() (string, error) {
|
||||
redisAddresses := strings.Split(address, ",")
|
||||
|
||||
var redisClient redis.UniversalClient
|
||||
if len(redisAddresses) > 1 {
|
||||
// Use cluster client for multiple addresses
|
||||
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
||||
Addrs: redisAddresses,
|
||||
Username: username,
|
||||
Password: password,
|
||||
})
|
||||
} else {
|
||||
// Use regular client for single address
|
||||
redisClient = redis.NewClient(&redis.Options{
|
||||
Addr: redisAddresses[0],
|
||||
Username: username,
|
||||
Password: password,
|
||||
})
|
||||
var err error
|
||||
|
||||
for attempt := 0; attempt <= maxRetry; attempt++ {
|
||||
if len(redisAddresses) > 1 {
|
||||
// Use cluster client for multiple addresses
|
||||
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
||||
Addrs: redisAddresses,
|
||||
Username: username,
|
||||
Password: password,
|
||||
})
|
||||
} else {
|
||||
// Use regular client for single address
|
||||
redisClient = redis.NewClient(&redis.Options{
|
||||
Addr: redisAddresses[0],
|
||||
Username: username,
|
||||
Password: password,
|
||||
})
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), redisConnTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Ping Redis to check connectivity
|
||||
_, err = redisClient.Ping(ctx).Result()
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
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()
|
||||
|
||||
// Ping Redis to check connectivity
|
||||
_, err := redisClient.Ping(context.Background()).Result()
|
||||
str := "the addr is:" + strings.Join(redisAddresses, ",")
|
||||
if err != nil {
|
||||
return "", errs.Wrap(errStr(err, str))
|
||||
}
|
||||
|
||||
str := "The addr is: " + strings.Join(redisAddresses, ",")
|
||||
return str, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user