-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
56 lines (50 loc) · 837 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/ODudek/go-aris/resp"
"net"
)
type Server struct {
port string
}
func (s *Server) Start() error {
l, err := net.Listen("tcp", s.port)
if err != nil {
return err
}
defer l.Close()
conn, err := l.Accept()
if err != nil {
return err
}
defer conn.Close()
handleData(conn)
return nil
}
func handleData(conn net.Conn) error {
for {
r := resp.NewReader(conn)
//w := resp.NewWriter(conn)
v, err := r.Read()
if err != nil {
return err
}
fmt.Println(v.GetValue())
conn.Write([]byte("+OK\r\n"))
//w.Write(v)
//buf := make([]byte, 1024)
//_, err := conn.Read(buf)
//if err != nil {
// if err == io.EOF {
// break
// }
// return err
//}
//conn.Write([]byte("+OK\r\n"))
}
}
func NewServer(port string) *Server {
return &Server{
port: port,
}
}