Error handling in sample

This commit is contained in:
Alex Ellis
2017-03-31 19:56:38 +01:00
parent 22b3e73b96
commit 43a66e4043

View File

@ -6,13 +6,23 @@ import (
"os" "os"
"strconv" "strconv"
"time" "time"
"log"
) )
func main() { func main() {
input, _ := ioutil.ReadAll(os.Stdin) input, err := ioutil.ReadAll(os.Stdin)
fmt.Println("Stashing request") if err != nil {
log.Fatalf("Cannot read input %s.\n", err)
return
}
now := time.Now() now := time.Now()
stamp := strconv.FormatInt(now.UnixNano(), 10) stamp := strconv.FormatInt(now.UnixNano(), 10)
ioutil.WriteFile(stamp+".txt", input, 0644) writeErr := ioutil.WriteFile(stamp+".txt", input, 0644)
if writeErr != nil {
log.Fatalf("Cannot write input %s.\n", err)
return
}
fmt.Printf("Stashing request: %s.txt\n", stamp)
} }