-func GenerateRPC(gen *Generator, file *File, outputDir string) *GenFile {
- packageDir := filepath.Join(outputDir, file.PackageName)
- filename := filepath.Join(packageDir, file.PackageName+rpcFileSuffix+outputFileExt)
+func resolveImportPath(dir string) string {
+ absPath, err := filepath.Abs(dir)
+ if err != nil {
+ panic(err)
+ }
+ modRoot := findGoModuleRoot(absPath)
+ if modRoot == "" {
+ logrus.Fatalf("module root not found at: %s", absPath)
+ }
+ modPath := findModulePath(path.Join(modRoot, "go.mod"))
+ if modPath == "" {
+ logrus.Fatalf("module path not found")
+ }
+ relDir, err := filepath.Rel(modRoot, absPath)
+ if err != nil {
+ panic(err)
+ }
+ return filepath.Join(modPath, relDir)
+}