-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 817 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
package main
import (
"log"
"net/http"
"github.com/danilomarques1/gos3example/api/controller"
"github.com/joho/godotenv"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal(err)
}
userController, err := controller.NewUserController()
if err != nil {
log.Fatal(err)
}
http.HandleFunc("/user", applicationJson(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
userController.Save(w, r)
case http.MethodGet:
userController.FindByEmail(w, r)
}
}))
log.Printf("server running on port 8080\n")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func applicationJson(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
h.ServeHTTP(w, r)
}
}