48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.ostiwe.com/ostiwe-com/status/model"
|
|
"git.ostiwe.com/ostiwe-com/status/modules/db"
|
|
appLog "git.ostiwe.com/ostiwe-com/status/modules/log"
|
|
"git.ostiwe.com/ostiwe-com/status/modules/queue"
|
|
"git.ostiwe.com/ostiwe-com/status/pkg/args"
|
|
"git.ostiwe.com/ostiwe-com/status/router"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func Run(serverArgs *args.ServerCmd) {
|
|
connect, err := db.Connect()
|
|
if err != nil {
|
|
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed connect to database: %v", err))
|
|
return
|
|
}
|
|
|
|
db.SetGlobal(connect)
|
|
appLog.Global.Get(appLog.SYSTEM).Info("Run db migration")
|
|
if err = runMigrate(); err != nil {
|
|
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Migration failed, error: %v", err))
|
|
return
|
|
}
|
|
|
|
appLog.Global.Get(appLog.SYSTEM).Info("Start service observer")
|
|
go queue.InitQueues()
|
|
|
|
appLog.Global.Put(appLog.SERVER, logrus.New())
|
|
appLog.Global.Get(appLog.SERVER).Info("Startup server on port: ", serverArgs.Port)
|
|
|
|
err = http.ListenAndServe(fmt.Sprintf(":%s", serverArgs.Port), router.InitRoutes())
|
|
if err != nil {
|
|
appLog.Global.Get(appLog.SERVER).Error(fmt.Sprintf("Startup server error: %v", err))
|
|
}
|
|
}
|
|
|
|
func runMigrate() error {
|
|
return db.Global.AutoMigrate(
|
|
model.Service{},
|
|
model.Status{},
|
|
)
|
|
}
|