gob로 변경
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/wshandler"
|
||||
@ -312,16 +313,13 @@ func (gc *groupChat) LeavePrivateChannel(ctx wshandler.ApiCallContext) {
|
||||
// }
|
||||
|
||||
func (gc *groupChat) FetchChattingChannels(w http.ResponseWriter, r *http.Request) {
|
||||
var data struct {
|
||||
Prefix string `bson:"prefix"`
|
||||
}
|
||||
if err := gocommon.ReadJsonDocumentFromBody(r.Body, &data); err != nil {
|
||||
var prefix string
|
||||
if err := gocommon.MakeDecoder(r).Decode(&prefix); err != nil {
|
||||
logger.Println("FetchChattingChannels failed. ReadJsonDocumentFromBody returns err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
prefix := data.Prefix
|
||||
if len(prefix) == 0 {
|
||||
logger.Println("FetchChattingChannel failed. prefix is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -346,53 +344,35 @@ func (gc *groupChat) FetchChattingChannels(w http.ResponseWriter, r *http.Reques
|
||||
if err == redis.Nil || onechan == nil {
|
||||
rows = append(rows, cfg.emptyJson)
|
||||
} else {
|
||||
rows = append(rows, onechan.(string))
|
||||
// json array로 나온다
|
||||
rows = append(rows, strings.Trim(onechan.(string), "[]"))
|
||||
}
|
||||
}
|
||||
|
||||
if len(rows) == 0 {
|
||||
w.Write([]byte("[]"))
|
||||
} else if len(rows) == 1 {
|
||||
w.Write([]byte(rows[0]))
|
||||
} else {
|
||||
first := rows[0]
|
||||
w.Write([]byte(first[:len(first)-1]))
|
||||
for i := 1; i < len(rows); i++ {
|
||||
mid := rows[i]
|
||||
w.Write([]byte(","))
|
||||
w.Write([]byte(mid[1 : len(mid)-1]))
|
||||
}
|
||||
w.Write([]byte("]"))
|
||||
}
|
||||
gocommon.MakeEncoder(w, r).Encode(rows)
|
||||
}
|
||||
|
||||
func (gc *groupChat) QueryPlayerChattingChannel(w http.ResponseWriter, r *http.Request) {
|
||||
var data struct {
|
||||
Accid string `bson:"accid"`
|
||||
Typename string `bson:"typename"`
|
||||
}
|
||||
err := gocommon.ReadJsonDocumentFromBody(r.Body, &data)
|
||||
if err != nil {
|
||||
var accid primitive.ObjectID
|
||||
if err := gocommon.MakeDecoder(r).Decode(&accid); err != nil {
|
||||
logger.Println("QueryPlayerChattingChannel failed. ReadJsonDocumentFromBody returns err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
accid := data.Accid
|
||||
sub, err := gc.rh.JSONGetDocuments(accid, "$.channel")
|
||||
sub, err := gc.rh.JSONGetDocuments(accid.Hex(), "$.channel")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(sub) > 0 {
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode(sub[0])
|
||||
gocommon.MakeEncoder(w, r).Encode(sub[0])
|
||||
}
|
||||
}
|
||||
|
||||
func (gc *groupChat) SendMessageOnChannel(w http.ResponseWriter, r *http.Request) {
|
||||
var msg wshandler.UpstreamMessage
|
||||
if err := gocommon.ReadJsonDocumentFromBody(r.Body, &msg); err != nil {
|
||||
if err := gocommon.MakeDecoder(r).Decode(&msg); err != nil {
|
||||
logger.Println("SendMessageOnChannel failed. ReadJsonDocumentFromBody return err :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user