Skip to content

Commit

Permalink
Fix bug introduced trying to sanitize log lines. Fixes #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Mar 3, 2024
1 parent 032bb36 commit b6a90d3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions weather/weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ func (p *Parser) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
if err != nil {
log.Printf("Failed to parse weather observation from request url: %+v", err)
}
p.parse(values)
p.Parse(values)
}

func (p *Parser) parse(values url.Values) {
func (p *Parser) Parse(values url.Values) {
defer func() {
if r := recover(); r != nil {
log.Printf("Failed to parse incoming request: %+v", r)
}
}()
parseValue := func(name string) (float64, error) {
array, ok := values[name]
first := strings.ReplaceAll(array[0], "\n", "")
first = strings.ReplaceAll(first, "\r", "")
if !ok {
return 0, fmt.Errorf("no such param: %s", name)
}
first := strings.ReplaceAll(array[0], "\n", "")
first = strings.ReplaceAll(first, "\r", "")
value, err := strconv.ParseFloat(first, 64)
if err != nil {
e := fmt.Errorf("failed to parse value: '%s': %+v", first, err)
Expand Down

0 comments on commit b6a90d3

Please sign in to comment.