-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.go
More file actions
62 lines (51 loc) · 1.03 KB
/
Copy pathplugin.go
File metadata and controls
62 lines (51 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package xpb
import (
"errors"
"github.com/pocketbase/pocketbase/core"
)
type Plugin interface {
/**
* Preload is called before the app is setup.
* This is a good place to load configurations.
*/
OnPreload() error
/**
* Load is called after the app is setup.
* This is a good place to register commands
* and hooks.
*/
OnLoad(app core.App) error
/**
* Get plugin info
*/
Info() PluginInfo
}
// For display purposes only
type PluginInfo struct {
Name string
Version string
Description string
}
var plugins = []Plugin{}
func Register(plugin Plugin) {
plugins = append(plugins, plugin)
}
func FireOnPreload() (err error) {
for _, plugin := range plugins {
if pluginErr := plugin.OnPreload(); pluginErr != nil {
err = errors.Join(err, pluginErr)
}
}
return
}
func FireOnLoad(app core.App) (err error) {
for _, plugin := range plugins {
if pluginErr := plugin.OnLoad(app); pluginErr != nil {
err = errors.Join(err, pluginErr)
}
}
return
}
func GetPlugins() []Plugin {
return plugins
}