Skip to content

Commit 3d5e985

Browse files
committed
Set default for extra imports
1 parent 9142f05 commit 3d5e985

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

interfaces/generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func (o *Options) SetDefaults() {
3131
if o.ShouldInclude == nil {
3232
o.ShouldInclude = func(reflect.Method) bool { return true }
3333
}
34+
if o.ExtraImports == nil {
35+
o.ExtraImports = func(reflect.Method) []string { return nil }
36+
}
3437
}
3538

3639
type Option func(*Options)

interfaces/generate_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ type InterfacesClient interface {
4141

4242
func TestGenerate(t *testing.T) {
4343
dir := t.TempDir()
44-
err := Generate([]any{&Client{}}, dir, WithIncludeFunc(func(m reflect.Method) bool {
45-
return MethodHasAnyPrefix(m, []string{"List"}) && MethodHasAnySuffix(m, []string{"Tables"})
46-
}))
44+
err := Generate([]any{&Client{}}, dir,
45+
WithIncludeFunc(func(m reflect.Method) bool {
46+
return MethodHasAnyPrefix(m, []string{"List"}) && MethodHasAnySuffix(m, []string{"Tables"})
47+
}),
48+
WithExtraImports(func(m reflect.Method) []string { return []string{"net/http"} },
49+
))
4750
if err != nil {
4851
t.Fatalf("unexpected error: %v", err)
4952
}

0 commit comments

Comments
 (0)