-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 850 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"
"net/http"
"os"
"example.com/m/v2/database"
"example.com/m/v2/handlers"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func loadENVs() {
if err := godotenv.Load(); err != nil {
fmt.Print("\nNo .env file found")
}
}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"message": "Welcome to the Flutter Task App API!"}`))
}
func main() {
loadENVs()
client := database.Connect()
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
handlers.SetUpHandlers(r, client)
port, exists := os.LookupEnv("PORT")
if exists {
fmt.Printf("\nListening on PORT " + port)
http.ListenAndServe(":"+port, r)
} else {
fmt.Printf("\nListening on PORT 3000")
http.ListenAndServe(":3000", r)
}
}