From 1bf64156e5f94bc2599a6b27f0b11163abeb16d2 Mon Sep 17 00:00:00 2001 From: Soma Szelpal Date: Mon, 27 May 2019 01:10:00 +0200 Subject: [PATCH] Added "Exists" function --- README.md | 2 ++ util.go | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index a440b90..569d07f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ golang-vfstemplate ======================= +Golang library for parsing template files from virtual http filesystem (httpfs) + ## Installation ``` diff --git a/util.go b/util.go index b567151..eb91c6c 100644 --- a/util.go +++ b/util.go @@ -45,3 +45,13 @@ func ReadFileString(fs http.FileSystem, path string) (string, error) { } return string(buf), nil } + +// Exists reports whether the named file or directory exists in http.FileSystem. +func Exists(fs http.FileSystem, name string) bool { + if _, err := Stat(fs, name); err != nil { + if os.IsNotExist(err) { + return false + } + } + return true +}