-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
902991c
commit a26eba1
Showing
12 changed files
with
373 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/patrickmn/go-cache" | ||
"time" | ||
) | ||
|
||
func NewCache() *cache.Cache { | ||
c := cache.New(1*time.Hour, 2*time.Hour) | ||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
package log | ||
|
||
import ( | ||
"fmt" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
func getLogLevel() logrus.Level { | ||
// 设置日志级别,可以根据需要修改 | ||
return logrus.DebugLevel | ||
} | ||
|
||
func getLogFormatter() logrus.Formatter { | ||
// 定义日志输出格式 | ||
return &logrus.TextFormatter{ | ||
FullTimestamp: true, | ||
TimestampFormat: "2006-01-02 15:04:05", //时间格式, | ||
CallerPrettyfier: callerPrettyfier, | ||
} | ||
} | ||
|
||
func callerPrettyfier(f *runtime.Frame) (string, string) { | ||
// 格式化输出文件名和行号 | ||
filename := filepath.Base(f.File) | ||
return fmt.Sprintf("%s:%d", filename, f.Line), "" | ||
} | ||
|
||
func NewLogger() *logrus.Logger { | ||
log := logrus.New() | ||
return log | ||
// 初始化日志 | ||
logger := logrus.New() | ||
logger.SetLevel(getLogLevel()) | ||
logger.SetOutput(os.Stdout) | ||
logger.SetFormatter(getLogFormatter()) | ||
|
||
return logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package domain | ||
|
||
import ( | ||
"github.com/hertz-contrib/websocket" | ||
"golang.org/x/sync/semaphore" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type ChatMessageEntity struct { | ||
Type string `json:"type"` | ||
Data string `json:"data"` | ||
Time time.Time `json:"time"` | ||
ErrorMsg string `json:"error_msg"` | ||
} | ||
|
||
type ChatEntity struct { | ||
ChatID string | ||
CreaterID string | ||
JoinerID string | ||
CreaterMessageLock sync.Mutex | ||
JoinerMessageLock sync.Mutex | ||
CreaterMessageWriteSem *semaphore.Weighted | ||
CreaterMessageReadSem *semaphore.Weighted | ||
JoinerMessageWriteSem *semaphore.Weighted | ||
JoinerMessageReadSem *semaphore.Weighted | ||
CreaterConn *websocket.Conn | ||
JoinerConn *websocket.Conn | ||
MessageSendByCreater []*ChatMessageEntity | ||
MessageSendByJoiner []*ChatMessageEntity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dto | ||
|
||
type SendMessageReq struct { | ||
ClientID string `json:"client_id"` | ||
Message string `json:"message"` | ||
ChatID string `json:"chat_id"` | ||
} | ||
|
||
type JoinChatReq struct { | ||
ChatID string `json:"chat_id"` | ||
} |
Oops, something went wrong.