Add error checking for tmp file

This commit is contained in:
Harlow Ward 2016-01-09 09:52:47 -08:00
parent d542fa996f
commit 509f68de89

View file

@ -2,7 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "log"
"os" "os"
"sync" "sync"
@ -13,13 +13,34 @@ import (
// Note: download file with test data // Note: download file with test data
// curl https://s3.amazonaws.com/kinesis.test/users.txt -o /tmp/users.txt // curl https://s3.amazonaws.com/kinesis.test/users.txt -o /tmp/users.txt
func putToS3(svc *kinesis.Kinesis, data string) {
params := &kinesis.PutRecordInput{
Data: []byte(data),
PartitionKey: aws.String("partitionKey"),
StreamName: aws.String("hw-test-stream"),
}
_, err := svc.PutRecord(params)
if err != nil {
log.Fatal(err.Error())
return
} else {
log.Print(".")
}
}
func main() { func main() {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
jobCh := make(chan string) jobCh := make(chan string)
// read sample data // read sample data
file, _ := os.Open("/tmp/users.txt") file, err := os.Open("/tmp/users.txt")
if err != nil {
log.Fatal("Cannot open users.txt file")
}
defer file.Close() defer file.Close()
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
@ -30,20 +51,7 @@ func main() {
wg.Add(1) wg.Add(1)
go func() { go func() {
for data := range jobCh { for data := range jobCh {
params := &kinesis.PutRecordInput{ putToS3(svc, data)
Data: []byte(data),
PartitionKey: aws.String("partitionKey"),
StreamName: aws.String("hw-test-stream"),
}
_, err := svc.PutRecord(params)
if err != nil {
fmt.Println(err.Error())
return
} else {
fmt.Print(".")
}
} }
wg.Done() wg.Done()
}() }()
@ -54,6 +62,6 @@ func main() {
jobCh <- data jobCh <- data
} }
fmt.Println(".") log.Println(".")
fmt.Println("Finished populating stream") log.Println("Finished populating stream")
} }