mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 09:34:40 +00:00
code-generator: Remove now unused helper function
This commit is contained in:
parent
10c32b3e2f
commit
7f5982e708
@ -17,40 +17,9 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
gobuild "go/build"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CurrentPackage returns the go package of the current directory, or "" if it cannot
|
||||
// be derived from the GOPATH.
|
||||
func CurrentPackage() string {
|
||||
for _, root := range gobuild.Default.SrcDirs() {
|
||||
if pkg, ok := hasSubdir(root, "."); ok {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func hasSubdir(root, dir string) (rel string, ok bool) {
|
||||
// ensure a tailing separator to properly compare on word-boundaries
|
||||
const sep = string(filepath.Separator)
|
||||
root = filepath.Clean(root)
|
||||
if !strings.HasSuffix(root, sep) {
|
||||
root += sep
|
||||
}
|
||||
|
||||
// check whether root dir starts with root
|
||||
dir = filepath.Clean(dir)
|
||||
if !strings.HasPrefix(dir, root) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// cut off root
|
||||
return filepath.ToSlash(dir[len(root):]), true
|
||||
}
|
||||
|
||||
// Vendorless trims vendor prefix from a package path to make it canonical
|
||||
func Vendorless(p string) string {
|
||||
if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {
|
||||
|
Loading…
Reference in New Issue
Block a user