main.go 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "log"
  4. "os"
  5. "path/filepath"
  6. gomodvendor "github.com/paketo-buildpacks/go-mod-vendor"
  7. "github.com/paketo-buildpacks/packit"
  8. )
  9. const GoModLocation = "go.mod"
  10. func main() {
  11. if len(os.Args) < 2 {
  12. log.Fatalln("Usage: ./test-runtime <project directory>")
  13. }
  14. workingDir := os.Args[1]
  15. /* First check if it is a go.mod project */
  16. goModParser := gomodvendor.NewGoModParser()
  17. detect := gomodvendor.Detect(goModParser)
  18. _, err := detect(packit.DetectContext{
  19. WorkingDir: workingDir,
  20. })
  21. if err == nil {
  22. log.Println("go.mod project detected")
  23. return
  24. }
  25. /* Next, check if it is a Gopkg.toml */
  26. _, err = os.Stat(filepath.Join(workingDir, "Gopkg.toml"))
  27. if err == nil {
  28. log.Println("Gopkg.toml project detected")
  29. return
  30. }
  31. /* Finally, check if it is a Go vendor */
  32. _, err = os.Stat(filepath.Join(workingDir, "vendor"))
  33. if err == nil {
  34. log.Println("Go vendor project detected")
  35. return
  36. }
  37. /* Not a Go project */
  38. log.Println("No Go project detected")
  39. }