-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (72 loc) · 2.17 KB
/
main.go
File metadata and controls
82 lines (72 loc) · 2.17 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"GoRedisLite/Logs"
"GoRedisLite/Security"
"GoRedisLite/Security/SecurityEntities"
"GoRedisLite/cmd"
"GoRedisLite/internal"
"GoRedisLite/internal/Entities"
"GoRedisLite/sdk"
server2 "GoRedisLite/server"
"fmt"
"os"
"time"
)
func main() {
fmt.Println(`
_____ _____ _ _ _ _ _
/ ____| | __ \ | (_) | | (_) |
| | __ ___ | |__) |___ __| |_ ___| | _| |_ ___
| | |_ |/ _ \| _ // _ \/ _' | / __| | | | __/ _ \
| |__| | (_) | | \ \ __/ (_| | \__ \ |____| | || __/
\_____|\___/|_| \_\___|\__,_|_|___/______|_|\__\___|
`)
fmt.Println("0.0.1 ")
security, err := Security.NewSecurity("leveldb/databases/users", "leveldb/databases/roles", "leveldb/databases/logs")
if err != nil {
fmt.Println("ERROR OCURRED ")
}
storage := internal.Storage{Values: make(map[interface{}]Entities.RedisValue)}
logs := Logs.Logs{Instructions: &[]Logs.Instruction{}}
server := server2.RedisServer{
Connections: make(map[string]*SecurityEntities.Connection),
}
go server.Start("tcp", ":"+func() string {
if len(os.Args) > 1 {
return os.Args[1]
}
return "8080"
}(), &storage, &logs, security)
//check this because we need to stop exec if not working
security.InitSec()
go func(storage *internal.Storage) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for range ticker.C {
if len(storage.ExpirationValues) < 200 {
for i, expirationValue := range storage.ExpirationValues {
if !expirationValue.Expiration.IsZero() {
if time.Now().After(expirationValue.Expiration) {
storage.DeleteHValue(expirationValue.Route)
storage.ExpirationValues = append(storage.ExpirationValues[:i], storage.ExpirationValues[i+1:]...)
}
}
}
}
}
}(&storage)
conn, err := sdk.Start()
if err != nil {
fmt.Println("Error al conectar con el servidor:", err)
// No continuamos si no podemos conectar
return
}
// Intentamos hacer login
err = sdk.SendMessage(conn, "login anchel 12345")
if err != nil {
fmt.Println("Error al enviar mensaje de login:", err)
} else {
fmt.Println("Respuesta del servidor:")
}
cmd.InitCLI(&storage, &logs, security)
}