| 1 | // Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. |
| 2 | // Use of this source code is governed by a MIT license found in the LICENSE file. |
| 3 | |
| 4 | //go:build go1.12 |
| 5 | // +build go1.12 |
| 6 | |
| 7 | package main |
| 8 | |
| 9 | import ( |
| 10 | "fmt" |
| 11 | |
| 12 | "golang.org/x/tools/go/packages" |
| 13 | ) |
| 14 | |
| 15 | func pkgPath(dir string) (string, error) { |
| 16 | pkgs, err := packages.Load(&packages.Config{Dir: dir}, ".") |
| 17 | if err != nil { |
| 18 | return "", err |
| 19 | } |
| 20 | if len(pkgs) != 1 { |
| 21 | return "", fmt.Errorf("Could not read package (%d package found)", len(pkgs)) |
| 22 | } |
| 23 | pkg := pkgs[0] |
| 24 | return pkg.PkgPath, nil |
| 25 | } |