-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (49 loc) · 1.27 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"log"
"os"
"strconv"
"github.com/gin-gonic/gin"
"github.com/hoomaac/vertex/api"
"github.com/hoomaac/vertex/models"
"github.com/hoomaac/vertex/pkg/config"
"github.com/hoomaac/vertex/pkg/database"
"github.com/hoomaac/vertex/pkg/redis"
"github.com/joho/godotenv"
)
func init() {
env := godotenv.Load()
if env != nil {
log.Fatal("could not read env file")
}
dbInfo := &config.DataBaseConfig{
Username: os.Getenv("DB_USERNAME"),
Password: os.Getenv("DB_PASSWORD"),
Ip: os.Getenv("DB_IP"),
Port: os.Getenv("DB_PORT"),
Name: os.Getenv("DB_NAME"),
}
redisDb, err := strconv.Atoi(os.Getenv("REDIS_DB"))
if err != nil {
log.Fatalf("redisdb is mistyped, %v\n", err)
}
redisConf := &config.RedisConfig{
Ip: os.Getenv("REDIS_IP"),
Port: os.Getenv("REDIS_PORT"),
Password: os.Getenv("REDIS_PASSWORD"),
Database: redisDb,
}
database.InitDb(dbInfo)
redis.InitRedis(redisConf)
// migrate each model here
database.Migrate(&models.User{})
database.Migrate(&models.Good{})
}
func main() {
// Start the engine and read configs from .env file
engine := api.StartEngine(gin.DebugMode)
port := os.Getenv("VERTEX_PORT")
addr := os.Getenv("VERTEX_ADDR")
engine.Run(fmt.Sprintf("%s:%s", addr, port))
}