Skip to content

Commit 93bbdb2

Browse files
committed
Add filters
1 parent d2a4d2a commit 93bbdb2

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

filter/processor.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package filter
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("filter processor is nil")
12+
}
13+
14+
return processorInstance
15+
}

filter/types.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package filter
2+
3+
import (
4+
"encoding/json"
5+
)
6+
7+
type Processor interface {
8+
// Check if a filter exists
9+
FilterExists(filter string) bool
10+
11+
// Create a new instance of the filter
12+
CreateFilter(filter string) interface{}
13+
14+
// Validate structure for filter validness
15+
ValidateFilter(filter ProcessedFilter) (bool, error)
16+
}
17+
18+
type EncodedFilter struct {
19+
Type string `json:"type"`
20+
Data json.RawMessage `json:"data"`
21+
}
22+
23+
type ProcessedFilter struct {
24+
Type string `json:"type"`
25+
Data interface{} `json:"data"`
26+
}

plugins/types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package plugins
22

3+
import (
4+
"github.com/StratoAPI/Interface/filter"
5+
)
6+
37
type Plugin interface {
48
// The name of the plugin
59
Name() string
@@ -30,16 +34,16 @@ type Storage interface {
3034
Stop() error
3135

3236
// Retrieve resources.
33-
GetResources(resource string, filters []interface{}) ([]map[string]interface{}, error)
37+
GetResources(resource string, filters []filter.ProcessedFilter) ([]map[string]interface{}, error)
3438

3539
// Create resources.
3640
CreateResources(resource string, data []map[string]interface{}) error
3741

3842
// Update resources.
39-
UpdateResources(resource string, data []map[string]interface{}, filters []interface{}) error
43+
UpdateResources(resource string, data []map[string]interface{}, filters []filter.ProcessedFilter) error
4044

4145
// Delete resources.
42-
DeleteResources(resource string, filters []interface{}) error
46+
DeleteResources(resource string, filters []filter.ProcessedFilter) error
4347
}
4448

4549
type Filter interface {
@@ -53,7 +57,10 @@ type Filter interface {
5357
Stop() error
5458

5559
// Validate structure for filter validness
56-
ValidateFilter(filter interface{}) (bool, error)
60+
ValidateFilter(filter filter.ProcessedFilter) (bool, error)
61+
62+
// Create a new instance of the filter
63+
CreateFilter(filter string) interface{}
5764
}
5865

5966
type Registry interface {

schema/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package schema
22

33
type Processor interface {
4-
// Get the store of a resource
4+
// Check if a resource schema exists
55
ResourceExists(resource string) bool
66

7-
// Get a list of all resources
7+
// Check if the resource structure is valid
88
ResourceValid(resource string, data string) (bool, error)
99

10+
// Get the schema of a resource
1011
GetSchema(resource string) *Schema
1112
}
1213

0 commit comments

Comments
 (0)