-
Notifications
You must be signed in to change notification settings - Fork 3
/
object_loader.go
47 lines (39 loc) · 1005 Bytes
/
object_loader.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
package mkdoc
import (
"log"
)
type ObjectLoader interface {
Load(ts TypeScope) (*Object, error)
LoadAll(tss []TypeScope) ([]*Object, error)
Add(object *Object) error
GetObjectId(ts TypeScope) (string, error)
SetConfig(cfg *ObjectLoaderConfig)
Lang() string
}
type TypeScope struct {
FileName string
TypeName string
}
type ObjectLoaderConfig struct {
Config
}
var objectLoaders map[string]ObjectLoader
// RegisterObjectLoader to global object loader
func RegisterObjectLoader(loader ObjectLoader) {
if objectLoaders == nil {
objectLoaders = make(map[string]ObjectLoader)
}
lang := loader.Lang()
if objectLoaders[lang] != nil {
log.Fatalf("duplicate register object loader : %s", lang)
}
objectLoaders[lang] = loader
}
// GetObjectLoaders get all registered object loaders
func GetObjectLoaders() map[string]ObjectLoader {
return objectLoaders
}
// GetObjectLoader get one registered object loader
func GetObjectLoader(lang string) ObjectLoader {
return objectLoaders[lang]
}