MCPcopy Index your code
hub / github.com/mpolden/echoip / DefaultHandler

Method DefaultHandler

http/http.go:342–383  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

340}
341
342func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appError {
343 response, err := s.newResponse(r)
344 if err != nil {
345 return badRequest(err).WithMessage(err.Error())
346 }
347 t, err := template.ParseGlob(s.Template + "/*")
348 if err != nil {
349 return internalServerError(err)
350 }
351 json, err := json.MarshalIndent(response, "", " ")
352 if err != nil {
353 return internalServerError(err)
354 }
355
356 var data = struct {
357 Response
358 Host string
359 BoxLatTop float64
360 BoxLatBottom float64
361 BoxLonLeft float64
362 BoxLonRight float64
363 JSON string
364 Port bool
365 Sponsor bool
366 ExplicitLookup bool
367 }{
368 response,
369 r.Host,
370 response.Latitude + 0.05,
371 response.Latitude - 0.05,
372 response.Longitude - 0.05,
373 response.Longitude + 0.05,
374 string(json),
375 s.LookupPort != nil,
376 s.Sponsor,
377 r.URL.Query().Has("ip"),
378 }
379 if err := t.Execute(w, &data); err != nil {
380 return internalServerError(err)
381 }
382 return nil
383}
384
385func NotFoundHandler(w http.ResponseWriter, r *http.Request) *appError {
386 err := notFound(nil).WithMessage("404 page not found")

Callers

nothing calls this directly

Calls 4

newResponseMethod · 0.95
badRequestFunction · 0.85
internalServerErrorFunction · 0.85
WithMessageMethod · 0.80

Tested by

no test coverage detected