@@ -15,7 +15,6 @@ import (
1515 "time"
1616
1717 "github.com/go-chi/chi/v5"
18- "github.com/go-chi/render"
1918 "github.com/go-pkgz/auth/v2"
2019 "github.com/go-pkgz/auth/v2/token"
2120 cache "github.com/go-pkgz/lcw/v2"
@@ -77,7 +76,7 @@ func (s *private) previewCommentCtrl(w http.ResponseWriter, r *http.Request) {
7776 user := rest .MustGetUserInfo (r )
7877
7978 comment := store.Comment {}
80- if err := render . DecodeJSON (http .MaxBytesReader (w , r .Body , hardBodyLimit ), & comment ); err != nil {
79+ if err := json . NewDecoder (http .MaxBytesReader (w , r .Body , hardBodyLimit )). Decode ( & comment ); err != nil {
8180 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't bind comment" , rest .ErrDecode )
8281 return
8382 }
@@ -100,14 +99,13 @@ func (s *private) previewCommentCtrl(w http.ResponseWriter, r *http.Request) {
10099 return
101100 }
102101 }
103-
104- render .HTML (w , r , comment .Text )
102+ rest .HTMLResponse (w , http .StatusOK , comment .Text )
105103}
106104
107105// POST /comment - adds comment, resets all immutable fields
108106func (s * private ) createCommentCtrl (w http.ResponseWriter , r * http.Request ) {
109107 comment := store.Comment {}
110- if err := render . DecodeJSON (http .MaxBytesReader (w , r .Body , hardBodyLimit ), & comment ); err != nil {
108+ if err := json . NewDecoder (http .MaxBytesReader (w , r .Body , hardBodyLimit )). Decode ( & comment ); err != nil {
111109 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't bind comment" , rest .ErrDecode )
112110 return
113111 }
@@ -176,8 +174,8 @@ func (s *private) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
176174
177175 log .Printf ("[DEBUG] created comment %+v" , finalComment )
178176
179- render . Status ( r , http .StatusCreated )
180- render . JSON ( w , r , & finalComment )
177+ w . WriteHeader ( http .StatusCreated )
178+ R . RenderJSON ( w , & finalComment )
181179}
182180
183181// PUT /comment/{id}?site=siteID&url=post-url - update comment
@@ -188,7 +186,7 @@ func (s *private) updateCommentCtrl(w http.ResponseWriter, r *http.Request) {
188186 Delete bool
189187 }{}
190188
191- if err := render . DecodeJSON (http .MaxBytesReader (w , r .Body , hardBodyLimit ), & edit ); err != nil {
189+ if err := json . NewDecoder (http .MaxBytesReader (w , r .Body , hardBodyLimit )). Decode ( & edit ); err != nil {
192190 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't read comment details from body" , rest .ErrDecode )
193191 return
194192 }
@@ -233,7 +231,7 @@ func (s *private) updateCommentCtrl(w http.ResponseWriter, r *http.Request) {
233231 }
234232
235233 s .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .SiteID , locator .URL , lastCommentsScope , user .ID ))
236- render . JSON ( w , r , res )
234+ R . RenderJSON ( w , res )
237235}
238236
239237// GET /user?site=siteID - returns user info
@@ -251,7 +249,7 @@ func (s *private) userInfoCtrl(w http.ResponseWriter, r *http.Request) {
251249 }
252250 }
253251
254- render . JSON ( w , r , user )
252+ R . RenderJSON ( w , user )
255253}
256254
257255// PUT /vote/{id}?site=siteID&url=post-url&vote=1 - vote for/against comment
@@ -292,7 +290,7 @@ func (s *private) voteCtrl(w http.ResponseWriter, r *http.Request) {
292290 return
293291 }
294292 s .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .URL , comment .User .ID ))
295- render . JSON ( w , r , R.JSON {"id" : comment .ID , "score" : comment .Score })
293+ R . RenderJSON ( w , R.JSON {"id" : comment .ID , "score" : comment .Score })
296294}
297295
298296// getEmailCtrl gets email address for authenticated user.
@@ -305,7 +303,7 @@ func (s *private) getEmailCtrl(w http.ResponseWriter, r *http.Request) {
305303 log .Printf ("[WARN] can't read email for %s, %v" , user .ID , err )
306304 }
307305
308- render . JSON ( w , r , R.JSON {"user" : user , "address" : address })
306+ R . RenderJSON ( w , R.JSON {"user" : user , "address" : address })
309307}
310308
311309// sendEmailConfirmationCtrl gets address and siteID from query, makes confirmation token and sends it to user.
@@ -322,7 +320,7 @@ func (s *private) sendEmailConfirmationCtrl(w http.ResponseWriter, r *http.Reque
322320 Address string
323321 autoConfirm bool
324322 }{autoConfirm : true }
325- if err := render . DecodeJSON (http .MaxBytesReader (w , r .Body , hardBodyLimit ), & subscribe ); err != nil {
323+ if err := json . NewDecoder (http .MaxBytesReader (w , r .Body , hardBodyLimit )). Decode ( & subscribe ); err != nil {
326324 if err != io .EOF {
327325 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't parse request body" , rest .ErrDecode )
328326 return
@@ -385,7 +383,7 @@ func (s *private) sendEmailConfirmationCtrl(w http.ResponseWriter, r *http.Reque
385383 },
386384 )
387385
388- render . JSON ( w , r , R.JSON {"user" : user , "address" : subscribe .Address , "updated" : false })
386+ R . RenderJSON ( w , R.JSON {"user" : user , "address" : subscribe .Address , "updated" : false })
389387}
390388
391389// telegramSubscribeCtrl generates and verifies telegram notification request
@@ -423,7 +421,7 @@ func (s *private) telegramSubscribeCtrl(w http.ResponseWriter, r *http.Request)
423421
424422 s .telegramService .AddToken (tkn , user .ID , siteID , expires )
425423
426- render . JSON ( w , r , R.JSON {"token" : tkn , "bot" : s .telegramService .GetBotUsername ()})
424+ R . RenderJSON ( w , R.JSON {"token" : tkn , "bot" : s .telegramService .GetBotUsername ()})
427425
428426 return
429427 }
@@ -445,7 +443,7 @@ func (s *private) telegramSubscribeCtrl(w http.ResponseWriter, r *http.Request)
445443 return
446444 }
447445
448- render . JSON ( w , r , R.JSON {"updated" : true , "address" : val })
446+ R . RenderJSON ( w , R.JSON {"updated" : true , "address" : val })
449447}
450448
451449// setConfirmedEmailCtrl uses provided token parameter (generated by sendEmailConfirmationCtrl) to set email and add it to user token
@@ -457,7 +455,7 @@ func (s *private) setConfirmedEmailCtrl(w http.ResponseWriter, r *http.Request)
457455 Site string
458456 Token string
459457 }{}
460- if err := render . DecodeJSON (http .MaxBytesReader (w , r .Body , hardBodyLimit ), & confirm ); err != nil {
458+ if err := json . NewDecoder (http .MaxBytesReader (w , r .Body , hardBodyLimit )). Decode ( & confirm ); err != nil {
461459 if err != io .EOF {
462460 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't parse request body" , rest .ErrDecode )
463461 return
@@ -513,7 +511,7 @@ func (s *private) setEmail(w http.ResponseWriter, r *http.Request, userID, siteI
513511 rest .SendErrorJSON (w , r , http .StatusInternalServerError , err , "failed to set token" , rest .ErrInternal )
514512 return
515513 }
516- render . JSON ( w , r , R.JSON {"updated" : true , "address" : val })
514+ R . RenderJSON ( w , R.JSON {"updated" : true , "address" : val })
517515}
518516
519517// POST/GET /email/unsubscribe.html?site=siteID&tkn=jwt - unsubscribe the user in token from email notifications
@@ -597,7 +595,7 @@ func (s *private) emailUnsubscribeCtrl(w http.ResponseWriter, r *http.Request) {
597595 tmpl := template .Must (template .New ("unsubscribe" ).Parse (tmplstr ))
598596 msg := bytes.Buffer {}
599597 MustExecute (tmpl , & msg , nil )
600- render . HTML (w , r , msg .String ())
598+ rest . HTMLResponse (w , http . StatusOK , msg .String ())
601599}
602600
603601// DELETE /email?site=siteID - removes user's email
@@ -624,7 +622,7 @@ func (s *private) deleteEmailCtrl(w http.ResponseWriter, r *http.Request) {
624622 return
625623 }
626624 }
627- render . JSON ( w , r , R.JSON {"deleted" : true })
625+ R . RenderJSON ( w , R.JSON {"deleted" : true })
628626}
629627
630628// DELETE /telegram?site=siteID - removes user's telegram
@@ -638,7 +636,7 @@ func (s *private) deleteTelegramCtrl(w http.ResponseWriter, r *http.Request) {
638636 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't delete telegram for user" , code )
639637 return
640638 }
641- render . JSON ( w , r , R.JSON {"deleted" : true })
639+ R . RenderJSON ( w , R.JSON {"deleted" : true })
642640}
643641
644642// GET /userdata?site=siteID - exports all data about the user as a json with user info and list of all comments
@@ -726,7 +724,7 @@ func (s *private) deleteMeCtrl(w http.ResponseWriter, r *http.Request) {
726724 }
727725
728726 link := fmt .Sprintf ("%s/web/deleteme.html?token=%s" , s .remarkURL , tokenStr )
729- render . JSON ( w , r , R.JSON {"site" : siteID , "user_id" : user .ID , "token" : tokenStr , "link" : link })
727+ R . RenderJSON ( w , R.JSON {"site" : siteID , "user_id" : user .ID , "token" : tokenStr , "link" : link })
730728}
731729
732730// POST /image - save image with form request
@@ -751,7 +749,7 @@ func (s *private) savePictureCtrl(w http.ResponseWriter, r *http.Request) {
751749 return
752750 }
753751
754- render . JSON ( w , r , R.JSON {"id" : id })
752+ R . RenderJSON ( w , R.JSON {"id" : id })
755753}
756754
757755func (s * private ) isReadOnly (locator store.Locator ) bool {
0 commit comments