@@ -2,7 +2,6 @@ package main
22
33import (
44 "context"
5- "fmt"
65 "math/rand/v2"
76 "slices"
87 "strconv"
@@ -59,18 +58,15 @@ func (app *App) HandleDB(request *http.Request) *http.Response {
5958}
6059
6160func (app * App ) HandleQuery (request * http.Request ) * http.Response {
62- n , err := normalizeNumber (request .Params .Get ("n" ))
63- if err != nil {
64- return http .Error (request , err )
65- }
61+ n := normalizeNumber (request .Params .Get ("n" ))
6662
6763 i , worlds := 0 , make (models.Worlds , n )
6864
6965 for i = range worlds {
7066 worlds [i ].ID = rand .IntN (10000 ) + 1
7167 }
7268
73- err = app .DB .FillWorldsByID (context .Background (), worlds )
69+ err : = app .DB .FillWorldsByID (context .Background (), worlds )
7470 if err != nil {
7571 return http .Error (request , err )
7672 }
@@ -79,18 +75,15 @@ func (app *App) HandleQuery(request *http.Request) *http.Response {
7975}
8076
8177func (app * App ) HandleUpdate (request * http.Request ) * http.Response {
82- n , err := normalizeNumber (request .Params .Get ("n" ))
83- if err != nil {
84- return http .Error (request , err )
85- }
78+ n := normalizeNumber (request .Params .Get ("n" ))
8679
8780 i , worlds := 0 , make (models.Worlds , n )
8881
8982 for i = range worlds {
9083 worlds [i ].ID = rand .IntN (10000 ) + 1
9184 }
9285
93- err = app .DB .FillWorldsByID (context .Background (), worlds )
86+ err : = app .DB .FillWorldsByID (context .Background (), worlds )
9487 if err != nil {
9588 return http .Error (request , err )
9689 }
@@ -112,10 +105,7 @@ func (app *App) HandleUpdate(request *http.Request) *http.Response {
112105}
113106
114107func (app * App ) HandleCachedQuery (request * http.Request ) * http.Response {
115- n , err := normalizeNumber (request .Params .Get ("n" ))
116- if err != nil {
117- return http .Error (request , err )
118- }
108+ n := normalizeNumber (request .Params .Get ("n" ))
119109
120110 i , worlds := 0 , make (models.Worlds , n )
121111
@@ -150,17 +140,17 @@ func (app *App) HandleFortune(request *http.Request) *http.Response {
150140}
151141
152142func (app * App ) HandlePlaintext (request * http.Request ) * http.Response {
153- return request .Respond ().Header ("Date" , time .Now ().Format (time .RFC1123 )).Header ("Server" , "indigo" ).String ("Hello, World!" )
143+ return request .Respond ().Header ("Date" , time .Now ().Format (time .RFC1123 )).Header ("Server" , "indigo" ).ContentType ( mime . Plain ). String ("Hello, World!" )
154144}
155145
156- func normalizeNumber (nString string , found bool ) ( int , error ) {
146+ func normalizeNumber (nString string , found bool ) int {
157147 if ! found {
158- return 0 , fmt . Errorf ( "not found" )
148+ nString = "0"
159149 }
160150
161151 n , err := strconv .Atoi (nString )
162152 if err != nil {
163- return 0 , err
153+ n = 0
164154 }
165155
166156 if n < 1 {
@@ -169,5 +159,5 @@ func normalizeNumber(nString string, found bool) (int, error) {
169159 n = 500
170160 }
171161
172- return n , nil
162+ return n
173163}
0 commit comments