(goCmd, inputPath string)
| 110 | } |
| 111 | |
| 112 | func getImportName(goCmd, inputPath string) (string, error) { |
| 113 | p, err := filepath.Abs(inputPath) |
| 114 | if err != nil { |
| 115 | return "", err |
| 116 | } |
| 117 | dir := filepath.Dir(p) |
| 118 | |
| 119 | // `go list dir` gives back the module name |
| 120 | // Should work for GOPATH as well as with modules |
| 121 | // Errors if no go files are found |
| 122 | cmd := exec.Command(goCmd, "list", dir) |
| 123 | b, err := cmd.Output() |
| 124 | if err == nil { |
| 125 | return string(b[:len(b)-1]), nil |
| 126 | } |
| 127 | |
| 128 | gopaths := strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator)) |
| 129 | |
| 130 | for _, path := range gopaths { |
| 131 | gpath, err := filepath.Abs(path) |
| 132 | if err != nil { |
| 133 | continue |
| 134 | } |
| 135 | rel, err := filepath.Rel(filepath.ToSlash(gpath), dir) |
| 136 | if err != nil { |
| 137 | return "", err |
| 138 | } |
| 139 | |
| 140 | if len(rel) < 4 || rel[:4] != "src"+string(os.PathSeparator) { |
| 141 | continue |
| 142 | } |
| 143 | return rel[4:], nil |
| 144 | } |
| 145 | return "", errors.New(fmt.Sprintf("Could not find source directory: GOPATH=%q REL=%q", gopaths, dir)) |
| 146 | |
| 147 | } |
| 148 | |
| 149 | func getExposePath(inputPath string) string { |
| 150 | return inputPath[0:len(inputPath)-3] + "_ffjson_expose.go" |
no outgoing calls
no test coverage detected
searching dependent graphs…