-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 773 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/RoyXiang/plexproxy/common"
"github.com/RoyXiang/plexproxy/handler"
)
var (
Version string
)
func main() {
srv := &http.Server{
Addr: "0.0.0.0:5000",
Handler: handler.NewRouter(),
}
go func() {
if err := srv.ListenAndServe(); err != nil {
common.GetLogger().Println(err)
}
}()
common.GetLogger().Printf("plexproxy started on :5000 (version=%q)", Version)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-c
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
_ = srv.Shutdown(ctx)
common.GetLogger().Println("Shutting down...")
os.Exit(0)
}