-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
50 lines (38 loc) · 1.07 KB
/
server.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
47
48
49
50
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/joho/godotenv"
)
// our main function
func main() {
fmt.Println("Starting...")
e := godotenv.Load() //Load .env file
if e != nil {
fmt.Println(e)
}
if compose := os.Getenv("indocker"); compose == "dockercompose" {
fmt.Println("Sleeping for 5 to wait for DB")
time.Sleep(time.Second * 5)
}
if needsAuth := os.Getenv("NEEDS_AUTH"); needsAuth == "yes" {
fmt.Println("Readying DB")
readyDB()
}
port := os.Getenv("PORT")
router := mux.NewRouter()
router.Use(jwtAuthentication)
router.HandleFunc("/api/user/new", createAccount).Methods("POST")
router.HandleFunc("/api/user/login", authenticate).Methods("POST")
router.HandleFunc("/api/quote", quoteResponse).Methods("GET")
router.HandleFunc("/api/quote/fr", quoteResponseFrench).Methods("GET")
p := fmt.Sprintf(":%v", port)
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
log.Fatal(http.ListenAndServe(p, loggedRouter))
}