-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ngql websocket #403
feat: ngql websocket #403
Conversation
if err == nil { | ||
clientInfo, _ = auth.Decode(tokenCookie.Value, svcCtx.Config.Auth.AccessSecret) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err != nil, need handle err? and why ingore auth.Decode err
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should make sure websocket connecting succeed
server/api/studio/pkg/ws/client.go
Outdated
msgPost := MessagePost{} | ||
msgPost.Header.MsgId = msgReceived.Header.MsgId | ||
msgPost.Header.SendTime = time.Now().UnixMilli() | ||
msgPost.Body.MsgType = msgReceived.Body.MsgType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge into one declaration? like
msgPost := MessagePost{
...
}
server/api/studio/pkg/ws/client.go
Outdated
reqParamList := msgReceived.Body.Content["paramList"] | ||
if reqParamList != nil && reflect.TypeOf(reqParamList).Kind() == reflect.Slice { | ||
s := reqParamList.([]interface{}) | ||
for i := 0; i < len(s); i++ { | ||
paramList = append(paramList, s[i].(string)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
reqParamList, ok := msgReceived.Body.Content["paramList"].([]interface{})
if ok {
paramList = append(paramList, reqParamList[i].(string)...)
}
instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kqzh []any
?
server/api/studio/pkg/ws/client.go
Outdated
gql, paramList := "", []string{} | ||
|
||
reqGql := msgReceived.Body.Content["gql"] | ||
if reqGql != nil { | ||
gql, _ = reqGql.(string) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
reqGql, ok := msgReceived.Body.Content["gql"].(string)
if ok {
gql = reqGql
}
instead ?
server/api/studio/pkg/ws/client.go
Outdated
} | ||
|
||
execute, _, err := dao.Execute(c.clientInfo.NSID, gql, paramList) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this empty line?
if auth.IsSessionError(err) { | ||
content["code"] = ecode.ErrSession.GetCode() | ||
} | ||
msgPost.Body.Content = &content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add &?
server/api/studio/pkg/ws/client.go
Outdated
msgPost := MessagePost{} | ||
msgPost.Header.MsgId = msgReceived.Header.MsgId | ||
msgPost.Header.SendTime = time.Now().UnixMilli() | ||
msgPost.Body.MsgType = msgReceived.Body.MsgType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as runNgql
msgPost.Body.Content = map[string]any{ | ||
"code": base.Success, | ||
"data": resContentData, | ||
"message": "Success", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execute batch ngql will never failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, single ngql execution may be error res, batch req should never fail unless network anomaly or other unexpected server error
server/api/studio/pkg/ws/hub.go
Outdated
case message := <-h.broadcast: | ||
for client := range h.clients { | ||
select { | ||
case client.send <- message: | ||
default: | ||
close(client.send) | ||
delete(h.clients, client) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has been commented out, may be used in future
server/api/studio/pkg/ws/client.go
Outdated
|
||
reqGql := msgReceived.Body.Content["gql"] | ||
if reqGql != nil { | ||
gql, _ = reqGql.(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it's should not to be ignored. How about you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msgReceived.Body.Content["gql"]
may be a nil
value in some case, only paramList
is passed in request data
"strings" | ||
"time" | ||
|
||
"github.com/gorilla/websocket" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to lint ?
server/api/studio/pkg/ws/client.go
Outdated
pingPeriod = (pongWait * 9) / 10 | ||
|
||
// Maximum message size allowed from peer. | ||
maxMessageSize = 16 * 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 16 * 1024
enough?
server/api/studio/pkg/ws/client.go
Outdated
if reqParamList != nil && reflect.TypeOf(reqParamList).Kind() == reflect.Slice { | ||
s := reqParamList.([]interface{}) | ||
for i := 0; i < len(s); i++ { | ||
paramList = append(paramList, s[i].(string)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s[i]
maybe not a string
?
} | ||
} | ||
|
||
msgSend, _ := json.Marshal(msgPost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check the error?
server/api/studio/pkg/ws/client.go
Outdated
reqGqls := msgReceived.Body.Content["gqls"] | ||
if reqGqls != nil && reflect.TypeOf(reqGqls).Kind() == reflect.Slice { | ||
s := reqGqls.([]interface{}) | ||
for i := 0; i < len(s); i++ { | ||
gqls = append(gqls, s[i].(string)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add some functions for MessageReceiveBody
is more clearer?
And check the type in those functions.
func (b *MessageReceiveBody) GetGqls() (string, error) {
}
func (b *MessageReceiveBody) GetParamList() ([]string, error) {
}
// and so on
server/api/studio/pkg/ws/client.go
Outdated
break | ||
} | ||
|
||
msgReceivedStr := bytes.TrimSpace(bytes.Replace(message, newline, space, -1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need bytes.Replace(message, newline, space, -1)
?
} | ||
w.Write(message) | ||
|
||
// Add queued chat messages to the current websocket message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chat messages?
// Add queued chat messages to the current websocket message. | ||
n := len(c.send) | ||
for i := 0; i < n; i++ { | ||
w.Write(newline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need to write newline
?
} | ||
} | ||
|
||
// ServeWs handles websocket requests from the peer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServeWs
=> ServeWebSocket
?
server/api/studio/pkg/ws/hub.go
Outdated
clients map[*Client]bool | ||
|
||
// Inbound messages from the clients. | ||
broadcast chan []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What type of PR is this?
What problem(s) does this PR solve?
Issue(s) number:
Description:
How do you solve it?
Special notes for your reviewer, ex. impact of this fix, design document, etc: