-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (37 loc) · 864 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"net"
"github.com/sirupsen/logrus"
)
var port int
var password string
func init() {
flag.IntVar(&port, "port", 6379, "HTTP Port")
flag.StringVar(&password, "requirepass", "", "Password")
}
func main() {
flag.Parse()
log := logrus.New()
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatalf("Could not start server: %v", err)
}
defer l.Close()
log.Infof("Listening on %d", port)
if len(password) > 0 {
log.Info("Server protected by password")
}
// TODO: Add mutex
storage := make(map[string]string)
for {
conn, err := l.Accept()
if err != nil {
log.Fatalf("Could not accept connection %v", err)
}
logger := log.WithField("remote", conn.RemoteAddr())
logger.Infoln("Serving")
go (&sessionHandler{conn, logger, storage, len(password) == 0}).handle()
}
}