57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"git.entr0py.de/garionion/gstreamer-graphix/api"
|
|
"git.entr0py.de/garionion/gstreamer-graphix/gstreamer"
|
|
"github.com/ilyakaznacheev/cleanenv"
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/rs/zerolog/pkgerrors"
|
|
"google.golang.org/grpc"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Outputs []string `yaml:"outputs"`
|
|
Address string `yaml:"address" env:"ADDRESS" env-default:":3000"`
|
|
LogFile string `yaml:"logfile" env:"LOGFILE" env-default:"./gstreamer-graphix.log"`
|
|
}
|
|
|
|
var cfg Config
|
|
|
|
func main() {
|
|
zerolog.TimeFieldFormat = time.RFC1123Z
|
|
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC1123Z}
|
|
log.Logger = log.Output(consoleWriter).With().Timestamp().Caller().Logger()
|
|
|
|
if err := cleanenv.ReadConfig("config.toml", &cfg); err != nil {
|
|
log.Fatal().Msgf("No configfile: ", err)
|
|
}
|
|
|
|
fset := flag.NewFlagSet("config", flag.ContinueOnError)
|
|
fset.Usage = cleanenv.FUsage(fset.Output(), &cfg, nil, fset.Usage)
|
|
fset.Parse(os.Args[1:])
|
|
|
|
l, err := os.OpenFile(cfg.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
|
|
multi := zerolog.MultiLevelWriter(consoleWriter, l)
|
|
log.Logger = zerolog.New(multi).With().Timestamp().Caller().Logger()
|
|
|
|
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
|
|
|
|
ln, err := net.Listen("tcp", cfg.Address)
|
|
if err != nil {
|
|
log.Fatal().Err(err)
|
|
}
|
|
|
|
gst := gstreamer.Init()
|
|
|
|
pipelineService := &api.PipelineService{Gstreamer: gst}
|
|
|
|
g := grpc.NewServer()
|
|
api.RegisterPipelineServiceServer(g, pipelineService)
|
|
|
|
log.Fatal().Msgf("Failed to serve: %v", g.Serve(ln))
|
|
}
|