-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugins.go
76 lines (62 loc) · 1.8 KB
/
plugins.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package deckconverter
import (
"log"
"github.com/jeandeaual/tts-deckconverter/plugins"
"github.com/jeandeaual/tts-deckconverter/plugins/custom"
"github.com/jeandeaual/tts-deckconverter/plugins/mtg"
"github.com/jeandeaual/tts-deckconverter/plugins/pkm"
"github.com/jeandeaual/tts-deckconverter/plugins/vanguard"
"github.com/jeandeaual/tts-deckconverter/plugins/ygo"
)
func init() {
Plugins = make(map[string]plugins.Plugin)
FileExtHandlers = make(map[string]plugins.FileHandler)
registerPlugins(
mtg.MagicPlugin,
pkm.PokemonPlugin,
ygo.YGOPlugin,
vanguard.VanguardPlugin,
custom.CustomPlugin,
)
registerURLHandlers()
registerFileExtHandlers()
}
// Plugins is the list of registered plugins.
var Plugins map[string]plugins.Plugin
// pluginIDs is the ordered list of registered plugins.
var pluginIDs []string
// URLHandlers are all the registered URL handlers.
var URLHandlers []plugins.URLHandler
// FileExtHandlers are all the registered file extension handlers.
var FileExtHandlers map[string]plugins.FileHandler
func registerPlugins(plugins ...plugins.Plugin) {
for _, plugin := range plugins {
Plugins[plugin.PluginID()] = plugin
pluginIDs = append(pluginIDs, plugin.PluginID())
}
}
func registerURLHandlers() {
for _, plugin := range Plugins {
URLHandlers = append(URLHandlers, plugin.URLHandlers()...)
}
}
func registerFileExtHandlers() {
for _, plugin := range Plugins {
for ext, fileExtHandler := range plugin.FileExtHandlers() {
_, found := FileExtHandlers[ext]
if found {
log.Fatalf(
"Handler for file extension %s already exists, cannot "+
"register for %s",
ext,
plugin.PluginID(),
)
}
FileExtHandlers[ext] = fileExtHandler
}
}
}
// AvailablePlugins lists the registered plugins, sorted.
func AvailablePlugins() []string {
return pluginIDs
}