GetExtensionFunction returns the function inside the extension matching the given names. Returns an error if the extension or function cannot be found.
(identifier LibraryIdentifier, funcName string)
| 86 | // GetExtensionFunction returns the function inside the extension matching the given names. Returns an error if the |
| 87 | // extension or function cannot be found. |
| 88 | func GetExtensionFunction(identifier LibraryIdentifier, funcName string) (_ pg_extension.Function, err error) { |
| 89 | libMutex.Lock() |
| 90 | defer libMutex.Unlock() |
| 91 | |
| 92 | extName := identifier.ExtensionName() |
| 93 | if identifier.Platform() != pg_extension.PLATFORM { |
| 94 | return pg_extension.Function{}, errors.Errorf( |
| 95 | `function "%s" was initialized through "%s" on a different platform, which is not supported`, funcName, extName) |
| 96 | } |
| 97 | lib, ok := allLibraries[extName] |
| 98 | if !ok { |
| 99 | ext, err := GetExtension(extName) |
| 100 | if err != nil { |
| 101 | return pg_extension.Function{}, err |
| 102 | } |
| 103 | lib, err = ext.LoadLibrary() |
| 104 | if err != nil { |
| 105 | return pg_extension.Function{}, err |
| 106 | } |
| 107 | lib.Version = ext.Control.DefaultVersion |
| 108 | allLibraries[extName] = lib |
| 109 | } |
| 110 | if lib.Version != identifier.Version() { |
| 111 | return pg_extension.Function{}, errors.Errorf( |
| 112 | `function "%s" was initialized through "%s" v%s, the current platform only supports v%s"`, |
| 113 | funcName, extName, identifier.Version().String(), lib.Version.String()) |
| 114 | } |
| 115 | libFunc, ok := lib.Funcs[funcName] |
| 116 | if !ok { |
| 117 | return pg_extension.Function{}, errors.Errorf(`extension "%s" does not declare the function "%s"`, extName, funcName) |
| 118 | } |
| 119 | return libFunc, nil |
| 120 | } |
| 121 | |
| 122 | // FindInvalidIdentifiers returns all identifiers that are not valid for the current environment. If the return is |
| 123 | // empty, then that means all of the given identifiers are valid. |
no test coverage detected