-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (35 loc) · 1.06 KB
/
main.go
File metadata and controls
40 lines (35 loc) · 1.06 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
package main
import (
"log"
"strings"
"tiny-url-service/config"
"tiny-url-service/handlers"
"tiny-url-service/storage"
)
func main() {
// Load configuration from environment variables
cfg := config.Load()
// Initialize storage based on configuration
var store storage.Storage
var err error
switch strings.ToLower(cfg.StorageType) {
case "redis":
log.Println("Initializing Redis storage...")
store, err = storage.NewRedisStorage(cfg.BaseURL, cfg.RedisURL)
if err != nil {
log.Fatal("Failed to initialize Redis storage:", err)
}
log.Println("Redis storage initialized successfully")
case "memory":
log.Println("Initializing in-memory storage...")
store = storage.NewMemoryStorage(cfg.BaseURL)
log.Println("In-memory storage initialized successfully")
default:
log.Fatalf("Unknown storage type: %s. Supported types: memory, redis", cfg.StorageType)
}
// Start HTTP server with graceful shutdown
log.Println("Starting Tiny URL Service...")
if err := handlers.StartServer(store, cfg); err != nil {
log.Fatal("Failed to start server:", err)
}
}