moq-rs/server/main.go

57 lines
1.2 KiB
Go
Raw Normal View History

2022-06-29 16:17:02 +00:00
package main
import (
"context"
"crypto/tls"
2022-06-29 16:17:02 +00:00
"flag"
"fmt"
"log"
"github.com/kixelated/invoker"
"github.com/kixelated/warp/server/internal/warp"
2022-06-29 16:17:02 +00:00
)
func main() {
err := run(context.Background())
2022-12-05 22:07:58 +00:00
if err != nil {
log.Fatal(err)
2022-06-29 16:17:02 +00:00
}
}
func run(ctx context.Context) (err error) {
2022-11-18 23:13:35 +00:00
addr := flag.String("addr", ":4443", "HTTPS server address")
cert := flag.String("tls-cert", "../cert/localhost.crt", "TLS certificate file path")
key := flag.String("tls-key", "../cert/localhost.key", "TLS certificate file path")
2022-06-29 16:17:02 +00:00
logDir := flag.String("log-dir", "", "logs will be written to the provided directory")
dash := flag.String("dash", "../media/playlist.mpd", "DASH playlist path")
2022-06-29 16:17:02 +00:00
flag.Parse()
media, err := warp.NewMedia(*dash)
if err != nil {
return fmt.Errorf("failed to open media: %w", err)
}
tlsCert, err := tls.LoadX509KeyPair(*cert, *key)
if err != nil {
return fmt.Errorf("failed to load TLS certificate: %w", err)
}
warpConfig := warp.Config{
Addr: *addr,
Cert: &tlsCert,
LogDir: *logDir,
Media: media,
2022-06-29 16:17:02 +00:00
}
warpServer, err := warp.New(warpConfig)
2022-06-29 16:17:02 +00:00
if err != nil {
return fmt.Errorf("failed to create warp server: %w", err)
}
log.Printf("listening on %s", *addr)
return invoker.Run(ctx, invoker.Interrupt, warpServer.Run)
2022-06-29 16:17:02 +00:00
}