From 5a8535c59591244d2f3d1c5fb185cd6466f5935d Mon Sep 17 00:00:00 2001 From: dalei Date: Mon, 19 Mar 2018 14:21:44 +0800 Subject: [PATCH] load if config file not exist --- multiconfig.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/multiconfig.go b/multiconfig.go index 0070344..7e98e3c 100644 --- a/multiconfig.go +++ b/multiconfig.go @@ -63,6 +63,15 @@ func NewWithPath(path string) *DefaultLoader { return d } +// NewWithPathOptional returns a new instance of DefaultLoader with given file optinal. +func NewWithPathOptional(path string) *DefaultLoader { + _, err := os.Stat(path) + if os.IsNotExist(err) { + return New() + } + return NewWithPath(path) +} + // New returns a new instance of DefaultLoader without any file loaders. func New() *DefaultLoader { loader := MultiLoader(