@@ -75,8 +75,23 @@ func MustGetwd() string {
75
75
// e.g: "github.com/example-inc/app-operator"
76
76
func CheckAndGetCurrPkg () string {
77
77
gopath := os .Getenv (GopathEnv )
78
- goSrc := filepath .Join (gopath , SrcDir )
78
+ if len (gopath ) == 0 {
79
+ log .Fatalf ("get current pkg failed: GOPATH env not set" )
80
+ }
81
+ var goSrc string
82
+ cwdInGopath := false
79
83
wd := MustGetwd ()
84
+ for _ , path := range strings .Split (gopath , ":" ) {
85
+ goSrc = filepath .Join (path , SrcDir )
86
+
87
+ if strings .HasPrefix (filepath .Dir (wd ), goSrc ) {
88
+ cwdInGopath = true
89
+ break
90
+ }
91
+ }
92
+ if ! cwdInGopath {
93
+ log .Fatalf ("check current pkg failed: must run from gopath" )
94
+ }
80
95
currPkg := strings .Replace (wd , goSrc + string (filepath .Separator ), "" , 1 )
81
96
// strip any "/" prefix from the repo path.
82
97
return strings .TrimPrefix (currPkg , string (filepath .Separator ))
@@ -93,27 +108,3 @@ func GetOperatorType() OperatorType {
93
108
}
94
109
return OperatorTypeGo
95
110
}
96
-
97
- func GetGopath () string {
98
- gopath , ok := os .LookupEnv (GopathEnv )
99
- if ! ok || len (gopath ) == 0 {
100
- log .Fatal ("get current pkg failed: GOPATH env not set" )
101
- }
102
- return gopath
103
- }
104
-
105
- func SetGopath (currentGopath string ) {
106
- var newGopath string
107
- cwdInGopath := false
108
- wd := MustGetwd ()
109
- for _ , newGopath = range strings .Split (currentGopath , ":" ) {
110
- if strings .HasPrefix (filepath .Dir (wd ), newGopath ) {
111
- cwdInGopath = true
112
- break
113
- }
114
- }
115
- if ! cwdInGopath {
116
- log .Fatalf ("check current pkg failed: must run from gopath" )
117
- }
118
- os .Setenv (GopathEnv , newGopath )
119
- }
0 commit comments