mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-09-02 21:29:59 +08:00
update
This commit is contained in:
parent
ed52d40d8d
commit
75d308de37
@ -39,7 +39,7 @@ type config struct {
|
|||||||
DBAddress []string `yaml:"dbAddress"`
|
DBAddress []string `yaml:"dbAddress"`
|
||||||
DBDirect bool `yaml:"dbDirect"`
|
DBDirect bool `yaml:"dbDirect"`
|
||||||
DBTimeout int `yaml:"dbTimeout"`
|
DBTimeout int `yaml:"dbTimeout"`
|
||||||
DBDatabase []string `yaml:"dbDatabase"`
|
DBDatabase string `yaml:"dbDatabase"`
|
||||||
DBSource string `yaml:"dbSource"`
|
DBSource string `yaml:"dbSource"`
|
||||||
DBUserName string `yaml:"dbUserName"`
|
DBUserName string `yaml:"dbUserName"`
|
||||||
DBPassword string `yaml:"dbPassword"`
|
DBPassword string `yaml:"dbPassword"`
|
||||||
@ -47,11 +47,11 @@ type config struct {
|
|||||||
DBRetainChatRecords int `yaml:"dbRetainChatRecords"`
|
DBRetainChatRecords int `yaml:"dbRetainChatRecords"`
|
||||||
}
|
}
|
||||||
Redis struct {
|
Redis struct {
|
||||||
DBAddress []string `yaml:"dbAddress"`
|
DBAddress string `yaml:"dbAddress"`
|
||||||
DBMaxIdle int `yaml:"dbMaxIdle"`
|
DBMaxIdle int `yaml:"dbMaxIdle"`
|
||||||
DBMaxActive int `yaml:"dbMaxActive"`
|
DBMaxActive int `yaml:"dbMaxActive"`
|
||||||
DBIdleTimeout int `yaml:"dbIdleTimeout"`
|
DBIdleTimeout int `yaml:"dbIdleTimeout"`
|
||||||
DBPassWord string `yaml:"dbPassWord"`
|
DBPassWord string `yaml:"dbPassWord"`
|
||||||
}
|
}
|
||||||
RpcPort struct {
|
RpcPort struct {
|
||||||
OpenImUserPort []int `yaml:"openImUserPort"`
|
OpenImUserPort []int `yaml:"openImUserPort"`
|
||||||
|
@ -3,11 +3,18 @@ package constant
|
|||||||
const (
|
const (
|
||||||
|
|
||||||
//group admin
|
//group admin
|
||||||
GroupAdmin = 1
|
OrdinaryMember = 0
|
||||||
|
GroupCreator = 1
|
||||||
|
Administrator = 2
|
||||||
|
//group application
|
||||||
|
Application = 0
|
||||||
|
AgreeApplication = 1
|
||||||
|
|
||||||
//feiend related
|
//feiend related
|
||||||
BlackListFlag = 1
|
BlackListFlag = 1
|
||||||
NotFriendFlag = 0
|
ApplicationFriendFlag = 0
|
||||||
FriendFlag = 1
|
FriendFlag = 1
|
||||||
|
RefuseFriendFlag = -1
|
||||||
|
|
||||||
//Websocket Protocol
|
//Websocket Protocol
|
||||||
WSGetNewestSeq = 1001
|
WSGetNewestSeq = 1001
|
||||||
@ -25,9 +32,27 @@ const (
|
|||||||
|
|
||||||
SyncSenderMsg = 108
|
SyncSenderMsg = 108
|
||||||
//SysRelated
|
//SysRelated
|
||||||
AddFriendTip = 201
|
AcceptFriendApplicationTip = 201
|
||||||
AgreeAddFriendTip = 202
|
AddFriendTip = 202
|
||||||
KickOnlineTip = 203
|
RefuseFriendApplicationTip = 203
|
||||||
|
SetSelfInfoTip = 204
|
||||||
|
Revoke = 205
|
||||||
|
C2CMessageAsRead = 206
|
||||||
|
|
||||||
|
KickOnlineTip = 303
|
||||||
|
|
||||||
|
TransferGroupOwnerTip = 501
|
||||||
|
CreateGroupTip = 502
|
||||||
|
GroupApplicationResponseTip = 503
|
||||||
|
JoinGroupTip = 504
|
||||||
|
QuitGroupTip = 505
|
||||||
|
SetGroupInfoTip = 506
|
||||||
|
AcceptGroupApplicationTip = 507
|
||||||
|
RefuseGroupApplicationTip = 508
|
||||||
|
KickGroupMemberTip = 509
|
||||||
|
InviteUserToGroupTip = 510
|
||||||
|
AcceptGroupApplicationResultTip = 511
|
||||||
|
RefuseGroupApplicationResultTip = 512
|
||||||
|
|
||||||
//MsgFrom
|
//MsgFrom
|
||||||
UserMsgType = 100
|
UserMsgType = 100
|
||||||
|
53
src/common/http/http_client.go
Normal file
53
src/common/http/http_client.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
** description("").
|
||||||
|
** copyright('open-im,www.open-im.io').
|
||||||
|
** author("fg,Gordon@tuoyun.net").
|
||||||
|
** time(2021/5/27 10:31).
|
||||||
|
*/
|
||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Get(url string) (response []byte, err error) {
|
||||||
|
client := http.Client{Timeout: 5 * time.Second}
|
||||||
|
resp, err := client.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//application/json; charset=utf-8
|
||||||
|
func Post(url string, data interface{}, contentType string) (content []byte, err error) {
|
||||||
|
jsonStr, _ := json.Marshal(data)
|
||||||
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Add("content-type", contentType)
|
||||||
|
defer req.Body.Close()
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 5 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
result, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
@ -15,10 +15,10 @@ type Producer struct {
|
|||||||
|
|
||||||
func NewKafkaProducer(addr []string, topic string) *Producer {
|
func NewKafkaProducer(addr []string, topic string) *Producer {
|
||||||
p := Producer{}
|
p := Producer{}
|
||||||
p.config = sarama.NewConfig() //Instantiate a sarama Config
|
p.config = sarama.NewConfig() //实例化个sarama的Config
|
||||||
p.config.Producer.Return.Successes = true //Whether to enable the successes channel to be notified after the message is sent successfully
|
p.config.Producer.Return.Successes = true //是否开启消息发送成功后通知 successes channel
|
||||||
p.config.Producer.RequiredAcks = sarama.WaitForAll //Set producer Message Reply level 0 1 all
|
p.config.Producer.RequiredAcks = sarama.WaitForAll //设置生产者 消息 回复等级 0 1 all
|
||||||
p.config.Producer.Partitioner = sarama.NewHashPartitioner //Set the hash-key automatic hash partition. When sending a message, you must specify the key value of the message. If there is no key, the partition will be selected randomly
|
p.config.Producer.Partitioner = sarama.NewHashPartitioner //过设置 hash-key 自动 hash 分区,在发送消息的时候必须指定消息的key值,如果没有key,则随机选取分区
|
||||||
|
|
||||||
p.addr = addr
|
p.addr = addr
|
||||||
p.topic = topic
|
p.topic = topic
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** description("Hook to send logs to elasticsearch").
|
** description("将日志发送到elasticsearch的hook").
|
||||||
** copyright('tuoyun,www.tuoyun.net').
|
** copyright('tuoyun,www.tuoyun.net').
|
||||||
** author("fg,Gordon@tuoyun.net").
|
** author("fg,Gordon@tuoyun.net").
|
||||||
** time(2021/3/26 17:05).
|
** time(2021/3/26 17:05).
|
||||||
@ -18,13 +18,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//esHook custom es hook
|
//esHook 自定义的ES hook
|
||||||
type esHook struct {
|
type esHook struct {
|
||||||
moduleName string
|
moduleName string
|
||||||
client *elasticV7.Client
|
client *elasticV7.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
//newEsHook initialization
|
//newEsHook 初始化
|
||||||
func newEsHook(moduleName string) *esHook {
|
func newEsHook(moduleName string) *esHook {
|
||||||
//https://github.com/sohlich/elogrus
|
//https://github.com/sohlich/elogrus
|
||||||
//client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
|
//client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
|
||||||
@ -61,19 +61,19 @@ func newEsHook(moduleName string) *esHook {
|
|||||||
return &esHook{client: es, moduleName: moduleName}
|
return &esHook{client: es, moduleName: moduleName}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fire log hook interface method
|
//Fire log hook interface 方法
|
||||||
func (hook *esHook) Fire(entry *logrus.Entry) error {
|
func (hook *esHook) Fire(entry *logrus.Entry) error {
|
||||||
doc := newEsLog(entry)
|
doc := newEsLog(entry)
|
||||||
go hook.sendEs(doc)
|
go hook.sendEs(doc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Levels log hook interface method, the log affected by this hook
|
//Levels log hook interface 方法,此hook影响的日志
|
||||||
func (hook *esHook) Levels() []logrus.Level {
|
func (hook *esHook) Levels() []logrus.Level {
|
||||||
return logrus.AllLevels
|
return logrus.AllLevels
|
||||||
}
|
}
|
||||||
|
|
||||||
//sendEs Asynchronously send logs to es
|
//sendEs 异步发送日志到es
|
||||||
func (hook *esHook) sendEs(doc appLogDocModel) {
|
func (hook *esHook) sendEs(doc appLogDocModel) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@ -102,7 +102,7 @@ func newEsLog(e *logrus.Entry) appLogDocModel {
|
|||||||
return ins
|
return ins
|
||||||
}
|
}
|
||||||
|
|
||||||
// indexName es index name time division
|
// indexName es index name 时间分割
|
||||||
func (m *appLogDocModel) indexName() string {
|
func (m *appLogDocModel) indexName() string {
|
||||||
return time.Now().Format("2006-01-02")
|
return time.Now().Format("2006-01-02")
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** description("Get the hook of the calling file name and line number").
|
** description("得到调用文件名字和行号的hook").
|
||||||
** copyright('tuoyun,www.tuoyun.net').
|
** copyright('tuoyun,www.tuoyun.net').
|
||||||
** author("fg,Gordon@tuoyun.net").
|
** author("fg,Gordon@tuoyun.net").
|
||||||
** time(2021/3/16 11:26).
|
** time(2021/3/16 11:26).
|
||||||
|
@ -12,42 +12,42 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TimeOffset = 8 * 3600 //8 hour offset
|
TimeOffset = 8 * 3600 //8个小时的偏移量
|
||||||
HalfOffset = 12 * 3600 //Half-day hourly offset
|
HalfOffset = 12 * 3600 //半天的小时偏移量
|
||||||
)
|
)
|
||||||
|
|
||||||
//Get the current timestamp
|
//获取当前的时间戳
|
||||||
func GetCurrentTimestamp() int64 {
|
func GetCurrentTimestamp() int64 {
|
||||||
return time.Now().Unix()
|
return time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the timestamp at 0 o'clock of the day
|
//获取当天0点的时间戳
|
||||||
func GetCurDayZeroTimestamp() int64 {
|
func GetCurDayZeroTimestamp() int64 {
|
||||||
timeStr := time.Now().Format("2006-01-02")
|
timeStr := time.Now().Format("2006-01-02")
|
||||||
t, _ := time.Parse("2006-01-02", timeStr)
|
t, _ := time.Parse("2006-01-02", timeStr)
|
||||||
return t.Unix() - TimeOffset
|
return t.Unix() - TimeOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the timestamp at 12 o'clock on the day
|
//获取当天12点的时间戳
|
||||||
func GetCurDayHalfTimestamp() int64 {
|
func GetCurDayHalfTimestamp() int64 {
|
||||||
return GetCurDayZeroTimestamp() + HalfOffset
|
return GetCurDayZeroTimestamp() + HalfOffset
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00"
|
//获取当天0点格式化时间,格式为"2006-01-02_00-00-00"
|
||||||
func GetCurDayZeroTimeFormat() string {
|
func GetCurDayZeroTimeFormat() string {
|
||||||
return time.Unix(GetCurDayZeroTimestamp(), 0).Format("2006-01-02_15-04-05")
|
return time.Unix(GetCurDayZeroTimestamp(), 0).Format("2006-01-02_15-04-05")
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00"
|
//获取当天12点格式化时间,格式为"2006-01-02_12-00-00"
|
||||||
func GetCurDayHalfTimeFormat() string {
|
func GetCurDayHalfTimeFormat() string {
|
||||||
return time.Unix(GetCurDayZeroTimestamp()+HalfOffset, 0).Format("2006-01-02_15-04-05")
|
return time.Unix(GetCurDayZeroTimestamp()+HalfOffset, 0).Format("2006-01-02_15-04-05")
|
||||||
}
|
}
|
||||||
func GetTimeStampByFormat(datetime string) string {
|
func GetTimeStampByFormat(datetime string) string {
|
||||||
timeLayout := "2006-01-02 15:04:05" //Template required for transformation
|
timeLayout := "2006-01-02 15:04:05" //转化所需模板
|
||||||
loc, _ := time.LoadLocation("Local") //Get time zone
|
loc, _ := time.LoadLocation("Local") //获取时区
|
||||||
tmp, _ := time.ParseInLocation(timeLayout, datetime, loc)
|
tmp, _ := time.ParseInLocation(timeLayout, datetime, loc)
|
||||||
timestamp := tmp.Unix() //Converted to timestamp type is int64
|
timestamp := tmp.Unix() //转化为时间戳 类型是int64
|
||||||
return strconv.FormatInt(timestamp, 10)
|
return strconv.FormatInt(timestamp, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user