Skip to content

Commit 8ca535e

Browse files
authored
Merge pull request #24 from nrfta/debug-main-scenario
account for debug main module
2 parents 8074803 + 958e4b8 commit 8ca535e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ type MetaConfig struct {
2323

2424
// Load config from file then from environment variables
2525
func Load(box *packr.Box, config interface{}) error {
26-
_, filename, _, _ := runtime.Caller(1)
27-
resolverRoot := path.Clean(path.Join(path.Dir(filename), box.Path))
26+
27+
var resolverRoot string
28+
// when debugging a main package, the Box path will be a full path
29+
if strings.HasPrefix(box.Path, "/") {
30+
resolverRoot = box.Path
31+
} else { // the Box path is relative, append to the config file's path
32+
_, filename, _, _ := runtime.Caller(1)
33+
resolverRoot = path.Clean(path.Join(path.Dir(filename), box.Path))
34+
}
2835
box.DefaultResolver = &resolver.Disk{Root: resolverRoot}
2936

3037
configType := "json"

0 commit comments

Comments
 (0)