Skip to content

Commit 77d4e0b

Browse files
authored
[chore] extract logic to separate function (#37887)
Extract code to a separate function in preparation of additional checks.
1 parent 93a3ded commit 77d4e0b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cmd/checkapi/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,14 @@ func walkFolder(folder string, componentType string) error {
183183
if len(result.Functions) > 1 {
184184
return fmt.Errorf("%s has more than one function: %q", folder, strings.Join(fnNames, ","))
185185
}
186+
if err := checkFactoryFunction(result.Functions[0], folder, componentType); err != nil {
187+
return err
188+
}
189+
return nil
190+
}
186191

187-
newFactoryFn := result.Functions[0]
192+
// check the only exported function of the module is NewFactory, matching the signature of the factory expected by the collector builder.
193+
func checkFactoryFunction(newFactoryFn *function, folder string, componentType string) error {
188194
if newFactoryFn.Name != "NewFactory" {
189195
return fmt.Errorf("%s does not define a NewFactory function", folder)
190196
}

0 commit comments

Comments
 (0)