2021-02-23 16:01:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"openmediacenter/apiGo/api"
|
2021-09-16 20:38:28 +00:00
|
|
|
api2 "openmediacenter/apiGo/api/api"
|
2021-09-06 18:20:33 +00:00
|
|
|
"openmediacenter/apiGo/config"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/database"
|
2021-04-02 17:04:15 +00:00
|
|
|
"openmediacenter/apiGo/static"
|
2021-04-18 19:16:38 +00:00
|
|
|
"openmediacenter/apiGo/videoparser"
|
2021-09-21 08:45:52 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2021-02-23 16:01:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println("init OpenMediaCenter server")
|
2021-09-21 08:45:52 +00:00
|
|
|
const port uint16 = 8081
|
2021-09-27 22:36:14 +00:00
|
|
|
errc := make(chan error, 1)
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-09-06 18:20:33 +00:00
|
|
|
config.Init()
|
|
|
|
|
2021-09-09 21:33:04 +00:00
|
|
|
// todo some verbosity logger or sth
|
|
|
|
fmt.Printf("Use verbose output: %t\n", config.GetConfig().General.VerboseLogging)
|
|
|
|
fmt.Printf("Videopath prefix: %s\n", config.GetConfig().General.ReindexPrefix)
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-09-27 22:36:14 +00:00
|
|
|
err := database.InitDB()
|
|
|
|
if err != nil {
|
|
|
|
errc <- err
|
|
|
|
}
|
2021-02-23 16:01:29 +00:00
|
|
|
defer database.Close()
|
|
|
|
|
2021-09-21 08:45:52 +00:00
|
|
|
api.AddHandlers()
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
videoparser.SetupSettingsWebsocket()
|
|
|
|
|
2021-04-02 17:04:15 +00:00
|
|
|
// add the static files
|
|
|
|
static.ServeStaticFiles()
|
|
|
|
|
2021-09-21 08:45:52 +00:00
|
|
|
// init api
|
|
|
|
go func() {
|
|
|
|
errc <- api2.ServerInit(port)
|
|
|
|
}()
|
|
|
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, os.Interrupt)
|
|
|
|
select {
|
|
|
|
case err := <-errc:
|
|
|
|
fmt.Printf("failed to serve: %v\n", err)
|
|
|
|
case sig := <-sigs:
|
|
|
|
fmt.Printf("terminating server: %v\n", sig)
|
|
|
|
}
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|