-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 1.21 KB
/
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
package main
import (
"fmt"
"log"
"net/http"
"time"
database "github.com/kozr/stalk/database"
rsakey "github.com/kozr/stalk/rsakey"
web_server "github.com/kozr/stalk/web_server"
)
func main() {
if err := initServices(); err != nil {
log.Fatalf("Failed to initialize services: %v", err)
}
defer cleanup()
// Setup HTTP server
http.HandleFunc("/public-key", web_server.PublicKeyHandler)
http.HandleFunc("/establish-connection", web_server.EstablishConnectionHandler)
log.Println("Starting server on :8080...")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}
func initServices() error {
var err error
if err = rsakey.Init(); err != nil {
return fmt.Errorf("rsa key service initialization failed: %w", err)
}
if err = database.Init(); err != nil {
return fmt.Errorf("database initialization failed: %w", err)
}
rotationService := rsakey.GetRotationService()
rotationService.SetRotationInterval(time.Hour * 24)
rotationService.SetMaxKeyAge(time.Hour * 24 * 2)
if err = rotationService.StartKeyRotation(); err != nil {
return fmt.Errorf("key rotation service failed to start: %w", err)
}
return nil
}
func cleanup() {
database.DB.Close()
}