Wrap wraps around a raw go plugin to provide typesafe access.
(p *plugin.Plugin)
| 10 | |
| 11 | // Wrap wraps around a raw go plugin to provide typesafe access. |
| 12 | func Wrap(p *plugin.Plugin) (Plugin, error) { |
| 13 | getInfoHandle, err := p.Lookup("GetGotifyPluginInfo") |
| 14 | if err != nil { |
| 15 | return nil, errors.New("missing GetGotifyPluginInfo symbol") |
| 16 | } |
| 17 | switch getInfoHandle := getInfoHandle.(type) { |
| 18 | case func() papiv1.Info: |
| 19 | v1 := PluginV1{} |
| 20 | |
| 21 | v1.Info = getInfoHandle() |
| 22 | newInstanceHandle, err := p.Lookup("NewGotifyPluginInstance") |
| 23 | if err != nil { |
| 24 | return nil, errors.New("missing NewGotifyPluginInstance symbol") |
| 25 | } |
| 26 | constructor, ok := newInstanceHandle.(func(ctx papiv1.UserContext) papiv1.Plugin) |
| 27 | if !ok { |
| 28 | return nil, fmt.Errorf("NewGotifyPluginInstance signature mismatch, func(ctx plugin.UserContext) plugin.Plugin expected, got %T", newInstanceHandle) |
| 29 | } |
| 30 | v1.Constructor = constructor |
| 31 | return v1, nil |
| 32 | default: |
| 33 | return nil, fmt.Errorf("unknown plugin version (unrecogninzed GetGotifyPluginInfo signature %T)", getInfoHandle) |
| 34 | } |
| 35 | } |
searching dependent graphs…