-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (36 loc) · 1000 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 (
"fmt"
"net/http"
"os"
"soci-video-cdn/config"
"soci-video-cdn/route"
)
func setupRoutes(settings *config.Config) {
http.Handle("/", http.FileServer(http.Dir("./files/videos")))
http.Handle("/thumbnail/", http.StripPrefix("/thumbnail/", http.FileServer(http.Dir("./files/thumbnails"))))
http.HandleFunc("/upload", route.UploadFile)
http.HandleFunc("/move", route.MoveFile)
http.HandleFunc("/encode", route.Encode)
port := os.Getenv("APP_PORT")
if port == "" {
port = settings.Port
if port == "" {
port = "4204"
}
}
fmt.Printf("Listening on %v\n", port)
http.ListenAndServe(":"+port, nil)
}
func main() {
// parse the config file
if err := config.ParseJSONFile("./config.json", &config.Settings); err != nil {
panic(err)
}
// validate the config file
if err := config.Settings.Validate(); err != nil {
panic(err)
}
fmt.Println("Starting video encoding server...")
setupRoutes(&config.Settings)
}