-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (40 loc) · 1.01 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
49
package main
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/steveyiyo/url-shortener/internal/cache"
"github.com/steveyiyo/url-shortener/internal/database"
"github.com/steveyiyo/url-shortener/internal/webserver"
"github.com/steveyiyo/url-shortener/pkg/tools"
)
func main() {
// Load .env
err := godotenv.Load()
if err != nil {
log.Println("Error loading .env file")
}
// Define Config
Listen := os.Getenv("Listen")
Host := os.Getenv("Host")
Port := os.Getenv("Port")
URL := Host + ":" + Port + "/"
Redis_Addr := os.Getenv("Redis_Addr")
Redis_Pwd := os.Getenv("Redis_Pwd")
fmt.Println(Redis_Addr)
if Listen == "" || Host == "" || Port == "" || Redis_Addr == "" {
log.Fatal("Error to loading environment.")
}
// Check Config
if tools.CheckIPAddress(Listen) {
// Init Redis
cache.InitRedis(Redis_Addr, Redis_Pwd)
// Init Database
database.Init()
// Init Web Server
webserver.Init(Listen, Host, Port, URL)
} else {
log.Fatal("Error: Listen IP Address is not valid")
}
}