()
| 28 | } |
| 29 | |
| 30 | func ResolveGoFmtPath() (string, error) { |
| 31 | settings := wconfig.GetWatcher().GetFullConfig().Settings |
| 32 | goPath := settings.TsunamiGoPath |
| 33 | |
| 34 | if goPath == "" { |
| 35 | var err error |
| 36 | goPath, err = build.FindGoExecutable() |
| 37 | if err != nil { |
| 38 | return "", err |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | goDir := filepath.Dir(goPath) |
| 43 | gofmtName := "gofmt" |
| 44 | if runtime.GOOS == "windows" { |
| 45 | gofmtName = "gofmt.exe" |
| 46 | } |
| 47 | gofmtPath := filepath.Join(goDir, gofmtName) |
| 48 | |
| 49 | info, err := os.Stat(gofmtPath) |
| 50 | if err != nil { |
| 51 | return "", fmt.Errorf("gofmt not found at %s: %w", gofmtPath, err) |
| 52 | } |
| 53 | |
| 54 | if info.IsDir() { |
| 55 | return "", fmt.Errorf("gofmt path is a directory: %s", gofmtPath) |
| 56 | } |
| 57 | |
| 58 | if info.Mode()&0111 == 0 { |
| 59 | return "", fmt.Errorf("gofmt is not executable: %s", gofmtPath) |
| 60 | } |
| 61 | |
| 62 | return gofmtPath, nil |
| 63 | } |
| 64 | |
| 65 | func FormatGoCode(contents []byte) []byte { |
| 66 | gofmtPath, err := ResolveGoFmtPath() |
no test coverage detected