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/csrf.go | |
parent | dd354bc323cd3176c9676444f99b33b69d0a2062 (diff) |
Move template rendering logic into api package
Diffstat (limited to 'srv/src/api/csrf.go')
-rw-r--r-- | srv/src/api/csrf.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/srv/src/api/csrf.go b/srv/src/api/csrf.go index 13b6ec6..9717030 100644 --- a/srv/src/api/csrf.go +++ b/srv/src/api/csrf.go @@ -4,7 +4,7 @@ import ( "errors" "net/http" - "github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutils" + "github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutil" ) const ( @@ -15,16 +15,16 @@ const ( func setCSRFMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - csrfTok, err := apiutils.GetCookie(r, csrfTokenCookieName, "") + csrfTok, err := apiutil.GetCookie(r, csrfTokenCookieName, "") if err != nil { - apiutils.InternalServerError(rw, r, err) + apiutil.InternalServerError(rw, r, err) return } else if csrfTok == "" { http.SetCookie(rw, &http.Cookie{ Name: csrfTokenCookieName, - Value: apiutils.RandStr(32), + Value: apiutil.RandStr(32), Secure: true, }) } @@ -36,10 +36,10 @@ func setCSRFMiddleware(h http.Handler) http.Handler { func checkCSRFMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - csrfTok, err := apiutils.GetCookie(r, csrfTokenCookieName, "") + csrfTok, err := apiutil.GetCookie(r, csrfTokenCookieName, "") if err != nil { - apiutils.InternalServerError(rw, r, err) + apiutil.InternalServerError(rw, r, err) return } @@ -49,7 +49,7 @@ func checkCSRFMiddleware(h http.Handler) http.Handler { } if csrfTok == "" || givenCSRFTok != csrfTok { - apiutils.BadRequest(rw, r, errors.New("invalid CSRF token")) + apiutil.BadRequest(rw, r, errors.New("invalid CSRF token")) return } |