forked from OdyseeTeam/chainquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.go
48 lines (41 loc) · 1.25 KB
/
serve.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
package cmd
import (
"log"
"github.com/lbryio/chainquery/apiactions"
"github.com/lbryio/chainquery/config"
"github.com/lbryio/chainquery/daemon"
"github.com/lbryio/chainquery/db"
"github.com/lbryio/chainquery/lbrycrd"
swagger "github.com/lbryio/chainquery/swagger/apiserver"
"github.com/lbryio/chainquery/twilio"
"github.com/pkg/profile"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
rootCmd.AddCommand(serveCmd)
}
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Run Daemon routines and the API Server",
Long: `Run Daemon routines and the API Server, check github.com/lbryio/chainquery#what-does-chainquery-consist-of`,
Args: cobra.OnlyValidArgs,
Run: func(cmd *cobra.Command, args []string) {
if viper.GetBool("codeprofile") {
defer profile.Start(profile.NoShutdownHook).Stop()
}
config.InitSlack()
twilio.InitTwilio()
apiactions.AutoUpdateCommand = config.GetAutoUpdateCommand()
//Main Chainquery DB connection
dbInstance, err := db.Init(config.GetMySQLDSN(), config.GetDebugQueryMode())
if err != nil {
log.Panic(err)
}
defer db.CloseDB(dbInstance)
lbrycrdClient := lbrycrd.Init()
defer lbrycrdClient.Shutdown()
go swagger.InitApiServer(config.GetAPIHostAndPort())
daemon.DoYourThing()
},
}