From 16d9c8b171da2f64e8327cb86e943fd256b1a04c Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Wed, 15 Jul 2026 20:39:23 +0100 Subject: [PATCH] fixed nil --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 8a7b687..9354d64 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,16 @@ import ( "path/filepath" ) +func check(e error) { + if e != nil { + panic(e) + } +} + func write(a, b string) { path := filepath.Join(a, b) - file, _ := os.Create(path) + file, err := os.Create(path) + check(err) file.Sync() @@ -23,4 +30,5 @@ func main() { fmt.Println("Leanring go.") fmt.Println("Adding a function to create a file") write("./", "file.txt") + fmt.Println("File created successfully. with contents inside") }