Kevin Wan 3 年之前
父節點
當前提交
fa0c364982
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      tools/goctl/docker/docker.go

+ 6 - 5
tools/goctl/docker/docker.go

@@ -120,11 +120,6 @@ func generateDockerfile(goFile string, port int, version string, args ...string)
 
 
 	if len(projPath) == 0 {
 	if len(projPath) == 0 {
 		projPath = "."
 		projPath = "."
-	} else {
-		pos := strings.IndexByte(projPath, os.PathSeparator)
-		if pos >= 0 {
-			projPath = projPath[pos+1:]
-		}
 	}
 	}
 
 
 	out, err := util.CreateIfNotExist(dockerfileName)
 	out, err := util.CreateIfNotExist(dockerfileName)
@@ -169,6 +164,12 @@ func getFilePath(file string) (string, error) {
 		if err != nil {
 		if err != nil {
 			return "", errors.New("no go.mod found, or not in GOPATH")
 			return "", errors.New("no go.mod found, or not in GOPATH")
 		}
 		}
+
+		// ignore project root directory for GOPATH mode
+		pos := strings.IndexByte(projPath, os.PathSeparator)
+		if pos >= 0 {
+			projPath = projPath[pos+1:]
+		}
 	}
 	}
 
 
 	return projPath, nil
 	return projPath, nil