1 // Copyright 2015 go-swagger maintainers
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
25 // GOPATHKey represents the env key for gopath
29 // FindInSearchPath finds a package in a provided lists of paths
30 func FindInSearchPath(searchPath, pkg string) string {
31 pathsList := filepath.SplitList(searchPath)
32 for _, path := range pathsList {
33 if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil {
34 if _, err := os.Stat(evaluatedPath); err == nil {
42 // FindInGoSearchPath finds a package in the $GOPATH:$GOROOT
43 func FindInGoSearchPath(pkg string) string {
44 return FindInSearchPath(FullGoSearchPath(), pkg)
47 // FullGoSearchPath gets the search paths for finding packages
48 func FullGoSearchPath() string {
49 allPaths := os.Getenv(GOPATHKey)
51 allPaths = filepath.Join(os.Getenv("HOME"), "go")
54 allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":")
56 allPaths = runtime.GOROOT()