/
routes.go
38 lines (31 loc) · 895 Bytes
/
routes.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/asvins/notification/mailer"
"github.com/asvins/router"
"github.com/asvins/router/errors"
)
func DefRoutes() *router.Router {
r := router.NewRouter()
r.Handle("/api/discovery", router.GET, func(w http.ResponseWriter, r *http.Request) errors.Http {
fmt.Fprint(w, "NOTIFICATION MODULE - TODO")
return nil
}, []router.Interceptor{})
r.Handle("/api/mailTest", router.GET, func(w http.ResponseWriter, r *http.Request) errors.Http {
m := mailer.Mail{
To: []string{"asvins.poli@gmail.com"},
Subject: "Está na hora de tomar sua medicação!",
Body: mailer.TemplatePackTime,
}
b, err := json.Marshal(&m)
if err != nil {
return errors.BadRequest(err.Error())
}
producer.Publish("send_mail", b)
fmt.Fprintf(w, "[INFO] Email sent")
return nil
}, []router.Interceptor{})
return r
}