Error handling in sample
@@ -6,13 +6,23 @@ import (
"os"
"strconv"
"time"
+ "log"
)
func main() {
- input, _ := ioutil.ReadAll(os.Stdin)
- fmt.Println("Stashing request")
+ input, err := ioutil.ReadAll(os.Stdin)
+ if err != nil {
+ log.Fatalf("Cannot read input %s.\n", err)
+ return
+ }
now := time.Now()
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)
}
