mirror of
https://github.com/pushbits/server.git
synced 2025-06-13 16:12:01 +02:00
Initialize repository
This commit is contained in:
commit
1d758fcfd0
28 changed files with 1107 additions and 0 deletions
53
app.go
Normal file
53
app.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/eikendev/pushbits/configuration"
|
||||
"github.com/eikendev/pushbits/database"
|
||||
"github.com/eikendev/pushbits/dispatcher"
|
||||
"github.com/eikendev/pushbits/router"
|
||||
"github.com/eikendev/pushbits/runner"
|
||||
)
|
||||
|
||||
func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-c
|
||||
dp.Close()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Starting PushBits.")
|
||||
|
||||
c := configuration.Get()
|
||||
|
||||
db, err := database.Create(c.Database.Dialect, c.Database.Connection)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if err := db.Populate(c.Admin.Name, c.Admin.Password, c.Admin.MatrixID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dp, err := dispatcher.Create(db, c.Matrix.Homeserver, c.Matrix.Username, c.Matrix.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer dp.Close()
|
||||
|
||||
setupCleanup(db, dp)
|
||||
|
||||
engine := router.Create(db, dp)
|
||||
runner.Run(engine)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue