forked from archway-network/valuter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (43 loc) · 1.2 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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/celestiaorg/cosmologger/database"
"github.com/celestiaorg/valuter/api"
"github.com/celestiaorg/valuter/cmd"
"github.com/celestiaorg/valuter/configs"
"github.com/celestiaorg/valuter/simplecache"
)
/*--------------*/
// const ENV_FILE = "../.env"
func main() {
// if err := godotenv.Load(ENV_FILE); err != nil {
// log.Warn("loading environment file `%s`: %v", ENV_FILE, err)
// }
/*-------------*/
configs.Init()
/*-------------*/
rootPath, err := os.Getwd()
if err != nil {
rootPath = "/tmp/"
}
cachePath := filepath.Join(rootPath, "cache-dir")
simplecache.SetConfig(simplecache.Config{StorePath: cachePath})
psqlconn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
os.Getenv("POSTGRES_HOST"),
os.Getenv("POSTGRES_PORT"),
os.Getenv("POSTGRES_USER"),
os.Getenv("POSTGRES_PASSWORD"),
os.Getenv("POSTGRES_DB"),
)
database.DB = database.New(database.Postgres, psqlconn)
defer database.DB.Close()
// Run the command only if there is input arguments
if len(os.Args) > 1 {
cmd.Execute()
return
}
// Otherwise start the API server
api.ListenAndServeHTTP(os.Getenv("SERVING_ADDR"))
}