Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Make filter configurable & remove some useless (#12)
Browse files Browse the repository at this point in the history
* filter factory

* make filter configurable & remove some useless

* Merge remote-tracking branch 'origin/master'

# Conflicts:
#	pkg/context/context.go
#	pkg/context/filter.go
#	pkg/filter/filter.go

* filter factory return error when necessary

* filter factory return error when necessary

* filter factory return error when necessary

* filter factory return error when necessary

* filter factory return error when necessary

* add base.go back

* remove filter.go

* remove filter.go
  • Loading branch information
mark4z authored Aug 29, 2021
1 parent 6088922 commit e3da6d7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 219 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/dubbogo/dubbo-go-pixiu-filter

go 1.14

require github.com/alibaba/sentinel-golang v1.0.2
87 changes: 0 additions & 87 deletions pkg/api/api.go

This file was deleted.

52 changes: 12 additions & 40 deletions pkg/api/config/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"time"
)

import (
"github.com/dubbogo/dubbo-go-pixiu-filter/pkg/api/config/ratelimit"
)

// HTTPVerb defines the restful api http verb
type HTTPVerb string

Expand Down Expand Up @@ -59,39 +55,10 @@ const (

// APIConfig defines the data structure of the api gateway configuration
type APIConfig struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Resources []Resource `json:"resources" yaml:"resources"`
Definitions []Definition `json:"definitions" yaml:"definitions"`
PluginFilePath string `json:"pluginFilePath" yaml:"pluginFilePath"`
PluginsGroup []PluginsGroup `json:"pluginsGroup" yaml:"pluginsGroup"`
RateLimit ratelimit.Config `json:"rateLimit" yaml:"rateLimit"`
}

type Plugin struct {
ID int64 `json:"id,inline,omitempty" yaml:"id,omitempty"`
Name string `json:"name" yaml:"name"`
Version string `json:"version" yaml:"version"`
Priority int `json:"priority" yaml:"priority"`
ExternalLookupName string `json:"externalLookupName" yaml:"externalLookupName"`
}

// PluginsGroup defines the plugins group info
type PluginsGroup struct {
ID int64 `json:"id,omitempty" yaml:"id,omitempty"`
GroupName string `json:"groupName" yaml:"groupName"`
Plugins []Plugin `json:"plugins" yaml:"plugins"`
}

//PluginsConfig defines the pre & post plugins
type PluginsConfig struct {
PrePlugins PluginsInUse `json:"pre" yaml:"pre"`
PostPlugins PluginsInUse `json:"post" yaml:"post"`
}

type PluginsInUse struct {
GroupNames []string `json:"groupNames" yaml:"groupNames"`
PluginNames []string `json:"pluginNames" yaml:"pluginNames"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Resources []Resource `json:"resources" yaml:"resources"`
Definitions []Definition `json:"definitions" yaml:"definitions"`
}

// Resource defines the API path
Expand All @@ -101,8 +68,7 @@ type Resource struct {
Path string `json:"path" yaml:"path"`
Timeout time.Duration `json:"timeout" yaml:"timeout"`
Description string `json:"description" yaml:"description"`
Filters []string `json:"filters" yaml:"filters"`
Plugins PluginsConfig `json:"plugins" yaml:"plugins"`
Filters []Filter `json:"filters" yaml:"filters"`
Methods []Method `json:"methods" yaml:"methods"`
Resources []Resource `json:"resources,omitempty" yaml:"resources,omitempty"`
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
Expand Down Expand Up @@ -137,14 +103,20 @@ func (r *Resource) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

// Filter filter with config
type Filter struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Config map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

// Method defines the method of the api
type Method struct {
ID int `json:"id,omitempty" yaml:"id,omitempty"`
ResourcePath string `json:"resourcePath" yaml:"resourcePath"`
Enable bool `json:"enable" yaml:"enable"` // true means the method is up and false means method is down
Timeout time.Duration `json:"timeout" yaml:"timeout"`
Mock bool `json:"mock" yaml:"mock"`
Filters []string `json:"filters" yaml:"filters"`
Filters []Filter `json:"filters" yaml:"filters"`
HTTPVerb `json:"httpVerb" yaml:"httpVerb"`
InboundRequest `json:"inboundRequest" yaml:"inboundRequest"`
IntegrationRequest `json:"integrationRequest" yaml:"integrationRequest"`
Expand Down
58 changes: 0 additions & 58 deletions pkg/api/config/ratelimit/config.go

This file was deleted.

5 changes: 1 addition & 4 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package context

import (
"github.com/dubbogo/dubbo-go-pixiu-filter/pkg/api"
"github.com/dubbogo/dubbo-go-pixiu-filter/pkg/router"
)

Expand All @@ -27,7 +26,7 @@ type Context interface {
Next()
Abort()
AbortWithError(string, error)
AppendFilterFunc(ff ...FilterFunc)
AppendFilter(ff ...func(Context))

Status(code int)
StatusCode() int
Expand All @@ -42,8 +41,6 @@ type Context interface {

API(router.API)
GetAPI() *router.API
Api(api *api.API)
GetApi() *api.API

GetClientIP() string
GetApplicationName() string
Expand Down
24 changes: 0 additions & 24 deletions pkg/context/filter.go

This file was deleted.

15 changes: 11 additions & 4 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ package filter

import "github.com/dubbogo/dubbo-go-pixiu-filter/pkg/context"

// Filter filter interface, used for context.FilterChain.
type Filter interface {
// Do run filter, use c.next() to next filter, before is pre logic, after is post logic.
Do() context.FilterFunc
// Filter filter func, filter
type Filter func(context.Context)

// Factory filter Factory, for FilterFunc. filter manager will fill the Configuration from local or config center
type Factory interface {
// Config return the pointer of config
Config() interface{}

// Apply return the filter func, initialize whatever you want before return the func
// use c.next() to next filter, before is pre logic, after is post logic.
Apply() (Filter, error)
}

// ErrResponse err response.
Expand Down

0 comments on commit e3da6d7

Please sign in to comment.