You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
766 B
44 lines
766 B
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"wss-pool/logging/applogger"
|
|
)
|
|
|
|
type PingMessage struct {
|
|
Ping int64 `json:"ping"`
|
|
}
|
|
|
|
type SymbolMessage struct {
|
|
Type string `json:"type"`
|
|
Symbol string `json:"symbol"`
|
|
}
|
|
|
|
func ParsePingMessage(message string) *PingMessage {
|
|
result := PingMessage{}
|
|
err := json.Unmarshal([]byte(message), &result)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
return &result
|
|
}
|
|
|
|
func SubMessage(message string) *SymbolMessage {
|
|
result := SymbolMessage{}
|
|
err := json.Unmarshal([]byte(message), &result)
|
|
applogger.Info("ws param %v", message)
|
|
if err != nil {
|
|
fmt.Println("subMessage", err)
|
|
return nil
|
|
}
|
|
|
|
return &result
|
|
}
|
|
|
|
func ReturnValue(str string) string {
|
|
pongMsg := fmt.Sprintf("{\"type\": \"%v\"}", str)
|
|
|
|
return pongMsg
|
|
}
|
|
|