(filePath string, requiredExtension string)
| 60 | } |
| 61 | |
| 62 | func pluginFileFromPath(filePath string, requiredExtension string) (pluginFile, bool) { |
| 63 | base := filepath.Base(filePath) |
| 64 | lowerBase := strings.ToLower(base) |
| 65 | extension := strings.TrimSpace(requiredExtension) |
| 66 | if extension != "" { |
| 67 | if !strings.HasSuffix(lowerBase, strings.ToLower(extension)) { |
| 68 | return pluginFile{}, false |
| 69 | } |
| 70 | } else { |
| 71 | for _, candidateExtension := range []string{".so", ".dylib", ".dll"} { |
| 72 | if strings.HasSuffix(lowerBase, candidateExtension) { |
| 73 | extension = candidateExtension |
| 74 | break |
| 75 | } |
| 76 | } |
| 77 | if extension == "" { |
| 78 | return pluginFile{}, false |
| 79 | } |
| 80 | } |
| 81 | name := base[:len(base)-len(extension)] |
| 82 | id := name |
| 83 | version := "" |
| 84 | if versionIndex := strings.LastIndex(name, "-v"); versionIndex > 0 { |
| 85 | candidateID := name[:versionIndex] |
| 86 | candidateVersion := name[versionIndex+2:] |
| 87 | if validPluginID(candidateID) && validPluginVersion(candidateVersion) { |
| 88 | id = candidateID |
| 89 | version = candidateVersion |
| 90 | } |
| 91 | } |
| 92 | if !validPluginID(id) { |
| 93 | return pluginFile{}, false |
| 94 | } |
| 95 | return pluginFile{ID: id, Path: filePath, Version: version}, true |
| 96 | } |
| 97 | |
| 98 | // PluginExtension returns the dynamic library file extension used for goos. |
| 99 | func PluginExtension(goos string) string { |
no test coverage detected