Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add DefaultPlugin #92

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/go-runner/plugins/fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func init() {

// FaultInjection is used in the benchmark
type FaultInjection struct {
// Embed the default plugin here,
// so that we don't need to reimplement all the methods.
plugin.DefaultPlugin
}

type FaultInjectionConf struct {
Expand Down Expand Up @@ -94,7 +97,3 @@ func (p *FaultInjection) RequestFilter(conf interface{}, w http.ResponseWriter,
log.Errorf("failed to write: %s", err)
}
}

func (p *FaultInjection) ResponseFilter(interface{}, pkgHTTP.Response) {

}
7 changes: 3 additions & 4 deletions cmd/go-runner/plugins/limit_req.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func init() {

// LimitReq is a demo for a real world plugin
type LimitReq struct {
// Embed the default plugin here,
// so that we don't need to reimplement all the methods.
plugin.DefaultPlugin
}

type LimitReqConf struct {
Expand Down Expand Up @@ -75,7 +78,3 @@ func (p *LimitReq) RequestFilter(conf interface{}, w http.ResponseWriter, r pkgH
}
time.Sleep(rs.Delay())
}

func (p *LimitReq) ResponseFilter(interface{}, pkgHTTP.Response) {

}
7 changes: 3 additions & 4 deletions cmd/go-runner/plugins/response_rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package plugins

import (
"encoding/json"
"net/http"

pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http"
"github.com/apache/apisix-go-plugin-runner/pkg/log"
Expand All @@ -35,6 +34,9 @@ func init() {

// ResponseRewrite is a demo to show how to rewrite response data.
type ResponseRewrite struct {
// Embed the default plugin here,
// so that we don't need to reimplement all the methods.
plugin.DefaultPlugin
}

type ResponseRewriteConf struct {
Expand All @@ -53,9 +55,6 @@ func (p *ResponseRewrite) ParseConf(in []byte) (interface{}, error) {
return conf, err
}

func (p *ResponseRewrite) RequestFilter(interface{}, http.ResponseWriter, pkgHTTP.Request) {
}

func (p *ResponseRewrite) ResponseFilter(conf interface{}, w pkgHTTP.Response) {
cfg := conf.(ResponseRewriteConf)
if cfg.Status > 0 {
Expand Down
7 changes: 3 additions & 4 deletions cmd/go-runner/plugins/say.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func init() {
// Say is a demo to show how to return data directly instead of proxying
// it to the upstream.
type Say struct {
// Embed the default plugin here,
// so that we don't need to reimplement all the methods.
plugin.DefaultPlugin
}

type SayConf struct {
Expand Down Expand Up @@ -64,7 +67,3 @@ func (p *Say) RequestFilter(conf interface{}, w http.ResponseWriter, r pkgHTTP.R
log.Errorf("failed to write: %s", err)
}
}

func (p *Say) ResponseFilter(interface{}, pkgHTTP.Response) {

}
6 changes: 6 additions & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ type Plugin interface {
func RegisterPlugin(p Plugin) error {
return plugin.RegisterPlugin(p.Name(), p.ParseConf, p.RequestFilter, p.ResponseFilter)
}

// DefaultPlugin provides the no-op implementation of the Plugin interface.
type DefaultPlugin struct{}

func (*DefaultPlugin) RequestFilter(interface{}, http.ResponseWriter, pkgHTTP.Request) {}
func (*DefaultPlugin) ResponseFilter(interface{}, pkgHTTP.Response) {}