Skip to content

Commit 2be6990

Browse files
committed
add import handler
1 parent 9c8756b commit 2be6990

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

importer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Importer struct {
1717
bufType map[string]Type
1818
bufBuild map[string]*build.Package
1919
errorHandler func(error)
20+
importHandler func(path, src, dir string)
2021
isCommentLocator bool
2122
ctx build.Context
2223
}
@@ -133,6 +134,9 @@ func (i *Importer) Import(path string, src string) (Type, error) {
133134
if ok {
134135
return tt, nil
135136
}
137+
if i.importHandler != nil {
138+
i.importHandler(path, src, dir)
139+
}
136140

137141
m := map[string]bool{}
138142
for _, v := range imp.GoFiles {

option.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ func WithCommentLocator() Option {
1616
i.isCommentLocator = true
1717
}
1818
}
19+
20+
// ImportHandler returns the import handler option
21+
func ImportHandler(f func(path, src, dir string)) Option {
22+
return func(i *Importer) {
23+
i.importHandler = f
24+
}
25+
}

0 commit comments

Comments
 (0)