diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-14 16:14:11 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-14 17:02:16 -0600 |
commit | 4c04177c05355ddb92d3d31a4c5cfbaa86555a13 (patch) | |
tree | d40a4dcb70ef84ba9356751a9bd96fed99f7f5d2 /srv/src/api/mailinglist.go | |
parent | dd354bc323cd3176c9676444f99b33b69d0a2062 (diff) |
Move template rendering logic into api package
Diffstat (limited to 'srv/src/api/mailinglist.go')
-rw-r--r-- | srv/src/api/mailinglist.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/srv/src/api/mailinglist.go b/srv/src/api/mailinglist.go index d89fe2a..c12e75d 100644 --- a/srv/src/api/mailinglist.go +++ b/srv/src/api/mailinglist.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutils" + "github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil" "github.com/mediocregopher/blog.mediocregopher.com/srv/mailinglist" ) @@ -16,7 +16,7 @@ func (a *api) mailingListSubscribeHandler() http.Handler { parts[0] == "" || parts[1] == "" || len(email) >= 512 { - apiutils.BadRequest(rw, r, errors.New("invalid email")) + apiutil.BadRequest(rw, r, errors.New("invalid email")) return } @@ -26,11 +26,11 @@ func (a *api) mailingListSubscribeHandler() http.Handler { // just eat the error, make it look to the user like the // verification email was sent. } else if err != nil { - apiutils.InternalServerError(rw, r, err) + apiutil.InternalServerError(rw, r, err) return } - apiutils.JSONResult(rw, r, struct{}{}) + apiutil.JSONResult(rw, r, struct{}{}) }) } @@ -40,25 +40,25 @@ func (a *api) mailingListFinalizeHandler() http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { subToken := r.PostFormValue("subToken") if l := len(subToken); l == 0 || l > 128 { - apiutils.BadRequest(rw, r, errInvalidSubToken) + apiutil.BadRequest(rw, r, errInvalidSubToken) return } err := a.params.MailingList.FinalizeSubscription(subToken) if errors.Is(err, mailinglist.ErrNotFound) { - apiutils.BadRequest(rw, r, errInvalidSubToken) + apiutil.BadRequest(rw, r, errInvalidSubToken) return } else if errors.Is(err, mailinglist.ErrAlreadyVerified) { // no problem } else if err != nil { - apiutils.InternalServerError(rw, r, err) + apiutil.InternalServerError(rw, r, err) return } - apiutils.JSONResult(rw, r, struct{}{}) + apiutil.JSONResult(rw, r, struct{}{}) }) } @@ -68,21 +68,21 @@ func (a *api) mailingListUnsubscribeHandler() http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { unsubToken := r.PostFormValue("unsubToken") if l := len(unsubToken); l == 0 || l > 128 { - apiutils.BadRequest(rw, r, errInvalidUnsubToken) + apiutil.BadRequest(rw, r, errInvalidUnsubToken) return } err := a.params.MailingList.Unsubscribe(unsubToken) if errors.Is(err, mailinglist.ErrNotFound) { - apiutils.BadRequest(rw, r, errInvalidUnsubToken) + apiutil.BadRequest(rw, r, errInvalidUnsubToken) return } else if err != nil { - apiutils.InternalServerError(rw, r, err) + apiutil.InternalServerError(rw, r, err) return } - apiutils.JSONResult(rw, r, struct{}{}) + apiutil.JSONResult(rw, r, struct{}{}) }) } |