summaryrefslogtreecommitdiff
path: root/client/utils.go
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-04-27 21:41:44 +0400
committerAndrew <saintruler@gmail.com>2021-04-27 21:41:44 +0400
commitf3088f22e319b7183f9ad29d582574d3a06666ed (patch)
tree89e2f076d83d50f050964c3e92ffd0093bac197f /client/utils.go
parent1fb7ca2bd298cbe340f7790cc40a808b1a4ab245 (diff)
Added GUI to client. renamed Message to Request. Added PING request type to sender server.
Diffstat (limited to 'client/utils.go')
-rw-r--r--client/utils.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/client/utils.go b/client/utils.go
index 4dc64b7..685a3a9 100644
--- a/client/utils.go
+++ b/client/utils.go
@@ -2,31 +2,38 @@ package main
import (
"encoding/json"
+ "fmt"
"net"
)
const (
MESSAGE = "message"
AUTHENTICATE = "authenticate"
- RENAME = "rename"
+ EXIT = "exit"
+ REGISTER = "register"
)
const (
SUCCESS = "success"
FAILURE = "failure"
+ PING = "ping"
)
-type Message struct {
+type Request struct {
Type string
Data string
User string
}
-func (msg *Message) serialize() string {
- data, _ := json.Marshal(msg)
+func (req *Request) serialize() string {
+ data, _ := json.Marshal(req)
return string(data)
}
+func (req *Request) toString() string {
+ return fmt.Sprintf("%s: %s", req.User, req.Data)
+}
+
type Response struct {
Status string
Data string
@@ -62,8 +69,8 @@ func sendMessage(conn net.Conn, message []byte) error {
return nil
}
-func parseMessage(data []byte) (Message, error) {
- var m Message
+func parseRequest(data []byte) (Request, error) {
+ var m Request
err := json.Unmarshal(data, &m)
return m, err
}