-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (27 loc) · 808 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
package main
import (
"fmt"
"github.com/gorilla/mux"
"log"
"net/http"
"os"
"github.com/tfonfara/plexsmarthome/app"
"github.com/tfonfara/plexsmarthome/constants"
"github.com/tfonfara/plexsmarthome/plex"
)
func main() {
log.Printf("=== Welcome to PlexSmartHome ===\n")
log.Printf("Container version %s\n", constants.Version)
eh := app.NewEventHandler()
wh := plex.NewWebhook(eh.WebhookHandler)
r := mux.NewRouter()
r.HandleFunc("/", wh.Handler).Methods(http.MethodPost)
r.HandleFunc("/health", healthHandler).Methods(http.MethodGet)
port := os.Getenv("PLEX_PORT")
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), r); err != nil {
log.Fatalf("Error starting container: %v\n", err)
}
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}