better logging
This commit is contained in:
parent
d9c49ae508
commit
8de5cc89c5
3 changed files with 11 additions and 14 deletions
|
@ -15,12 +15,6 @@ import (
|
||||||
|
|
||||||
var contactEmailT *template.Template
|
var contactEmailT *template.Template
|
||||||
|
|
||||||
// EmailContact describes an email EmailContact
|
|
||||||
type EmailContact struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
contactEmailT = template.Must(template.New("contactEmail").Parse(contactEmailTemplate))
|
contactEmailT = template.Must(template.New("contactEmail").Parse(contactEmailTemplate))
|
||||||
}
|
}
|
||||||
|
@ -30,10 +24,12 @@ type Contact struct {
|
||||||
*revel.Controller
|
*revel.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request handles a customer contact request
|
// ContactRequest handles a customer contact request
|
||||||
func (c Contact) Request(name, email string) revel.Result {
|
func (c Contact) ContactRequest(name, email string) revel.Result {
|
||||||
|
|
||||||
emailBody, err := renderContactEmail(name, email)
|
c.Log.Info("received contact request", "name", name, "email", email, "source", c.ClientIP)
|
||||||
|
|
||||||
|
emailBody, err := c.renderContactEmail(name, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Controller.RenderError(errors.Wrap(err, "failed to render email for contact request"))
|
return c.Controller.RenderError(errors.Wrap(err, "failed to render email for contact request"))
|
||||||
}
|
}
|
||||||
|
@ -43,7 +39,7 @@ func (c Contact) Request(name, email string) revel.Result {
|
||||||
Name: "CyCore Systems, Inc",
|
Name: "CyCore Systems, Inc",
|
||||||
Email: "sys@cycoresys.com",
|
Email: "sys@cycoresys.com",
|
||||||
},
|
},
|
||||||
To: getEmailContacts(),
|
To: c.getEmailContacts(),
|
||||||
Subject: "Contact Request",
|
Subject: "Contact Request",
|
||||||
HTMLContent: emailBody,
|
HTMLContent: emailBody,
|
||||||
Tags: []string{"contact-request"},
|
Tags: []string{"contact-request"},
|
||||||
|
@ -56,7 +52,7 @@ func (c Contact) Request(name, email string) revel.Result {
|
||||||
return c.Redirect(routes.App.Index())
|
return c.Redirect(routes.App.Index())
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderContactEmail(name, email string) (string, error) {
|
func (c Contact) renderContactEmail(name, email string) (string, error) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := contactEmailT.Execute(buf, struct {
|
err := contactEmailT.Execute(buf, struct {
|
||||||
Name string
|
Name string
|
||||||
|
@ -73,12 +69,13 @@ func renderContactEmail(name, email string) (string, error) {
|
||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEmailContacts() []sendinblue.Address {
|
func (c Contact) getEmailContacts() []sendinblue.Address {
|
||||||
|
|
||||||
var ret []sendinblue.Address
|
var ret []sendinblue.Address
|
||||||
if err := json.Unmarshal([]byte(os.Getenv("CONTACT_RECIPIENTS")), &ret); err != nil {
|
if err := json.Unmarshal([]byte(os.Getenv("CONTACT_RECIPIENTS")), &ret); err != nil {
|
||||||
|
|
||||||
// Fall back to default if we fail to load from environment
|
// Fall back to default if we fail to load from environment
|
||||||
|
c.Log.Warn("failed to load recipients from environment", "error", err)
|
||||||
ret = append(ret, sendinblue.Address{
|
ret = append(ret, sendinblue.Address{
|
||||||
Name: "System Receiver",
|
Name: "System Receiver",
|
||||||
Email: "sys@cycoresys.com",
|
Email: "sys@cycoresys.com",
|
||||||
|
|
|
@ -20,7 +20,7 @@ app.behind.proxy = false
|
||||||
|
|
||||||
|
|
||||||
# The IP address on which to listen.
|
# The IP address on which to listen.
|
||||||
http.addr =
|
http.addr = 0.0.0.0
|
||||||
|
|
||||||
# The port on which to listen.
|
# The port on which to listen.
|
||||||
http.port = 9000
|
http.port = 9000
|
||||||
|
|
|
@ -7,7 +7,7 @@ module:testrunner
|
||||||
GET / App.Index
|
GET / App.Index
|
||||||
|
|
||||||
# Handle contact requests
|
# Handle contact requests
|
||||||
POST /contact/request Contact.Request
|
POST /contact/request Contact.ContactRequest
|
||||||
|
|
||||||
# Ignore favicon requests
|
# Ignore favicon requests
|
||||||
GET /favicon.ico 404
|
GET /favicon.ico 404
|
||||||
|
|
Loading…
Reference in a new issue