diff --git a/snippets/go.snippets b/snippets/go.snippets index 35f2a7292..b2e7e3d5a 100644 --- a/snippets/go.snippets +++ b/snippets/go.snippets @@ -559,3 +559,12 @@ snippet signals "handle signals" fmt.Println("awaiting signal") <-done fmt.Println("exiting") + +snippet fileExists "check if a file exists" + if _, err := os.Stat("${1}"); err == nil { + // path/to/whatever exists + } else if errors.Is(err, os.ErrNotExist) { + // path/to/whatever does *not* exist + } else { + // other errors + }