body와 query 분리, 모듈 업데이트
This commit is contained in:
@ -223,7 +223,7 @@ func (gc *groupChat) ClientMessageReceived(sender *wshandler.Sender, mt wshandle
|
||||
}
|
||||
|
||||
func (gc *groupChat) FetchChattingChannels(w http.ResponseWriter, r *http.Request) {
|
||||
prefix, _ := gocommon.ReadStringFormValue(r.Form, "prefix")
|
||||
prefix, _ := gocommon.ReadStringFormValue(r.URL.Query(), "prefix")
|
||||
if len(prefix) == 0 {
|
||||
logger.Println("FetchChattingChannel failed. prefix is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -269,8 +269,8 @@ func (gc *groupChat) FetchChattingChannels(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
func (gc *groupChat) QueryPlayerChattingChannel(w http.ResponseWriter, r *http.Request) {
|
||||
accid, _ := gocommon.ReadStringFormValue(r.Form, "accid")
|
||||
typename, _ := gocommon.ReadStringFormValue(r.Form, "typename")
|
||||
accid, _ := gocommon.ReadStringFormValue(r.URL.Query(), "accid")
|
||||
typename, _ := gocommon.ReadStringFormValue(r.URL.Query(), "typename")
|
||||
|
||||
var fields []string
|
||||
if len(typename) == 0 {
|
||||
@ -298,9 +298,9 @@ func (gc *groupChat) QueryPlayerChattingChannel(w http.ResponseWriter, r *http.R
|
||||
}
|
||||
|
||||
func (gc *groupChat) SendMessageOnChannel(w http.ResponseWriter, r *http.Request) {
|
||||
channel, _ := gocommon.ReadStringFormValue(r.Form, "channel")
|
||||
target, _ := gocommon.ReadStringFormValue(r.Form, "target")
|
||||
tag, _ := gocommon.ReadStringFormValue(r.Form, "tag")
|
||||
channel, _ := gocommon.ReadStringFormValue(r.URL.Query(), "channel")
|
||||
target, _ := gocommon.ReadStringFormValue(r.URL.Query(), "target")
|
||||
tag, _ := gocommon.ReadStringFormValue(r.URL.Query(), "tag")
|
||||
if len(channel) == 0 || len(target) == 0 || len(tag) == 0 {
|
||||
logger.Println("SendMessageOnChannel failed. channel or target or tag is empty")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -331,9 +331,9 @@ func (gc *groupChat) SendMessageOnChannel(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
func (gc *groupChat) BroadcastMessageOnChannel(w http.ResponseWriter, r *http.Request) {
|
||||
nickname, _ := gocommon.ReadStringFormValue(r.Form, "nickname")
|
||||
channel, _ := gocommon.ReadStringFormValue(r.Form, "channel")
|
||||
tag, _ := gocommon.ReadStringFormValue(r.Form, "tag")
|
||||
nickname, _ := gocommon.ReadStringFormValue(r.URL.Query(), "nickname")
|
||||
channel, _ := gocommon.ReadStringFormValue(r.URL.Query(), "channel")
|
||||
tag, _ := gocommon.ReadStringFormValue(r.URL.Query(), "tag")
|
||||
text, _ := io.ReadAll(r.Body)
|
||||
|
||||
if len(tag) > 0 {
|
||||
|
||||
@ -302,13 +302,13 @@ func (gp *groupParty) JoinParty(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("JoinParty failed. gid is missing :", r.Form)
|
||||
logger.Println("JoinParty failed. gid is missing :", r.URL.Query())
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
mid, midok := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
mid, midok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
if !midok {
|
||||
logger.Println("JoinParty failed. mid should be exist")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -363,13 +363,13 @@ func (gp *groupParty) JoinParty(w http.ResponseWriter, r *http.Request) {
|
||||
// - timeout : 초대 유지시간(optional. 없으면 config 기본 값)
|
||||
// - (body) : 검색시 노출되는 document
|
||||
func (gp *groupParty) InviteToParty(w http.ResponseWriter, r *http.Request) {
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("InviteToParty failed. gid is missing :", r)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
mid, ok := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
mid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
if !ok {
|
||||
logger.Println("InviteToParty failed. mid is missing :", r)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -459,8 +459,8 @@ func (gp *groupParty) InviteToParty(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (gp *groupParty) AcceptPartyInvitation(w http.ResponseWriter, r *http.Request) {
|
||||
gid, _ := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
mid, _ := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
gid, _ := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
mid, _ := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
|
||||
var member bson.M
|
||||
if err := readBsonDoc(r.Body, &member); err != nil {
|
||||
@ -512,8 +512,8 @@ func (gp *groupParty) AcceptPartyInvitation(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
func (gp *groupParty) DenyPartyInvitation(w http.ResponseWriter, r *http.Request) {
|
||||
gid, _ := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
mid, _ := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
gid, _ := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
mid, _ := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
|
||||
gp.rh.Del(context.Background(), "inv."+mid.Hex()).Result()
|
||||
gd := groupDoc{
|
||||
@ -524,9 +524,9 @@ func (gp *groupParty) DenyPartyInvitation(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
func (gp *groupParty) QueryPartyMemberState(w http.ResponseWriter, r *http.Request) {
|
||||
mid, ok := gocommon.ReadStringFormValue(r.Form, "mid")
|
||||
mid, ok := gocommon.ReadStringFormValue(r.URL.Query(), "mid")
|
||||
if !ok {
|
||||
logger.Println("IsOnline failed. mid is missing :", r.Form)
|
||||
logger.Println("IsOnline failed. mid is missing :", r.URL.Query())
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -545,19 +545,19 @@ func (gp *groupParty) QueryPartyMemberState(w http.ResponseWriter, r *http.Reque
|
||||
// - 그룹 타입에 맞는 키(주로 _id)
|
||||
// - member_id : 나갈 멤버의 아이디
|
||||
func (gp *groupParty) LeaveParty(w http.ResponseWriter, r *http.Request) {
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("LeaveParty failed. gid is missing :", r.Form)
|
||||
logger.Println("LeaveParty failed. gid is missing :", r.URL.Query())
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
mid, midok := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
mid, midok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
if !midok {
|
||||
logger.Println("LeaveParty failed. mid is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
tid, tidok := gocommon.ReadStringFormValue(r.Form, "tid")
|
||||
tid, tidok := gocommon.ReadStringFormValue(r.URL.Query(), "tid")
|
||||
gd := groupDoc{
|
||||
id: gid,
|
||||
rh: gp.rh,
|
||||
@ -638,14 +638,14 @@ func (gp *groupParty) updateMemberDocument(gid groupID, mid accountID, doc bson.
|
||||
}
|
||||
|
||||
func (gp *groupParty) UpdatePartyMemberDocument(w http.ResponseWriter, r *http.Request) {
|
||||
mid, ok := gocommon.ReadObjectIDFormValue(r.Form, "mid")
|
||||
mid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "mid")
|
||||
if !ok {
|
||||
logger.Println("UpdatePartyMemberDocument failed. member_id is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("UpdatePartyMemberDocument failed. _id is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -684,7 +684,7 @@ func (gp *groupParty) updatePartyDocument(gid groupID, frag bson.M) error {
|
||||
}
|
||||
|
||||
func (gp *groupParty) UpdatePartyDocument(w http.ResponseWriter, r *http.Request) {
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("UpdatePartyDocument failed. gid is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -706,7 +706,7 @@ func (gp *groupParty) UpdatePartyDocument(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
func (gp *groupParty) QueryPartyMembers(w http.ResponseWriter, r *http.Request) {
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.Form, "gid")
|
||||
gid, ok := gocommon.ReadObjectIDFormValue(r.URL.Query(), "gid")
|
||||
if !ok {
|
||||
logger.Println("QueryPartyMembers failed. gid is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
@ -181,7 +181,15 @@ func (tv *Tavern) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux,
|
||||
func (tv *Tavern) OnClientMessageReceived(sender *wshandler.Sender, messageType wshandler.WebSocketMessageType, body io.Reader) {
|
||||
if messageType == wshandler.Connected {
|
||||
logger.Println("OnClientMessageReceived : connected ", sender.Accid.Hex())
|
||||
_, err := tv.redison.HSet(tv.redison.Context(), sender.Accid.Hex(), "_ts", time.Now().UTC().Unix()).Result()
|
||||
if err != nil {
|
||||
logger.Println("OnClientMessageReceived HSet error :", err)
|
||||
if *devflag {
|
||||
tv.redison.Del(tv.redison.Context(), sender.Accid.Hex()).Result()
|
||||
tv.redison.HSet(tv.redison.Context(), sender.Accid.Hex(), "_ts", time.Now().UTC().Unix()).Result()
|
||||
}
|
||||
}
|
||||
|
||||
for _, gt := range tv.groups {
|
||||
gt.ClientMessageReceived(sender, messageType, nil)
|
||||
}
|
||||
@ -257,9 +265,6 @@ func (tv *Tavern) api(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if r.PostForm == nil {
|
||||
r.ParseMultipartForm(defaultMaxMemory)
|
||||
}
|
||||
|
||||
operation := r.URL.Query().Get("operation")
|
||||
if len(operation) == 0 {
|
||||
|
||||
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
go.mongodb.org/mongo-driver v1.11.7
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230831121619-9e9d91b5a30f
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230901022951-26e968f7c9bf
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
2
go.sum
2
go.sum
@ -154,3 +154,5 @@ repositories.action2quare.com/ayo/gocommon v0.0.0-20230831121208-90502c3029c5 h1
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230831121208-90502c3029c5/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230831121619-9e9d91b5a30f h1:X4NTuEgFodH8CStrjNw0uYA9P8oJzjflH9TboKt67gg=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230831121619-9e9d91b5a30f/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230901022951-26e968f7c9bf h1:lG83p89qnYwtYYLh92Fc5hXHPk3lKxKe1lZx1ShDu/Y=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230901022951-26e968f7c9bf/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
|
||||
Reference in New Issue
Block a user