You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/05/31 02:07:28 UTC

[apisix-go-plugin-runner] 21/22: feat: expose ConfToken method

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-go-plugin-runner.git

commit 4ad02dec9e6d409344ca01a58944cf6b73881466
Author: spacewander <sp...@gmail.com>
AuthorDate: Fri May 28 10:21:45 2021 +0800

    feat: expose ConfToken method
---
 internal/plugin/plugin.go | 11 +++++++++--
 pkg/http/http.go          |  5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go
index b88ade7..b7400b0 100644
--- a/internal/plugin/plugin.go
+++ b/internal/plugin/plugin.go
@@ -15,6 +15,7 @@
 package plugin
 
 import (
+	"context"
 	"net/http"
 
 	hrc "github.com/api7/ext-plugin-proto/go/A6/HTTPReqCall"
@@ -25,7 +26,7 @@ import (
 	pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http"
 )
 
-func handle(conf RuleConf, w http.ResponseWriter, r pkgHTTP.Request) error {
+func handle(conf RuleConf, ctx context.Context, w http.ResponseWriter, r pkgHTTP.Request) error {
 	return nil
 }
 
@@ -36,6 +37,10 @@ func reportAction(id uint32, req *inHTTP.Request, resp *inHTTP.Response) *flatbu
 		return builder
 	}
 
+	if req != nil && req.FetchChanges(id, builder) {
+		return builder
+	}
+
 	hrc.RespStart(builder)
 	hrc.RespAddId(builder, id)
 	res := hrc.RespEnd(builder)
@@ -55,7 +60,9 @@ func HTTPReqCall(buf []byte) (*flatbuffers.Builder, error) {
 	if err != nil {
 		return nil, err
 	}
-	err = handle(conf, resp, req)
+
+	ctx := context.Background()
+	err = handle(conf, ctx, resp, req)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/http/http.go b/pkg/http/http.go
index cfc4284..d7ca549 100644
--- a/pkg/http/http.go
+++ b/pkg/http/http.go
@@ -32,6 +32,11 @@ import (
 type Request interface {
 	// ID returns the request id
 	ID() uint32
+	// ConfToken returns the token represents the configuration of current route.
+	// Each route have its unique token, so we can use it to distinguish different
+	// route in the same plugin.
+	ConfToken() uint32
+
 	// SrcIP returns the client's IP
 	SrcIP() net.IP
 	// Method returns the HTTP method (GET, POST, PUT, etc.)