-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
46 lines (35 loc) · 906 Bytes
/
application.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
46
package main
import (
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
handler "github.com/warrenb95/website/internal/http"
)
func main() {
// AWS Elastic Beanstalk runs off port 5000.
port := os.Getenv("PORT")
if port == "" {
port = "5000"
}
// Save the logs here for AWS Elastic Beanstalk.
if os.Getenv("ENV") == "PRODUCTION" {
f, _ := os.Create("/var/log/blog.log")
defer f.Close()
log.SetOutput(f)
}
log := logrus.New()
s := handler.NewServer("eu-west-2", log)
r := mux.NewRouter()
// Middleware.
r.Use(s.Logger)
fs := http.FileServer(http.Dir("assets"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
// Server handlers.
r.HandleFunc("/", s.Index)
r.HandleFunc("/about", s.About)
r.HandleFunc("/blog/{title}", s.Show)
log.Printf("Listening on port %s\n\n", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}