From 34f209d1ff65364d9563871047cbfb06dfda3131 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Wed, 17 Oct 2018 22:15:55 +0300 Subject: [PATCH 1/4] Refactor to StratoAPI --- LICENSE | 2 +- README.md | 2 +- go.mod | 6 +++--- main.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 6730d53..94c6a28 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018 ResourceAPI Team + Copyright 2018 StratoAPI Team Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index ed070f7..4ac2f83 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Plugin-Skeleton -An example plugin for ResourceAPI/Core +An example plugin for StratoAPI/Core diff --git a/go.mod b/go.mod index 3141e6a..8a4ef1b 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ -module github.com/ResourceAPI/Plugin-Skeleton +module github.com/StratoAPI/Plugin-Skeleton -replace github.com/ResourceAPI/Interface v0.0.0 => ../Interface +replace github.com/StratoAPI/Interface v0.0.0 => ../Interface -require github.com/ResourceAPI/Interface v0.0.0 +require github.com/StratoAPI/Interface v0.0.0 diff --git a/main.go b/main.go index f4b0c83..239cee1 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/ResourceAPI/Interface/plugins" + "github.com/StratoAPI/Interface/plugins" - "github.com/ResourceAPI/Plugin-Skeleton/skeleton" + "github.com/StratoAPI/Plugin-Skeleton/skeleton" ) type SkeletonPlugin string From a01e7abac4139731a362d430597d392102a0fe61 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Mon, 22 Oct 2018 03:42:06 +0300 Subject: [PATCH 2/4] Add filtering, add simple filter --- Makefile | 4 ++++ go.mod | 4 +--- go.sum | 4 ++++ skeleton/filter.go | 9 ++++++++- skeleton/storage.go | 8 +++++--- 5 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 go.sum diff --git a/Makefile b/Makefile index 6bc12fb..3ea2f8d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ GOCMD=go GOBUILD=$(GOCMD) build +GOMOD=$(GOCMD) mod BINARY_NAME=skeleton.so all: build @@ -7,5 +8,8 @@ all: build build: $(GOBUILD) -buildmode=plugin -o $(BINARY_NAME) main.go +tidy: + $(GOMOD) tidy + clean: rm -f $(BINARY_NAME) \ No newline at end of file diff --git a/go.mod b/go.mod index 8a4ef1b..3c4c354 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/StratoAPI/Plugin-Skeleton -replace github.com/StratoAPI/Interface v0.0.0 => ../Interface - -require github.com/StratoAPI/Interface v0.0.0 +require github.com/StratoAPI/Interface v0.0.6 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..987665c --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/StratoAPI/Interface v0.0.4 h1:QsoEeeJUe/+K9TToFwYexoIlhvj6ofl27ZnJNwB35mo= +github.com/StratoAPI/Interface v0.0.4/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= +github.com/StratoAPI/Interface v0.0.5/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= +github.com/StratoAPI/Interface v0.0.6/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= diff --git a/skeleton/filter.go b/skeleton/filter.go index d99e690..1318141 100644 --- a/skeleton/filter.go +++ b/skeleton/filter.go @@ -1,5 +1,7 @@ package skeleton +import "github.com/StratoAPI/Interface/filter" + type SkeletonFilter struct { } @@ -19,6 +21,11 @@ func (skeleton SkeletonFilter) Stop() error { } // Validate structure for filter validness -func (skeleton SkeletonFilter) ValidateFilter(filter interface{}) (bool, error) { +func (skeleton SkeletonFilter) ValidateFilter(filter filter.ProcessedFilter) (bool, error) { return false, nil // TODO } + +// Create a new instance of the filter +func (skeleton SkeletonFilter) CreateFilter(filter string) (interface{}, error) { + return nil, nil // TODO +} diff --git a/skeleton/storage.go b/skeleton/storage.go index d1e196c..26056d9 100644 --- a/skeleton/storage.go +++ b/skeleton/storage.go @@ -1,5 +1,7 @@ package skeleton +import "github.com/StratoAPI/Interface/filter" + type SkeletonStorage struct { } @@ -19,7 +21,7 @@ func (storage SkeletonStorage) Stop() error { } // Retrieve resources. -func (storage SkeletonStorage) GetResources(resource string, filters []interface{}) ([]map[string]interface{}, error) { +func (storage SkeletonStorage) GetResources(resource string, filters []filter.ProcessedFilter) ([]map[string]interface{}, error) { return nil, nil // TODO } @@ -29,11 +31,11 @@ func (storage SkeletonStorage) CreateResources(resource string, data []map[strin } // Update resources. -func (storage SkeletonStorage) UpdateResources(resource string, data []map[string]interface{}, filters []interface{}) error { +func (storage SkeletonStorage) UpdateResources(resource string, data []map[string]interface{}, filters []filter.ProcessedFilter) error { return nil // TODO } // Delete resources. -func (storage SkeletonStorage) DeleteResources(resource string, filters []interface{}) error { +func (storage SkeletonStorage) DeleteResources(resource string, filters []filter.ProcessedFilter) error { return nil // TODO } From a115ced3505d5f055ea3aad05dd48186667f494e Mon Sep 17 00:00:00 2001 From: Vilsol Date: Tue, 23 Oct 2018 07:01:32 +0300 Subject: [PATCH 3/4] Complete REST and Flatfile-JSON implementations --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 3c4c354..f632c7d 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/StratoAPI/Plugin-Skeleton -require github.com/StratoAPI/Interface v0.0.6 +require github.com/StratoAPI/Interface v0.0.8 diff --git a/go.sum b/go.sum index 987665c..1f9b42a 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ -github.com/StratoAPI/Interface v0.0.4 h1:QsoEeeJUe/+K9TToFwYexoIlhvj6ofl27ZnJNwB35mo= -github.com/StratoAPI/Interface v0.0.4/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= -github.com/StratoAPI/Interface v0.0.5/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= -github.com/StratoAPI/Interface v0.0.6/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= +github.com/StratoAPI/Interface v0.0.8 h1:iOh/54yilmULpuS1t849SU91HTlLYyt5Dc1a8rFb5Bg= +github.com/StratoAPI/Interface v0.0.8/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= From f7e227e938acdda6ac10f143dd5bfd561cb2d1e0 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Sun, 28 Oct 2018 22:57:18 +0200 Subject: [PATCH 4/4] Add middleware support --- go.mod | 2 +- go.sum | 4 ++-- main.go | 1 + skeleton/middleware.go | 35 +++++++++++++++++++++++++++++++++++ skeleton/storage.go | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 skeleton/middleware.go diff --git a/go.mod b/go.mod index f632c7d..d9e5129 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/StratoAPI/Plugin-Skeleton -require github.com/StratoAPI/Interface v0.0.8 +require github.com/StratoAPI/Interface v0.0.11 diff --git a/go.sum b/go.sum index 1f9b42a..19883a9 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/StratoAPI/Interface v0.0.8 h1:iOh/54yilmULpuS1t849SU91HTlLYyt5Dc1a8rFb5Bg= -github.com/StratoAPI/Interface v0.0.8/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= +github.com/StratoAPI/Interface v0.0.11 h1:oms2ia6Rl6TBC98umloNGthx5+aFPDP1oK+1aMog7Ds= +github.com/StratoAPI/Interface v0.0.11/go.mod h1:jLlD9bBfAuFE0VN6FkrvX3cMhuDnbikzonCMprOLsyw= diff --git a/main.go b/main.go index 239cee1..4ddc138 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ func (SkeletonPlugin) Entrypoint() { plugins.GetRegistry().RegisterFacade("skeleton", &skeleton.SkeletonFacade{}) plugins.GetRegistry().RegisterStorage("skeleton", &skeleton.SkeletonStorage{}) plugins.GetRegistry().RegisterFilter("skeleton", &skeleton.SkeletonFilter{}) + plugins.GetRegistry().RegisterMiddleware("skeleton", &skeleton.SkeletonMiddleware{}) plugins.GetRegistry().AssociateFilter("skeleton", "skeleton") fmt.Println("Skeleton Plugin Initialized") } diff --git a/skeleton/middleware.go b/skeleton/middleware.go new file mode 100644 index 0000000..2f9ece0 --- /dev/null +++ b/skeleton/middleware.go @@ -0,0 +1,35 @@ +package skeleton + +import "github.com/StratoAPI/Interface/middleware" + +type SkeletonMiddleware struct { +} + +// Initialize the facade. +func (middleware SkeletonMiddleware) Initialize() error { + return nil // TODO +} + +// Start the facade. Must be a blocking call. +func (middleware SkeletonMiddleware) Start() error { + return nil // TODO +} + +// Graceful stopping of the facade with a 30s timeout. +func (middleware SkeletonMiddleware) Stop() error { + return nil // TODO +} + +// Validate request +// If returns nil, it will pass the request onwards +// If returns a pointer, request will get replied to with provided response +func (middleware SkeletonMiddleware) Request(resource string, headers map[string][]string, config interface{}) *middleware.RequestResponse { + return nil // TODO +} + +// Validate and filter response +// If returns nil, it will pass the request onwards with the returned data +// If returns a pointer, request will get replied to with provided response without data +func (middleware SkeletonMiddleware) Response(resource string, headers map[string][]string, data []map[string]interface{}, config interface{}) ([]map[string]interface{}, *middleware.RequestResponse) { + return data, nil // TODO +} diff --git a/skeleton/storage.go b/skeleton/storage.go index 26056d9..8b58b39 100644 --- a/skeleton/storage.go +++ b/skeleton/storage.go @@ -31,7 +31,7 @@ func (storage SkeletonStorage) CreateResources(resource string, data []map[strin } // Update resources. -func (storage SkeletonStorage) UpdateResources(resource string, data []map[string]interface{}, filters []filter.ProcessedFilter) error { +func (storage SkeletonStorage) UpdateResources(resource string, data map[string]interface{}, filters []filter.ProcessedFilter) error { return nil // TODO }