-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (52 loc) · 1.25 KB
/
main.go
File metadata and controls
61 lines (52 loc) · 1.25 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
package main
import (
"flag"
"fmt"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
)
func main() {
var command string
flag.StringVar(&command, "cmd", "server", "Command to run: server, processor")
flag.Parse()
cfg, err := Load()
if err != nil {
log.Fatal().Err(err).Msg("failed to load config")
}
db, err := NewGORM(cfg)
if err != nil {
log.Fatal().Err(err).Msg("failed to create GORM instance")
}
switch command {
case "api":
runServer()
case "queue":
runProcessor(cfg, db)
default:
fmt.Printf("Unknown command: %s\n", command)
fmt.Println("Available commands: server, processor")
os.Exit(1)
}
}
func runServer() {
log.Info().Msg("Starting HTTP server...")
server, err := NewServer()
if err != nil {
log.Fatal().Err(err).Msg("failed to create server")
}
if err := server.Run(8080); err != nil {
log.Fatal().Err(err).Msg("failed to run server")
}
}
func runProcessor(cfg *Config, db *gorm.DB) {
log.Info().Msg("Starting queue processor...")
processor, err := NewQueueProcessor(cfg, db, &FakeAPI{})
if err != nil {
log.Fatal().Err(err).Msg("failed to create queue processor")
}
if err := processor.Start(); err != nil {
log.Fatal().Err(err).Msg("failed to start queue processor")
}
}