Skip to content

Commit

Permalink
tweak struct & improve comment (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Nov 16, 2023
1 parent 7022f99 commit 2ae736f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
7 changes: 1 addition & 6 deletions pkg/filtermanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ type BufferInstance = api.BufferInstance
type RequestTrailerMap = api.RequestTrailerMap
type ResponseTrailerMap = api.ResponseTrailerMap

type FilterConfigParser interface {
Parse(input interface{}, callbacks ConfigCallbackHandler) (interface{}, error)
Merge(parentConfig interface{}, childConfig interface{}) interface{}
}
type FilterConfigFactory func(config interface{}) FilterFactory

type StreamInfo = api.StreamInfo
type FilterCallbackHandler interface {
StreamInfo() StreamInfo
Expand All @@ -87,6 +81,7 @@ type FilterCallbackHandler interface {
}

type FilterFactory func(callbacks FilterCallbackHandler) Filter
type FilterConfigFactory func(config interface{}) FilterFactory

type DynamicMetadata = api.DynamicMetadata
type FilterState = api.FilterState
Expand Down
16 changes: 12 additions & 4 deletions pkg/filtermanager/filtermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ var (
httpFilterConfigFactoryAndParser = sync.Map{}
)

// Here we introduce extra struct to avoid cyclic import between pkg/filtermanager and pkg/plugins
type FilterConfigParser interface {
Parse(input interface{}, callbacks api.ConfigCallbackHandler) (interface{}, error)
Merge(parentConfig interface{}, childConfig interface{}) interface{}
}

type filterConfigFactoryAndParser struct {
configParser api.FilterConfigParser
configParser FilterConfigParser
configFactory api.FilterConfigFactory
}

// we can't import package below here which will cause the integration test to fail in Mac
// We can't import package below here that will cause build failure in Mac
// "github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http"
// therefore, we choice to export these fields
// Therefore, the FilterManagerConfigParser & FilterManagerConfigFactory need to be exportable.
// The http.RegisterHttpFilterConfigFactoryAndParser will be called in the main.go when building
// the shared library in Linux.

type FilterManagerConfigParser struct {
}
Expand Down Expand Up @@ -478,7 +486,7 @@ func (m *filterManager) OnLog() {
}
}

func RegisterHttpFilterConfigFactoryAndParser(name string, factory api.FilterConfigFactory, parser api.FilterConfigParser) {
func RegisterHttpFilterConfigFactoryAndParser(name string, factory api.FilterConfigFactory, parser FilterConfigParser) {
if factory == nil {
panic("config factory should not be nil")
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func (cp *PluginConfigParser) Parse(any interface{}, callbacks api.ConfigCallbac
// PluginMethodDefaultImpl provides reasonable implementation for optional methods
type PluginMethodDefaultImpl struct{}

func (p *PluginMethodDefaultImpl) Handle(c interface{}, callbacks api.ConfigCallbackHandler) (interface{}, error) {
return c, nil
}

func (p *PluginMethodDefaultImpl) Merge(parent interface{}, child interface{}) interface{} {
return child
}

0 comments on commit 2ae736f

Please sign in to comment.