This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: chat service timestamp error (#116)
* Update init.go * Update get_message.go --------- Co-authored-by: ozline <ozlinex@outlook.com>
- Loading branch information
Showing
11 changed files
with
107 additions
and
26 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ozline/tiktok/cmd/chat/dal" | ||
"github.com/ozline/tiktok/config" | ||
"github.com/ozline/tiktok/kitex_gen/chat" | ||
"github.com/ozline/tiktok/pkg/utils" | ||
) | ||
|
||
func TestHadnlerGet(t *testing.T) { | ||
t.Log("result===>") | ||
config.InitForTest() | ||
dal.Init() | ||
msi := new(MessageServiceImpl) | ||
token, err := utils.CreateToken(3) | ||
if err != nil { | ||
t.Error(err) | ||
t.Fail() | ||
} | ||
mlr, err := msi.MessageList(context.Background(), &chat.MessageListRequest{ | ||
Token: token, | ||
ToUserId: 2, | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
t.Fail() | ||
} | ||
t.Log("result===>", mlr.MessageList) | ||
t.Log("result===>", mlr.Total) | ||
time.Sleep(2 * time.Second) | ||
} |
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,28 +1,29 @@ | ||
package pack | ||
|
||
import ( | ||
"time" | ||
"fmt" | ||
|
||
"github.com/ozline/tiktok/cmd/chat/dal/db" | ||
"github.com/ozline/tiktok/kitex_gen/chat" | ||
) | ||
|
||
type MessageBuildArray []*chat.Message | ||
|
||
func BuildMessage(data []*db.Message) []*chat.Message { | ||
if data == nil { | ||
return make([]*chat.Message, 0) | ||
} | ||
|
||
res := make([]*chat.Message, 0) | ||
res := make(MessageBuildArray, 0) | ||
for _, val := range data { | ||
create_time := val.CreatedAt.Format(time.DateTime) | ||
message := &chat.Message{ | ||
create_at := fmt.Sprintf("%v", val.CreatedAt.UnixMilli()) | ||
msg := &chat.Message{ | ||
Id: val.Id, | ||
ToUserId: val.ToUserId, | ||
FromUserId: val.FromUserId, | ||
Content: val.Content, | ||
CreateTime: &create_time, | ||
CreateTime: &create_at, | ||
} | ||
res = append(res, message) | ||
res = append(res, msg) | ||
} | ||
return res | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ants | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
|
||
"github.com/panjf2000/ants" | ||
) | ||
|
||
var ( | ||
AntsPool *ants.PoolWithFunc | ||
Wg sync.WaitGroup | ||
) | ||
|
||
func Init() { | ||
ants_Pool, err := ants.NewPoolWithFunc(500, func(payload interface{}) { | ||
defer Wg.Done() | ||
}) | ||
if err != nil { | ||
panic(errors.New("[ants goroutine init error]")) | ||
} | ||
AntsPool = ants_Pool | ||
} |