Commit 5742f471 authored by hujiebin's avatar hujiebin

feat: go 1.17

parent 1f94239d
......@@ -134,3 +134,8 @@ const (
)
var GROUP_ROLE_VIEW_LIMIT = 10
var GROUP_INTRODUCTION_LENGTH_LIMIT = 500
const ROOM_PASSWORD_LENGTH = 4
const SETTING_CUSTOMIZED = 2
const SETTING_OFFICIAL = 1
......@@ -2,8 +2,14 @@ package group_c
import (
"context"
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"github.com/go-redis/redis/v8"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/group_k"
"hilo-group/domain/model/group_m"
"strings"
"time"
)
......@@ -80,3 +86,56 @@ func ClearGroupConsume(groupId string) error {
key := getGroupConsumeKey(groupId)
return redisCli.RedisClient.Del(context.Background(), key).Err()
}
// 增加编辑用户cd
// 6小时cd
func AddEditGroupCd(model *domain.Model, imGroupId mysql.Str) error {
key := group_k.GetEditGroupCDKey(imGroupId)
return model.Redis.SetEX(model, key, 1, time.Hour*6).Err()
}
// 是否编辑群组cd中
func IsEditGroupCd(model *domain.Model, imGroupId mysql.Str) bool {
key := group_k.GetEditGroupCDKey(imGroupId)
n, err := model.Redis.Exists(model, key).Result()
if err != nil {
model.Log.Errorf("IsEditGroupCd fail:%v", err)
}
return n > 0
}
//
func GetGroupInfoCache(model *domain.Model, imGroupId mysql.Str) (*group_m.GroupInfo, error) {
key := group_k.GetGroupInfoKey(imGroupId)
data, err := model.Redis.Get(model, key).Bytes()
if err != nil {
if err == redis.Nil {
return nil, nil
}
model.Log.Errorf("GetGroupInfo fail,imGroupId:%v,err:%v", imGroupId, err)
return nil, err
}
res := new(group_m.GroupInfo)
err = json.Unmarshal(data, &res)
if err != nil {
model.Log.Errorf("GetGroupInfo fail,imGroupId:%v,err:%v", imGroupId, err)
return nil, err
}
return res, nil
}
//
func SetGroupInfoCache(model *domain.Model, info *group_m.GroupInfo) error {
key := group_k.GetGroupInfoKey(info.ImGroupId)
data, err := json.Marshal(info)
if err != nil {
model.Log.Errorf("SetGroupInfo fail,info:%+v,err:%v", info, err)
return err
}
err = model.Redis.Set(model, key, data, time.Minute*5).Err()
if err != nil {
model.Log.Errorf("SetGroupInfo fail,info:%+v,err:%v", info, err)
return err
}
return nil
}
......@@ -4,6 +4,7 @@ import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/_const/enum/diamond_e"
"hilo-group/myerr"
)
type DiamondAccount struct {
......@@ -48,3 +49,15 @@ type DiamondPinkAccountDetail struct {
AftNum mysql.Num
diamondAccount *DiamondAccount `gorm:"-"`
}
//通过userId获取帐号
func GetDiamondAccountByUserId(model *domain.Model, userId mysql.ID) (*DiamondAccount, error) {
var diamondAccount DiamondAccount
if err := model.Db.WithContext(model).Where(&DiamondAccount{
UserId: userId,
}).First(&diamondAccount).Error; err != nil {
return nil, myerr.WrapErr(err)
}
diamondAccount.Model = model
return &diamondAccount, nil
}
package signal_s
import (
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"github.com/sirupsen/logrus"
"hilo-group/domain/model/group_m"
"runtime/debug"
)
// 发送群信令。入参是内部imGroupId,这里做转换
func SendSignalMsg(model *domain.Model, groupId string, msg group_m.GroupSystemMsg, async bool) {
model.Log.WithField("groupId", groupId)
groupId, err := group_m.ToTxGroupId(model, groupId)
if err != nil {
return
}
buffer, err := json.Marshal(msg)
if err == nil {
str := string(buffer)
model.Log.Infof("SendSignalMsg: %s, async = %v", str, async)
if async {
go func(logger *logrus.Entry) {
defer func() {
if r := recover(); r != nil {
//打印错误堆栈信息
logger.Errorf("SendSignalMsg SYSTEM ACTION PANIC: %v, stack: %v", r, string(debug.Stack()))
}
}()
if err = tencentyun.SendSystemMsg(logger, groupId, []string{}, str); err != nil {
logger.Errorf("SendSignalMsg aync failed for %s, msgId = %d, context:%v, err:%v", groupId, msg.MsgId, str, err)
} else {
logger.Infof("SendSignalMsg aync success for %s, msgId = %d, context:%v", groupId, msg.MsgId, str)
}
}(model.Log)
} else if err = tencentyun.SendSystemMsg(model.Log, groupId, []string{}, str); err != nil {
model.Log.Errorf("SendSignalMsg sync failed for %s, msgId = %d, context:%v, err:%v", groupId, msg.MsgId, str, err)
} else {
model.Log.Infof("SendSignalMsg sync success for %s, msgId = %d, context:%v", groupId, msg.MsgId, str)
}
} else {
model.Log.Errorf("Marshall failure, msgId = %d : %s", msg.MsgId, err.Error())
}
}
module hilo-group
go 1.18
go 1.17
replace git.hilo.cn/hilo-common => ../hilo-common
require (
git.hilo.cn/hilo-common v0.0.0-00010101000000-000000000000 // indirect
git.hilo.cn/hilo-common v0.0.0-00010101000000-000000000000
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/bluele/gcache v0.0.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.6.3
github.com/go-redis/redis/v8 v8.11.5
github.com/jinzhu/copier v0.3.5
github.com/pkg/errors v0.9.1
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.7.0
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7
gorm.io/gorm v1.23.8
)
require (
github.com/AgoraIO/Tools/DynamicKey/AgoraDynamicKey/go/src v0.0.0-20200910100525-12b7f1b63a6a // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/bluele/gcache v0.0.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.12 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/rekognition v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 // indirect
github.com/aws/smithy-go v1.13.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.6.3 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/spec v0.19.4 // indirect
......@@ -27,7 +56,6 @@ require (
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.2.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/hashicorp/consul/api v1.7.0 // indirect
......@@ -38,11 +66,11 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/hashicorp/serf v0.9.3 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
......@@ -54,12 +82,7 @@ require (
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/swaggo/gin-swagger v1.2.0 // indirect
github.com/swaggo/swag v1.6.7 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ims v1.0.479 // indirect
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0 // indirect
......@@ -74,5 +97,4 @@ require (
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.4.3 // indirect
gorm.io/gorm v1.23.8 // indirect
)
This diff is collapsed.
......@@ -6,14 +6,15 @@ import (
var (
// 一般性错误
TokenInvalid = myerr.NewBusinessCode(1001, "token invalid", myerr.BusinessData{})
ExternalIdNoExist = myerr.NewBusinessCode(1003, "externalId no exist", myerr.BusinessData{})
CodeNoExist = myerr.NewBusinessCode(1005, "code no exist", myerr.BusinessData{})
ParaMissing = myerr.NewBusinessCode(1006, "parameter missing", myerr.BusinessData{})
InvalidParameter = myerr.NewBusinessCode(1009, "Invalid parameter", myerr.BusinessData{})
IncorrectState = myerr.NewBusinessCode(1013, "Incorrect state", myerr.BusinessData{})
TransactionFailed = myerr.NewBusinessCode(1014, "Transaction failed", myerr.BusinessData{})
ReqTooFrequent = myerr.NewBusinessCode(1018, "Requests are too frequent", myerr.BusinessData{})
TokenInvalid = myerr.NewBusinessCode(1001, "token invalid", myerr.BusinessData{})
ExternalIdNoExist = myerr.NewBusinessCode(1003, "externalId no exist", myerr.BusinessData{})
CodeNoExist = myerr.NewBusinessCode(1005, "code no exist", myerr.BusinessData{})
ParaMissing = myerr.NewBusinessCode(1006, "parameter missing", myerr.BusinessData{})
InvalidParameter = myerr.NewBusinessCode(1009, "Invalid parameter", myerr.BusinessData{})
IncorrectState = myerr.NewBusinessCode(1013, "Incorrect state", myerr.BusinessData{})
TransactionFailed = myerr.NewBusinessCode(1014, "Transaction failed", myerr.BusinessData{})
ImagePolicyViolation = myerr.NewBusinessCode(1017, "image policy violation", myerr.BusinessData{})
ReqTooFrequent = myerr.NewBusinessCode(1018, "Requests are too frequent", myerr.BusinessData{})
// 钻石
DiamondNoEnough = myerr.NewBusinessCode(4000, "Insufficient diamonds", myerr.BusinessData{})
......@@ -28,6 +29,7 @@ var (
UserMedalThresholdLimit = myerr.NewBusinessCode(9006, "勋章条件未达到", myerr.BusinessData{})
UserHeadwearHasEnd = myerr.NewBusinessCode(9014, "用户头饰已经过期, 不能赠送", myerr.BusinessData{})
UserPropertyHasEnd = myerr.NewBusinessCode(9015, "用户座驾已经过期, 不能赠送", myerr.BusinessData{})
EditCd = myerr.NewBusinessCode(9017, "not allow to edit", myerr.BusinessData{}) // 编辑cd中
// 麦位
GroupMicNoPermission = myerr.NewBusinessCode(12000, "Mic has no permission to mic", myerr.BusinessData{}) // 麦位没有操作的权限
......@@ -41,6 +43,7 @@ var (
// 群组
GroupNotFound = myerr.NewBusinessCode(14001, "Group not found", myerr.BusinessData{}) // 找不到该群
NoPrivileges = myerr.NewBusinessCode(14004, "Not enough permission", myerr.BusinessData{}) // 操作权限不够
WrongPasswordLength = myerr.NewBusinessCode(14010, "Incorrect password length", myerr.BusinessData{}) // 密码长度错误
GroupIsBanned = myerr.NewBusinessCode(14011, "group is banned by ", myerr.BusinessData{}) // 群已经被管理员封禁
GroupCreateLimitReached = myerr.NewBusinessCode(14014, "Create group limit reached", myerr.BusinessData{}) // 你创建的群组数已达上限
GroupCustomThemeLimit = myerr.NewBusinessCode(14020, "Group Custom Theme Limit", myerr.BusinessData{}) //群主题定制数量只能是5个
......
This diff is collapsed.
......@@ -27,7 +27,7 @@ func InitRouter() *gin.Engine {
imGroup.DELETE("/group/:groupId", wrapper(group_r.DestroyGroup))
imGroup.GET("/group/:code", wrapper(group_r.GetGroupInfo))
imGroup.GET("/detail/:groupId", wrapper(group_r.GetGroupDetail))
//imGroup.PUT("/group/:groupId", wrapper(ModifyGroupInfo))
imGroup.PUT("/group/:groupId", wrapper(group_r.ModifyGroupInfo))
//imGroup.GET("/search/:code", wrapper(SearchGroup))
//imGroup.DELETE("/member/:groupId", wrapper(LeaveGroup))
//imGroup.PUT("/permanent/:groupId", wrapper(AddPermanentMember))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment