From 8f89223a161a9e2bbdde8008c24a23f0d537b1fd Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:03:00 +0800 Subject: [PATCH] Add comments (#516) * refactor dockerFile * Add comments to the configuration file * feat: chat admin config (#508) * Add comments to the configuration file * Remove comments --------- Co-authored-by: chao <48119764+withchao@users.noreply.github.com> --- Dockerfile | 2 +- config/chat-api-admin.yml | 2 ++ config/chat-api-chat.yml | 2 ++ config/chat-rpc-admin.yml | 3 ++ config/chat-rpc-chat.yml | 3 ++ config/log.yml | 7 ++++- config/mongodb.yml | 9 +++++- config/redis.yml | 9 +++++- config/share.yml | 5 +++- config/zookeeper.yml | 5 +++- go.mod | 2 +- go.sum | 4 +-- pkg/common/db/model/admin/ip_forbidden.go | 1 - pkg/common/db/table/admin/admin.go | 2 +- pkg/common/db/table/admin/client_config.go | 2 +- .../db/table/admin/forbidden_account.go | 2 +- .../db/table/admin/invitation_register.go | 1 - pkg/common/db/table/admin/ip_forbidden.go | 1 - .../db/table/admin/limit_user_login_ip.go | 1 - .../db/table/admin/register_add_friend.go | 1 - .../db/table/admin/register_add_group.go | 1 - pkg/common/db/table/chat/account.go | 1 - pkg/common/db/table/chat/attribute.go | 1 - pkg/common/db/table/chat/register.go | 1 - pkg/common/db/table/chat/user_login_record.go | 1 - pkg/common/xlsx/main.go | 8 +++--- pkg/common/xlsx/utils.go | 13 ++++----- pkg/eerrs/predefine.go | 28 +++++++++---------- pkg/email/mail.go | 2 +- 29 files changed, 72 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52e18410..ed17db92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,7 +43,7 @@ COPY --from=builder $SERVER_DIR/start-config.yml $SERVER_DIR/ COPY --from=builder $SERVER_DIR/go.mod $SERVER_DIR/ COPY --from=builder $SERVER_DIR/go.sum $SERVER_DIR/ -RUN go get github.com/openimsdk/gomake@v0.0.9-alpha.3 +RUN go get github.com/openimsdk/gomake@v0.0.9 # Set the command to run when the container starts ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"] diff --git a/config/chat-api-admin.yml b/config/chat-api-admin.yml index dfc773c9..e03ee18c 100644 --- a/config/chat-api-admin.yml +++ b/config/chat-api-admin.yml @@ -1,4 +1,6 @@ api: + # Listening IP; 0.0.0.0 means both internal and external IPs are listened to, default is recommended listenIP: 0.0.0.0 + # Listening ports; if multiple are configured, multiple instances will be launched ports: [ 10009 ] diff --git a/config/chat-api-chat.yml b/config/chat-api-chat.yml index 4c86fed5..c563647d 100644 --- a/config/chat-api-chat.yml +++ b/config/chat-api-chat.yml @@ -1,4 +1,6 @@ api: + # Listening IP; 0.0.0.0 means both internal and external IPs are listened to, default is recommended listenIP: 0.0.0.0 + # Listening ports; if multiple are configured, multiple instances will be launched ports: [ 10008 ] diff --git a/config/chat-rpc-admin.yml b/config/chat-rpc-admin.yml index fb25d131..7494356f 100644 --- a/config/chat-rpc-admin.yml +++ b/config/chat-rpc-admin.yml @@ -1,6 +1,9 @@ rpc: + # The IP address where this RPC service registers itself; if left blank, it defaults to the internal network IP registerIP: '' + # IP address that the RPC service listens on; setting to 0.0.0.0 listens on both internal and external IPs. If left blank, it automatically uses the internal network IP listenIP: 0.0.0.0 + # List of ports that the RPC service listens on; configuring multiple ports will launch multiple instances. ports: [ 30200 ] tokenPolicy: diff --git a/config/chat-rpc-chat.yml b/config/chat-rpc-chat.yml index 264759c6..d015ad63 100644 --- a/config/chat-rpc-chat.yml +++ b/config/chat-rpc-chat.yml @@ -1,6 +1,9 @@ rpc: + # The IP address where this RPC service registers itself; if left blank, it defaults to the internal network IP registerIP: '' + # IP address that the RPC service listens on; setting to 0.0.0.0 listens on both internal and external IPs. If left blank, it automatically uses the internal network IP listenIP: 0.0.0.0 + # List of ports that the RPC service listens on; configuring multiple ports will launch multiple instances. ports: [ 30300 ] verifyCode: diff --git a/config/log.yml b/config/log.yml index 08139390..44ff3ee7 100644 --- a/config/log.yml +++ b/config/log.yml @@ -1,7 +1,12 @@ +# Log storage path, default is acceptable, change to a full path if modification is needed storageLocation: ../../../../logs/ +# Log rotation period (in hours), default is acceptable rotationTime: 24 +# Number of log files to retain, default is acceptable remainRotationCount: 2 +# Log level settings: 3 for production environment; 6 for more verbose logging in debugging environments remainLogLevel: 6 +# Whether to output to standard output, default is acceptable isStdout: false +# Whether to log in JSON format, default is acceptable isJson: false -withStack: false diff --git a/config/mongodb.yml b/config/mongodb.yml index 12f1f66a..98f5694e 100644 --- a/config/mongodb.yml +++ b/config/mongodb.yml @@ -1,7 +1,14 @@ +# URI for database connection, leave empty if using address and credential settings directly uri: '' +# List of MongoDB server addresses address: [ localhost:37017 ] +# Name of the database database: openim_v3 +# Username for database authentication username: openIM +# Password for database authentication password: openIM123 +# Maximum number of connections in the connection pool maxPoolSize: 100 -maxRetry: 10 \ No newline at end of file +# Maximum number of retry attempts for a failed database connection +maxRetry: 10 diff --git a/config/redis.yml b/config/redis.yml index 26becd88..27361ba9 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -1,7 +1,14 @@ +# List of Redis server addresses address: [ localhost:16379 ] +# Username for Redis authentication (leave blank if not used) username: '' +# Password for Redis authentication password: openIM123 +# Enable or disable pipeline processing enablePipeline: false +# Enable or disable cluster mode clusterMode: false +# Database index to be used db: 0 -maxRetry: 10 \ No newline at end of file +# Maximum number of retry attempts for a failed connection +maxRetry: 10 diff --git a/config/share.yml b/config/share.yml index 2eed7bd7..6b1bab17 100644 --- a/config/share.yml +++ b/config/share.yml @@ -4,11 +4,14 @@ rpcRegisterName: admin: admin openIM: + # OpenIM API address apiURL: http://127.0.0.1:10002 + # OpenIM secret key, must be consistent with OpenIM secret: openIM123 + # OpenIM administrator userID, must be consistent with OpenIM adminUserID: imAdmin chatAdmin: + # Default username and password for the admin - "chatAdmin" -#proxyHeader: "X-Forwarded-For" \ No newline at end of file diff --git a/config/zookeeper.yml b/config/zookeeper.yml index 73c76e79..7b7557c9 100644 --- a/config/zookeeper.yml +++ b/config/zookeeper.yml @@ -1,5 +1,8 @@ +# Database schema name schema: openim +# List of server addresses address: [ localhost:12181 ] +# Username for authentication (leave blank if not used) username: '' +# Password for authentication (leave blank if not used) password: '' - diff --git a/go.mod b/go.mod index c27621cd..f8caab7d 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( require ( github.com/livekit/protocol v1.10.1 github.com/mitchellh/mapstructure v1.5.0 - github.com/openimsdk/gomake v0.0.9-alpha.3 + github.com/openimsdk/gomake v0.0.9 github.com/openimsdk/protocol v0.0.63 github.com/openimsdk/tools v0.0.49-alpha.3 github.com/redis/go-redis/v9 v9.5.1 diff --git a/go.sum b/go.sum index 322597b3..9052f235 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADym github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/openimsdk/gomake v0.0.9-alpha.3 h1:KO3stbmiTksnnx2o2Lh8/FkKXc7qiF4rwPnr01WO7aM= -github.com/openimsdk/gomake v0.0.9-alpha.3/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= +github.com/openimsdk/gomake v0.0.9 h1:ouf25ygN2PMQ68Gfgns/EQRPiLPnp+77SIr68GfE+n4= +github.com/openimsdk/gomake v0.0.9/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= github.com/openimsdk/protocol v0.0.63 h1:9DnweZe9nEYDFa4fGTbC9Cqi0gLUdtBhRo1NRP2X3WQ= github.com/openimsdk/protocol v0.0.63/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8= github.com/openimsdk/tools v0.0.49-alpha.3 h1:mXKU09asKTLjj0yCsfqqMizs3ibl1vLimW7ZYzAMw44= diff --git a/pkg/common/db/model/admin/ip_forbidden.go b/pkg/common/db/model/admin/ip_forbidden.go index 97431e9c..09fd33c2 100644 --- a/pkg/common/db/model/admin/ip_forbidden.go +++ b/pkg/common/db/model/admin/ip_forbidden.go @@ -62,7 +62,6 @@ func (o *IPForbidden) Search(ctx context.Context, keyword string, state int32, p switch state { case constant.LimitNil: - // 不添加额外的过滤条件 case constant.LimitEmpty: filter = bson.M{"limit_register": 0, "limit_login": 0} case constant.LimitOnlyRegisterIP: diff --git a/pkg/common/db/table/admin/admin.go b/pkg/common/db/table/admin/admin.go index 059976b5..4773e276 100644 --- a/pkg/common/db/table/admin/admin.go +++ b/pkg/common/db/table/admin/admin.go @@ -20,7 +20,7 @@ import ( "time" ) -// Admin 后台管理员. +// Admin user type Admin struct { Account string `bson:"account"` Password string `bson:"password"` diff --git a/pkg/common/db/table/admin/client_config.go b/pkg/common/db/table/admin/client_config.go index 93006683..4b941001 100644 --- a/pkg/common/db/table/admin/client_config.go +++ b/pkg/common/db/table/admin/client_config.go @@ -16,7 +16,7 @@ package admin import "context" -// ClientConfig 客户端相关配置项. +// ClientConfig config type ClientConfig struct { Key string `bson:"key"` Value string `bson:"value"` diff --git a/pkg/common/db/table/admin/forbidden_account.go b/pkg/common/db/table/admin/forbidden_account.go index 2e0e5abf..fb324761 100644 --- a/pkg/common/db/table/admin/forbidden_account.go +++ b/pkg/common/db/table/admin/forbidden_account.go @@ -20,7 +20,7 @@ import ( "time" ) -// ForbiddenAccount 封号表. +// ForbiddenAccount table type ForbiddenAccount struct { UserID string `bson:"user_id"` Reason string `bson:"reason"` diff --git a/pkg/common/db/table/admin/invitation_register.go b/pkg/common/db/table/admin/invitation_register.go index 40155f45..4970b4ad 100644 --- a/pkg/common/db/table/admin/invitation_register.go +++ b/pkg/common/db/table/admin/invitation_register.go @@ -20,7 +20,6 @@ import ( "time" ) -// 邀请码被注册使用. type InvitationRegister struct { InvitationCode string `bson:"invitation_code"` UsedByUserID string `bson:"used_by_user_id"` diff --git a/pkg/common/db/table/admin/ip_forbidden.go b/pkg/common/db/table/admin/ip_forbidden.go index 39577a9a..15e299d1 100644 --- a/pkg/common/db/table/admin/ip_forbidden.go +++ b/pkg/common/db/table/admin/ip_forbidden.go @@ -20,7 +20,6 @@ import ( "time" ) -// 禁止ip登录 注册. type IPForbidden struct { IP string `bson:"ip"` LimitRegister bool `bson:"limit_register"` diff --git a/pkg/common/db/table/admin/limit_user_login_ip.go b/pkg/common/db/table/admin/limit_user_login_ip.go index e167f633..b3413f27 100644 --- a/pkg/common/db/table/admin/limit_user_login_ip.go +++ b/pkg/common/db/table/admin/limit_user_login_ip.go @@ -20,7 +20,6 @@ import ( "time" ) -// 限制userID只能在某些ip登录. type LimitUserLoginIP struct { UserID string `bson:"user_id"` IP string `bson:"ip"` diff --git a/pkg/common/db/table/admin/register_add_friend.go b/pkg/common/db/table/admin/register_add_friend.go index bd864805..b0888e74 100644 --- a/pkg/common/db/table/admin/register_add_friend.go +++ b/pkg/common/db/table/admin/register_add_friend.go @@ -20,7 +20,6 @@ import ( "time" ) -// RegisterAddFriend 注册时默认好友. type RegisterAddFriend struct { UserID string `bson:"user_id"` CreateTime time.Time `bson:"create_time"` diff --git a/pkg/common/db/table/admin/register_add_group.go b/pkg/common/db/table/admin/register_add_group.go index 1b7f4d12..ebfd4a01 100644 --- a/pkg/common/db/table/admin/register_add_group.go +++ b/pkg/common/db/table/admin/register_add_group.go @@ -20,7 +20,6 @@ import ( "time" ) -// RegisterAddGroup 注册时默认群组. type RegisterAddGroup struct { GroupID string `bson:"group_id"` CreateTime time.Time `bson:"create_time"` diff --git a/pkg/common/db/table/chat/account.go b/pkg/common/db/table/chat/account.go index 414a0326..dba6d68d 100644 --- a/pkg/common/db/table/chat/account.go +++ b/pkg/common/db/table/chat/account.go @@ -19,7 +19,6 @@ import ( "time" ) -// Account 账号密码表. type Account struct { UserID string `bson:"user_id"` Password string `bson:"password"` diff --git a/pkg/common/db/table/chat/attribute.go b/pkg/common/db/table/chat/attribute.go index 1b7ba29b..57f62f7e 100644 --- a/pkg/common/db/table/chat/attribute.go +++ b/pkg/common/db/table/chat/attribute.go @@ -20,7 +20,6 @@ import ( "time" ) -// Attribute 用户属性表. type Attribute struct { UserID string `bson:"user_id"` Account string `bson:"account"` diff --git a/pkg/common/db/table/chat/register.go b/pkg/common/db/table/chat/register.go index 72d51436..647037ef 100644 --- a/pkg/common/db/table/chat/register.go +++ b/pkg/common/db/table/chat/register.go @@ -19,7 +19,6 @@ import ( "time" ) -// Register 注册信息表. type Register struct { UserID string `bson:"user_id"` DeviceID string `bson:"device_id"` diff --git a/pkg/common/db/table/chat/user_login_record.go b/pkg/common/db/table/chat/user_login_record.go index 6c3a8eda..0b2b65aa 100644 --- a/pkg/common/db/table/chat/user_login_record.go +++ b/pkg/common/db/table/chat/user_login_record.go @@ -19,7 +19,6 @@ import ( "time" ) -// 用户登录信息表. type UserLoginRecord struct { UserID string `bson:"user_id"` LoginTime time.Time `bson:"login_time"` diff --git a/pkg/common/xlsx/main.go b/pkg/common/xlsx/main.go index c170bd19..3606d8bc 100644 --- a/pkg/common/xlsx/main.go +++ b/pkg/common/xlsx/main.go @@ -38,7 +38,7 @@ func ParseSheet(file *excelize.File, v interface{}) error { } else if sheetIndex < 0 { return nil } - fieldIndex := make(map[string]int) // 结构体对应的下标 + fieldIndex := make(map[string]int) for i := 0; i < itemType.NumField(); i++ { field := itemType.Field(i) alias := field.Tag.Get("column") @@ -54,8 +54,8 @@ func ParseSheet(file *excelize.File, v interface{}) error { if len(fieldIndex) == 0 { return errors.New("empty column struct") } - sheetIndex := make(map[string]int) // sheet 对应的下标 - for i := 1; ; i++ { // 第一行 + sheetIndex := make(map[string]int) + for i := 1; ; i++ { name, err := file.GetCellValue(sheetName, GetAxis(i, 1)) if err != nil { return err @@ -88,7 +88,7 @@ func ParseSheet(file *excelize.File, v interface{}) error { return err } } - if notEmpty > 0 { // 空行表示结束 + if notEmpty > 0 { putItem(item) } else { break diff --git a/pkg/common/xlsx/utils.go b/pkg/common/xlsx/utils.go index 885bb962..fea67dce 100644 --- a/pkg/common/xlsx/utils.go +++ b/pkg/common/xlsx/utils.go @@ -22,22 +22,21 @@ func Num2AZ(num int) string { var ( str string k int - temp []int //保存转化后每一位数据的值,然后通过索引的方式匹配A-Z + temp []int ) - //用来匹配的字符A-Z slices := []string{"", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} - if num > 26 { //数据大于26需要进行拆分 + if num > 26 { for { - k = num % 26 //从个位开始拆分,如果求余为0,说明末尾为26,也就是Z,如果是转化为26进制数,则末尾是可以为0的,这里必须为A-Z中的一个 + k = num % 26 if k == 0 { temp = append(temp, 26) k = 26 } else { temp = append(temp, k) } - num = (num - k) / 26 //减去num最后一位数的值,因为已经记录在temp中 - if num <= 26 { //小于等于26直接进行匹配,不需要进行数据拆分 + num = (num - k) / 26 + if num <= 26 { temp = append(temp, num) break } @@ -46,7 +45,7 @@ func Num2AZ(num int) string { return slices[num] } for _, value := range temp { - str = slices[value] + str //因为数据切分后存储顺序是反的,所以str要放在后面 + str = slices[value] + str } return str } diff --git a/pkg/eerrs/predefine.go b/pkg/eerrs/predefine.go index 621cba72..6546d53a 100644 --- a/pkg/eerrs/predefine.go +++ b/pkg/eerrs/predefine.go @@ -17,18 +17,18 @@ package eerrs import "github.com/openimsdk/tools/errs" var ( - ErrPassword = errs.NewCodeError(20001, "PasswordError") // 密码错误 - ErrAccountNotFound = errs.NewCodeError(20002, "AccountNotFound") // 账号不存在 - ErrPhoneAlreadyRegister = errs.NewCodeError(20003, "PhoneAlreadyRegister") // 手机号已经注册 - ErrAccountAlreadyRegister = errs.NewCodeError(20004, "AccountAlreadyRegister") // 账号已经注册 - ErrVerifyCodeSendFrequently = errs.NewCodeError(20005, "VerifyCodeSendFrequently") // 频繁获取验证码 - ErrVerifyCodeNotMatch = errs.NewCodeError(20006, "VerifyCodeNotMatch") // 验证码错误 - ErrVerifyCodeExpired = errs.NewCodeError(20007, "VerifyCodeExpired") // 验证码过期 - ErrVerifyCodeMaxCount = errs.NewCodeError(20008, "VerifyCodeMaxCount") // 验证码失败次数过多 - ErrVerifyCodeUsed = errs.NewCodeError(20009, "VerifyCodeUsed") // 已经使用 - ErrInvitationCodeUsed = errs.NewCodeError(20010, "InvitationCodeUsed") // 邀请码已经使用 - ErrInvitationNotFound = errs.NewCodeError(20011, "InvitationNotFound") // 邀请码不存在 - ErrForbidden = errs.NewCodeError(20012, "Forbidden") // 限制登录注册 - ErrRefuseFriend = errs.NewCodeError(20013, "RefuseFriend") // 拒绝添加好友 - ErrEmailAlreadyRegister = errs.NewCodeError(20014, "EmailAlreadyRegister") // 邮箱已经注册 + ErrPassword = errs.NewCodeError(20001, "PasswordError") + ErrAccountNotFound = errs.NewCodeError(20002, "AccountNotFound") + ErrPhoneAlreadyRegister = errs.NewCodeError(20003, "PhoneAlreadyRegister") + ErrAccountAlreadyRegister = errs.NewCodeError(20004, "AccountAlreadyRegister") + ErrVerifyCodeSendFrequently = errs.NewCodeError(20005, "VerifyCodeSendFrequently") + ErrVerifyCodeNotMatch = errs.NewCodeError(20006, "VerifyCodeNotMatch") + ErrVerifyCodeExpired = errs.NewCodeError(20007, "VerifyCodeExpired") + ErrVerifyCodeMaxCount = errs.NewCodeError(20008, "VerifyCodeMaxCount") + ErrVerifyCodeUsed = errs.NewCodeError(20009, "VerifyCodeUsed") + ErrInvitationCodeUsed = errs.NewCodeError(20010, "InvitationCodeUsed") + ErrInvitationNotFound = errs.NewCodeError(20011, "InvitationNotFound") + ErrForbidden = errs.NewCodeError(20012, "Forbidden") + ErrRefuseFriend = errs.NewCodeError(20013, "RefuseFriend") + ErrEmailAlreadyRegister = errs.NewCodeError(20014, "EmailAlreadyRegister") ) diff --git a/pkg/email/mail.go b/pkg/email/mail.go index 42194b6c..1c1d2d1d 100644 --- a/pkg/email/mail.go +++ b/pkg/email/mail.go @@ -50,6 +50,6 @@ func (m *mail) SendMail(ctx context.Context, mail string, verifyCode string) err msg.SetHeader(`From`, m.senderMail) msg.SetHeader(`To`, []string{mail}...) msg.SetHeader(`Subject`, m.title) - msg.SetBody(`text/html`, fmt.Sprintf("您的验证码为:%s,该验证码5分钟内有效,请勿泄露于他人。", verifyCode)) + msg.SetBody(`text/html`, fmt.Sprintf("Your verification code is: %s. This code is valid for 5 minutes and should not be shared with others", verifyCode)) return errs.Wrap(m.dail.DialAndSend(msg)) }