beardlessCat opened a new issue, #134:
URL: https://github.com/apache/apisix-go-plugin-runner/issues/134

   ### Issue description
   
   ### Environment
   
   * APISIX Go Plugin Runner's version: 0.5.0
   * APISIX version:3.2.0
   * Go version:1.17.6
   * OS (cmd: `uname -a`):linux
   
   The code is as follows
   `
   
   func init() {
        err := plugin.RegisterPlugin(&MyRewriteResponse{})
        if err != nil {
                log.Fatalf("failed to register plugin MyRewriteResponse: %s", 
err)
        }
   }
   
   // it to the upstream.
   type MyRewriteResponse struct {
        // Embed the default plugin here,
        // so that we don't need to reimplement all the methods.
        plugin.DefaultPlugin
   }
   
   type MyRewriteResponseConf struct {
        Tag string `json:"tag"`
   }
   
   func (p *MyRewriteResponse) Name() string {
        return "my-rewrite-response"
   }
   
   func (p *MyRewriteResponse) ParseConf(in []byte) (interface{}, error) {
        conf := MyRewriteResponseConf{}
        err := json.Unmarshal(in, &conf)
        return conf, err
   }
   
   func (p *MyRewriteResponse) ResponseFilter(conf interface{}, w 
pkgHTTP.Response) {
        w.Header().Set("responseid", uuid.New().String())
        tag := conf.(MyRewriteResponseConf).Tag
        if len(tag) > 0 {
                _, err := w.Write([]byte(tag))
                if err != nil {
                        log.Errorf("failed to write: %s", err)
                }
        }
   }
   
   `
   the config as flows:
   `
   {
     "uri": "/user/*",
     "name": "用户服务",
     "desc": "用户服务",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE",
       "PURGE"
     ],
     "plugins": {
       "ext-plugin-post-resp": {
         "_meta": {
           "disable": false
         },
         "conf": [
           {
             "name": "my-rewrite-response",
             "value": "{\"tag\":\"hello my-rewrite-response\"}"
           }
         ]
       }
     },
     "upstream_id": "454615881717122005",
     "labels": {
       "API_VERSION": "V1"
     },
     "status": 1
   }
   `
   
![image](https://user-images.githubusercontent.com/13743949/230706615-10acf6ab-e350-4849-b0d0-f4a9b04917f7.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to