-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
45 lines (39 loc) · 919 Bytes
/
http.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
package push_notification
import (
"cloud.google.com/go/functions/metadata"
"dinamo.app/push_notification/response"
"encoding/json"
"fmt"
"log"
"net/http"
)
func HandlerSendPushNotificaction(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
_ = response.HTTPError(w, r, http.StatusBadRequest, "Metodo POST requerido")
return
}
ctx := r.Context()
//
meta, err := metadata.FromContext(ctx)
if err != nil {
fmt.Println("error: ", err)
}
fmt.Println(meta)
fmt.Println(ctx)
fmt.Println(ctx.Value("auth"))
//
data := DataNotification{}
err = json.NewDecoder(r.Body).Decode(&data)
if err != nil {
log.Println(err.Error())
_ = response.HTTPError(w, r, http.StatusBadRequest, err.Error())
return
}
defer r.Body.Close()
err = SendPushNotificaction(ctx, &data)
if err != nil {
log.Println(err.Error())
return
}
_ = response.JSON(w, r, http.StatusBadRequest, "OK")
}