filepath.go 438 B

1234567891011121314151617181920212223242526
  1. package gen
  2. import (
  3. "errors"
  4. "os"
  5. "path/filepath"
  6. "github.com/tal-tech/go-zero/tools/goctl/util"
  7. )
  8. func getFilePath(file string) (string, error) {
  9. wd, err := os.Getwd()
  10. if err != nil {
  11. return "", err
  12. }
  13. projPath, ok := util.FindGoModPath(filepath.Join(wd, file))
  14. if !ok {
  15. projPath, err = util.PathFromGoSrc()
  16. if err != nil {
  17. return "", errors.New("no go.mod found, or not in GOPATH")
  18. }
  19. }
  20. return projPath, nil
  21. }