Skip to content

Commit 33c05a2

Browse files
committed
Create an interface between core and plugins
0 parents  commit 33c05a2

File tree

9 files changed

+324
-0
lines changed

9 files changed

+324
-0
lines changed

.gitignore

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
2+
# Created by https://www.gitignore.io/api/go,osx,linux,windows,jetbrains+all
3+
4+
### Go ###
5+
# Binaries for programs and plugins
6+
*.exe
7+
*.exe~
8+
*.dll
9+
*.so
10+
*.dylib
11+
12+
# Test binary, build with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
*.out
17+
18+
### Go Patch ###
19+
/vendor/
20+
/Godeps/
21+
22+
### JetBrains+all ###
23+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
24+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
25+
26+
# User-specific stuff
27+
.idea/**/workspace.xml
28+
.idea/**/tasks.xml
29+
.idea/**/usage.statistics.xml
30+
.idea/**/dictionaries
31+
.idea/**/shelf
32+
33+
# Generated files
34+
.idea/**/contentModel.xml
35+
36+
# Sensitive or high-churn files
37+
.idea/**/dataSources/
38+
.idea/**/dataSources.ids
39+
.idea/**/dataSources.local.xml
40+
.idea/**/sqlDataSources.xml
41+
.idea/**/dynamic.xml
42+
.idea/**/uiDesigner.xml
43+
.idea/**/dbnavigator.xml
44+
45+
# Gradle
46+
.idea/**/gradle.xml
47+
.idea/**/libraries
48+
49+
# Gradle and Maven with auto-import
50+
# When using Gradle or Maven with auto-import, you should exclude module files,
51+
# since they will be recreated, and may cause churn. Uncomment if using
52+
# auto-import.
53+
# .idea/modules.xml
54+
# .idea/*.iml
55+
# .idea/modules
56+
57+
# CMake
58+
cmake-build-*/
59+
60+
# Mongo Explorer plugin
61+
.idea/**/mongoSettings.xml
62+
63+
# File-based project format
64+
*.iws
65+
66+
# IntelliJ
67+
out/
68+
69+
# mpeltonen/sbt-idea plugin
70+
.idea_modules/
71+
72+
# JIRA plugin
73+
atlassian-ide-plugin.xml
74+
75+
# Cursive Clojure plugin
76+
.idea/replstate.xml
77+
78+
# Crashlytics plugin (for Android Studio and IntelliJ)
79+
com_crashlytics_export_strings.xml
80+
crashlytics.properties
81+
crashlytics-build.properties
82+
fabric.properties
83+
84+
# Editor-based Rest Client
85+
.idea/httpRequests
86+
87+
# Android studio 3.1+ serialized cache file
88+
.idea/caches/build_file_checksums.ser
89+
90+
### JetBrains+all Patch ###
91+
# Ignores the whole .idea folder and all .iml files
92+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
93+
94+
.idea/
95+
96+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
97+
98+
*.iml
99+
modules.xml
100+
.idea/misc.xml
101+
*.ipr
102+
103+
### Linux ###
104+
*~
105+
106+
# temporary files which can be created if a process still has a handle open of a deleted file
107+
.fuse_hidden*
108+
109+
# KDE directory preferences
110+
.directory
111+
112+
# Linux trash folder which might appear on any partition or disk
113+
.Trash-*
114+
115+
# .nfs files are created when an open file is removed but is still being accessed
116+
.nfs*
117+
118+
### OSX ###
119+
# General
120+
.DS_Store
121+
.AppleDouble
122+
.LSOverride
123+
124+
# Icon must end with two \r
125+
Icon
126+
127+
# Thumbnails
128+
._*
129+
130+
# Files that might appear in the root of a volume
131+
.DocumentRevisions-V100
132+
.fseventsd
133+
.Spotlight-V100
134+
.TemporaryItems
135+
.Trashes
136+
.VolumeIcon.icns
137+
.com.apple.timemachine.donotpresent
138+
139+
# Directories potentially created on remote AFP share
140+
.AppleDB
141+
.AppleDesktop
142+
Network Trash Folder
143+
Temporary Items
144+
.apdisk
145+
146+
### Windows ###
147+
# Windows thumbnail cache files
148+
Thumbs.db
149+
ehthumbs.db
150+
ehthumbs_vista.db
151+
152+
# Dump file
153+
*.stackdump
154+
155+
# Folder config file
156+
[Dd]esktop.ini
157+
158+
# Recycle Bin used on file shares
159+
$RECYCLE.BIN/
160+
161+
# Windows Installer files
162+
*.cab
163+
*.msi
164+
*.msix
165+
*.msm
166+
*.msp
167+
168+
# Windows shortcuts
169+
*.lnk
170+
171+
172+
# End of https://www.gitignore.io/api/go,osx,linux,windows,jetbrains+all

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Interface
2+
3+
The interface between the ResourceAPI/Core and its plugins

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module github.com/ResourceAPI/Interface

plugins/registry.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package plugins
2+
3+
var registryInstance Registry
4+
5+
func SetRegistry(registry Registry) {
6+
registryInstance = registry
7+
}
8+
9+
func GetRegistry() Registry {
10+
if registryInstance == nil {
11+
panic("registry is nil")
12+
}
13+
14+
return registryInstance
15+
}

plugins/types.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package plugins
2+
3+
type Plugin interface {
4+
// The name of the plugin
5+
Name() string
6+
7+
// The entrypoint function
8+
Entrypoint()
9+
}
10+
11+
type Facade interface {
12+
// Initialize the facade.
13+
Initialize() error
14+
15+
// Start the facade. Must be a blocking call.
16+
Start() error
17+
18+
// Graceful stopping of the facade with a 30s timeout.
19+
Stop() error
20+
}
21+
22+
type Storage interface {
23+
// Initialize the storage.
24+
Initialize() error
25+
26+
// Start the storage. Must be a blocking call.
27+
Start() error
28+
29+
// Graceful stopping of the storage with a 30s timeout.
30+
Stop() error
31+
32+
// Retrieve resources.
33+
GetResources(resource string, filters []interface{}) ([]map[string]interface{}, error)
34+
35+
// Create resources.
36+
CreateResources(resource string, data []map[string]interface{}) error
37+
38+
// Update resources.
39+
UpdateResources(resource string, data []map[string]interface{}, filters []interface{}) error
40+
41+
// Delete resources.
42+
DeleteResources(resource string, filters []interface{}) error
43+
}
44+
45+
type Filter interface {
46+
// Initialize the filter.
47+
Initialize() error
48+
49+
// Start the filter. Does not have to be blocking.
50+
Start() error
51+
52+
// Graceful stopping of the filter with a 30s timeout.
53+
Stop() error
54+
55+
// Validate structure for filter validness
56+
ValidateFilter(filter interface{}) (bool, error)
57+
}
58+
59+
type Registry interface {
60+
// Register a facade
61+
RegisterFacade(name string, facade Facade) error
62+
63+
// Register a store
64+
RegisterStorage(name string, storage Storage) error
65+
66+
// Register a filter
67+
RegisterFilter(name string, filter Filter) error
68+
69+
// Associate a filter with a store
70+
AssociateFilter(filter string, storage string) error
71+
}

resource/processor.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package resource
2+
3+
var processorInstance Processor
4+
5+
func SetProcessor(processor Processor) {
6+
processorInstance = processor
7+
}
8+
9+
func GetProcessor() Processor {
10+
if processorInstance == nil {
11+
panic("resource processor is nil")
12+
}
13+
14+
return processorInstance
15+
}

resource/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package resource
2+
3+
import "github.com/ResourceAPI/Interface/plugins"
4+
5+
type Processor interface {
6+
// Get the store of a resource
7+
GetStore(resource string) *plugins.Storage
8+
9+
// Get a list of all resources
10+
GetResources() []string
11+
}

schema/processor.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package schema
2+
3+
var processorInstance Processor
4+
5+
func SetProcessor(processor Processor) {
6+
processorInstance = processor
7+
}
8+
9+
func GetProcessor() Processor {
10+
if processorInstance == nil {
11+
panic("schema processor is nil")
12+
}
13+
14+
return processorInstance
15+
}

schema/types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package schema
2+
3+
type Processor interface {
4+
// Get the store of a resource
5+
ResourceExists(resource string) bool
6+
7+
// Get a list of all resources
8+
ResourceValid(resource string, data string) (bool, error)
9+
10+
GetSchema(resource string) *Schema
11+
}
12+
13+
type Schema struct {
14+
Source map[string]interface{}
15+
Meta ResourceMeta
16+
}
17+
18+
type ResourceMeta struct {
19+
Resource string `json:"resource"`
20+
Store string `json:"store"`
21+
}

0 commit comments

Comments
 (0)