-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
executable file
·109 lines (90 loc) · 2.56 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/gallynaut/gocrypto-api/store"
"github.com/gorilla/mux"
"github.com/spf13/viper"
)
type appConfig struct {
DB struct {
Hostname string `json:"hostname" mapstructure:"hostname"`
Username string `json:"username" mapstructure:"username"`
Password string `json:"password" mapstructure:"password"`
DBName string `json:"dbName" mapstructure:"dbName"`
} `json:"db" mapstructure:"db"`
API struct {
Port uint `json:"port" mapstructure:"port"`
} `json:"api" mapstructure:"api"`
Solana struct {
PrivateKey []byte `json:"privKey" mapstructure:"privKey"`
Network string `json:"network" mapstructure:"network"`
AccountPollRate uint `json:"accountPollRate" mapstructure:"accountPollRate"`
} `json:"solana" mapstructure:"solana"`
FTX struct {
ApiKey string `json:"apiKey" mapstructure:"apiKey"`
Secret string `json:"secret" mapstructure:"secret"`
} `json:"ftx" mapstructure:"ftx"`
CW struct {
PublicKey string `json:"pubKey" mapstructure:"pubKey"`
Secret string `json:"secret" mapstructure:"secret"`
URL string `json:"url" mapstructure:"url"`
} `json:"cryptoWatch" mapstructure:"cryptoWatch"`
}
type App struct {
Router *mux.Router
Store store.StoreApp
Solana SolanaApp
FTX FTXApp
Gecko GeckoApp
CW CWApp
cfg appConfig
ctx context.Context
}
func main() {
a := App{}
var cancel context.CancelFunc
a.ctx, cancel = context.WithCancel(context.Background())
go func() {
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt)
oscall := <-done
log.Printf("system call:%+v", oscall)
cancel()
}()
var err error
a.cfg, err = loadConfig("config.yml")
if err != nil {
log.Fatal("cannot load config:", err)
}
a.initialize(a.cfg)
// go a.getGoogleTrends("solana")
// go a.CW.getCandles()
// start api
a.RunAPI(a.ctx.Done())
log.Println("shutting down")
os.Exit(0)
}
func loadConfig(path string) (config appConfig, err error) {
viper.SetConfigFile(path)
// viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
return
}
err = viper.Unmarshal(&config)
return
}
func (a *App) initialize(config appConfig) {
// database and api routes
// a.Store = store.InitializeDB(config.DB.Hostname, config.DB.Username, config.DB.Password, config.DB.DBName)
a.initializeRoutes()
// intitialize data feeds
// a.initializeCW(config.CW.PublicKey)
a.initializeGecko()
// a.initializeFTX(config.FTX.ApiKey, config.FTX.Secret)
// solana keys, rpc, and websocket
// a.initializeSolana(config.Solana.Network, config.Solana.PrivateKey)
}