talks

git clone git://code.dwrz.net/talks
Log | Files | Refs

weather.go (621B)


      1 package main
      2 
      3 import (
      4 	"sync"
      5 	"time"
      6 
      7 	"github.com/dwrz/talks/concurrency/pkg/weather"
      8 )
      9 
     10 func getZipTemp(
     11 	wg *sync.WaitGroup, record []string, ztchan chan *ZipTemp,
     12 ) {
     13 	defer wg.Done()
     14 
     15 	// Ignore malformed records.
     16 	if len(record) < 5 {
     17 		return
     18 	}
     19 
     20 	var zt = &ZipTemp{
     21 		City:      record[3],
     22 		Latitude:  record[1],
     23 		Longitude: record[2],
     24 		State:     record[4],
     25 		ZipCode:   record[0],
     26 	}
     27 
     28 	// Ignore zip codes we were not able to get the weather for.
     29 	weather, err := weather.GetGeo(zt.Latitude, zt.Longitude)
     30 	if err != nil {
     31 		return
     32 	}
     33 
     34 	zt.Temperature = weather.Temp
     35 	zt.Time = time.Now()
     36 
     37 	ztchan <- zt
     38 }