1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 09:12:19 +00:00
ghostream/main.go
2020-11-07 15:02:09 +01:00

60 lines
1.6 KiB
Go

//go:generate pkger
// Package main provides the full-featured server with configuration loading
// and communication between routines.
package main
import (
"log"
"github.com/pkg/profile"
"gitlab.crans.org/nounous/ghostream/auth"
"gitlab.crans.org/nounous/ghostream/internal/config"
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
"gitlab.crans.org/nounous/ghostream/messaging"
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
"gitlab.crans.org/nounous/ghostream/stream/srt"
"gitlab.crans.org/nounous/ghostream/stream/telnet"
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
"gitlab.crans.org/nounous/ghostream/transcoder"
"gitlab.crans.org/nounous/ghostream/web"
)
func main() {
// TODO Don't always profile if not needed
defer profile.Start().Stop()
// Configure logger
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
// Load configuration
cfg, err := config.Load()
if err != nil {
log.Fatalln("Failed to load configuration:", err)
}
// Init authentification
authBackend, err := auth.New(&cfg.Auth)
if err != nil {
log.Fatalln("Failed to load authentification backend:", err)
}
if authBackend != nil {
defer authBackend.Close()
}
// Init streams messaging
streams := messaging.New()
// Start routines
go transcoder.Init(streams, &cfg.Transcoder)
go forwarding.Serve(streams, cfg.Forwarding)
go monitoring.Serve(&cfg.Monitoring)
go srt.Serve(streams, authBackend, &cfg.Srt)
go telnet.Serve(streams, &cfg.Telnet)
go web.Serve(streams, &cfg.Web)
go webrtc.Serve(streams, &cfg.WebRTC)
// Wait for routines
select {}
}