This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve.go
62 lines (47 loc) · 1.52 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd
import (
"log"
"net/http"
"github.com/dlmiddlecote/sqlstats"
"github.com/factly/mande-server/action"
"github.com/factly/mande-server/model"
"github.com/factly/mande-server/util/razorpay"
"github.com/factly/x/meilisearchx"
"github.com/go-chi/chi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
rootCmd.AddCommand(serveCmd)
}
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Starts server for mande-server.",
Run: func(cmd *cobra.Command, args []string) {
// db setup
model.SetupDB()
meilisearchx.SetupMeiliSearch("mande", []string{"name", "slug", "description", "title", "contact_name", "contact_email", "license", "caption", "alt_text", "plan_name", "plan_info"})
razorpay.SetupClient()
// register routes
userRouter := action.RegisterUserRoutes()
adminRouter := action.RegisterAdminRoutes()
webhookRouter := action.RegisterWebHookRoutes()
go func() {
promRouter := chi.NewRouter()
sqlDB, _ := model.DB.DB()
collector := sqlstats.NewStatsCollector(viper.GetString("database_name"), sqlDB)
prometheus.MustRegister(collector)
promRouter.Mount("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8001", promRouter))
}()
go func() {
log.Fatal(http.ListenAndServe(":8002", userRouter))
}()
go func() {
log.Fatal(http.ListenAndServe(":8003", webhookRouter))
}()
log.Fatal(http.ListenAndServe(":8000", adminRouter))
},
}