Skip to content

Commit

Permalink
Store email address for optional status change alert
Browse files Browse the repository at this point in the history
  • Loading branch information
cpjolicoeur committed May 7, 2015
1 parent 67565ca commit 27d3f12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions handlers.go
Expand Up @@ -59,6 +59,7 @@ func createStatusHandler(c *echo.Context) *echo.HTTPError {
}

params.URL = strings.TrimSpace(params.URL)
params.Email = strings.TrimSpace(params.Email)

if 0 == len(strings.TrimSpace(params.URL)) {
return c.JSON(http.StatusBadRequest, "URL parameter required")
Expand All @@ -72,6 +73,14 @@ func createStatusHandler(c *echo.Context) *echo.HTTPError {
return handleError(http.StatusInternalServerError, "Problem saving your new site", err)
}

// See NOTE above about ignoring the bool return value here as well
if len(params.Email) > 0 {
_, err = redisClient.Hset(redisScopedKey(emailsRedisKey), params.URL, []byte(params.Email))
if err != nil {
return handleError(http.StatusInternalServerError, "Problem saving your site email address to alert", err)
}
}

return c.JSON(http.StatusCreated, &Site{URL: params.URL})
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -12,7 +12,8 @@ import (
)

const (
sitesRedisKey = "sites"
sitesRedisKey = "sites"
emailsRedisKey = "site-emails"
)

var (
Expand Down

0 comments on commit 27d3f12

Please sign in to comment.