-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (35 loc) · 938 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
43
44
45
// Copyright (c) Warner Media, LLC. All rights reserved. Licensed under the MIT license.
// See the LICENSE file for license information.
package main
import (
"fmt"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", defaultHandler)
r.HandleFunc("/health", defaultHandler)
http.Handle("/", r)
var port = getenv("PORT", "8001")
fmt.Println("Listening on: " + port)
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
if os.Getenv("ENABLE_LOGGING") == "true" {
fmt.Println("Logging enabled")
http.ListenAndServe(":"+port, loggedRouter)
} else {
http.ListenAndServe(":"+port, nil)
}
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("This is the Fargate default backend."))
}
func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}