-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 905 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/j1nxie/closure-api/v2/routes"
_ "github.com/joho/godotenv/autoload"
)
func main() {
addr := os.Getenv("SERVER_ADDRESS")
var port string
if port = os.Getenv("SERVER_PORT"); port == "" {
port = "3333"
} else {
port = os.Getenv("SERVER_PORT")
}
listenAddr := fmt.Sprintf("%v:%v", addr, port)
log.Printf("closure listening on %v", listenAddr)
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Get("/api/status", routes.GetStatus)
r.Get("/api/event", routes.GetEvent)
r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "assets/favicon.ico")
})
if err := http.ListenAndServe(listenAddr, r); err != nil {
log.Fatal(err)
}
}