@@ -58,6 +58,7 @@ type Extension struct {
58
58
entc.DefaultExtension
59
59
protoDir string
60
60
skipGenFile bool
61
+ goPkg string
61
62
}
62
63
63
64
// WithProtoDir sets the directory where the generated .proto files will be written.
@@ -67,6 +68,13 @@ func WithProtoDir(dir string) ExtensionOption {
67
68
}
68
69
}
69
70
71
+ // WithProtoDir sets the directory where the generated .proto files will be written.
72
+ func WithGoPkg (pkg string ) ExtensionOption {
73
+ return func (e * Extension ) {
74
+ e .goPkg = pkg
75
+ }
76
+ }
77
+
70
78
// SkipGenFile skips the generation of a generate.go file next to each .proto file.
71
79
func SkipGenFile () ExtensionOption {
72
80
return func (e * Extension ) {
@@ -124,10 +132,11 @@ func (e *Extension) generate(g *gen.Graph) error {
124
132
if e .protoDir != "" {
125
133
entProtoDir = e .protoDir
126
134
}
127
- adapter , err := LoadAdapter (g )
135
+ adapter , err := LoadAdapter (g , e . goPkg )
128
136
if err != nil {
129
137
return fmt .Errorf ("entproto: failed parsing ent graph: %w" , err )
130
138
}
139
+
131
140
var errs error
132
141
for _ , schema := range g .Schemas {
133
142
name := schema .Name
@@ -197,7 +206,7 @@ func (e *Extension) generate(g *gen.Graph) error {
197
206
if err != nil {
198
207
return err
199
208
}
200
- contents := protocGenerateGo (fd , toSchema , toEnt , g .Config .Package )
209
+ contents := e . protocGenerateGo (fd , toSchema , toEnt , g .Config .Package )
201
210
if err := os .WriteFile (genGoPath , []byte (contents ), 0600 ); err != nil {
202
211
return fmt .Errorf ("entproto: failed generating generate.go file for %q: %w" , protoFilePath , err )
203
212
}
@@ -216,7 +225,7 @@ func fileExists(fpath string) bool {
216
225
return true
217
226
}
218
227
219
- func protocGenerateGo (fd * desc.FileDescriptor , toSchemaDir , entPath , entPackage string ) string {
228
+ func ( e * Extension ) protocGenerateGo (fd * desc.FileDescriptor , toSchemaDir , entPath , entPackage string ) string {
220
229
levelsUp := len (strings .Split (fd .GetPackage (), "." ))
221
230
toProtoBase := ""
222
231
for i := 0 ; i < levelsUp ; i ++ {
0 commit comments