pkger/here/current.go

30 lines
398 B
Go
Raw Permalink Normal View History

2019-08-05 00:13:27 +03:00
package here
import (
"path/filepath"
"sync"
)
var curOnce sync.Once
var curErr error
var current Info
func Current() (Info, error) {
(&curOnce).Do(func() {
b, err := run("go", "env", "GOMOD")
if err != nil {
curErr = err
return
}
root := filepath.Dir(string(b))
i, err := Dir(root)
if err != nil {
curErr = err
return
}
current = i
})
return current, curErr
}