MasterKenway commented on a change in pull request #277:
URL: https://github.com/apache/dubbo-go-pixiu/pull/277#discussion_r730267876



##########
File path: docs/developer/filter.md
##########
@@ -1,49 +1,200 @@
 # Filter
 
-Filter is the composition of filter chain, make use more control.
 
-## Default filter
+Filter provides request handle abstraction. user can combinate many filter 
together into filter-chain.
 

Review comment:
       the first charater of user should be upper case and the `filter` should 
be `filters`

##########
File path: docs/developer/filter.md
##########
@@ -1,49 +1,200 @@
 # Filter
 
-Filter is the composition of filter chain, make use more control.
 
-## Default filter
+Filter provides request handle abstraction. user can combinate many filter 
together into filter-chain.
 
-### Remote filter
+When receive request from listener, filter will handle it in the order at pre 
or post phase.
 
-call downstream service, only for call, not process the response. 
+Because pixiu want offer network protocol transform function, so the filter 
contains network filter and the filter below network filter such as http filter.
 

Review comment:
       change `want` to `want to`, `offer` to `provider`

##########
File path: docs/developer/filter.md
##########
@@ -1,49 +1,200 @@
 # Filter
 
-Filter is the composition of filter chain, make use more control.
 
-## Default filter
+Filter provides request handle abstraction. user can combinate many filter 
together into filter-chain.
 
-### Remote filter
+When receive request from listener, filter will handle it in the order at pre 
or post phase.
 
-call downstream service, only for call, not process the response. 
+Because pixiu want offer network protocol transform function, so the filter 
contains network filter and the filter below network filter such as http filter.
 
-#### field
+the request handle process like below.
+```
+client -> listner -> network filter such as httpconnectionmanager -> http 
filter chain
+
+```
+
+### Http Filter List
+
+You can find out all filters in pkg/filter, just list some import ones.
+
+- ratelimit the filter provides rate limit function using sentinel-go;
+- timeout the filter provides timeout function;
+- tracing the filter provides tracing function with jaeger;
+- grpcproxy the filter provides http to grpc proxy function;
+- httpproxy the filter provides http to http proxy function;
+- proxywrite the filter provides http request path or header amend function;
+- apiconfig the filter provides http to dubbo transform mapping function with 
remote filter;
+- remote the filter provides http to dubbo proxy function with apiconfig 
filter.
+
+
+### How to define custom http filter
+#### step one
+
+There are two abstraction interface: plugin and filter.
+
+```go
+// HttpFilter describe http filter
+type HttpFilter interface {
+    // PrepareFilterChain add filter into chain
+    PrepareFilterChain(ctx *http.HttpContext) error
+
+    // Handle filter hook function
+    Handle(ctx *http.HttpContext)
+
+    Apply() error
+
+    // Config get config for filter
+    Config() interface{}
+}
+
+// HttpFilter describe http filter
+type HttpFilter interface {
+    // PrepareFilterChain add filter into chain
+    PrepareFilterChain(ctx *http.HttpContext) error
+
+    // Handle filter hook function
+    Handle(ctx *http.HttpContext)
+
+    Apply() error
+
+    // Config get config for filter
+    Config() interface{}
+}
+```
+
+You should define yourself plugin and filter, then implement its function.
+
+Otherwise, you maybe would define filter-own config like as below.
+
+```go
+// Config describe the config of Filter
+type Config struct {           
+       AllowOrigin []string `yaml:"allow_origin" json:"allow_origin" 
mapstructure:"allow_origin"`
+       // AllowMethods access-control-allow-methods
+       AllowMethods string `yaml:"allow_methods" json:"allow_methods" 
mapstructure:"allow_methods"`
+       // AllowHeaders access-control-allow-headers
+       AllowHeaders string `yaml:"allow_headers" json:"allow_headers" 
mapstructure:"allow_headers"`
+       // ExposeHeaders access-control-expose-headers
+       ExposeHeaders string `yaml:"expose_headers" json:"expose_headers" 
mapstructure:"expose_headers"`
+       // MaxAge access-control-max-age
+       MaxAge           string `yaml:"max_age" json:"max_age" 
mapstructure:"max_age"`
+       AllowCredentials bool   `yaml:"allow_credentials" 
json:"allow_credentials" mapstructure:"allow_credentials"`
+}
+```
 
-> level: mockLevel 
- 
-- 0:open Global mock is open, api need config `mock=true` in `api_config.yaml` 
will mock response. If some api need mock, you need use this. 
-- 1:close Not mock anyone.
-- 2:all Global mock setting, all api auto mock.
+You can initialize filter-own config instance when plugin CreateFilter, and 
return it at config function.
 
-result
-```json
-{
-    "message": "success"
+```go
+
+func (p *Plugin) CreateFilter() (filter.HttpFilter, error) {
+     return &Filter{cfg: &Config{}}, nil
+}
+
+func (f *Filter) Config() interface{} {
+       return f.cfg
 }
 ```
+Then pixiu will fill it's value using the value in pixiu config yaml.
 
-#### Pixiu log 
-```bash
-2020-11-17T11:31:05.718+0800    DEBUG   remote/call.go:92       
[dubbo-go-pixiu] client call resp:map[age:88 iD:3213 name:tiecheng time:<nil>]
+After filling config value, pixiu will call Apply function, you should prepare 
filter, such as fetch remote info etc.
+
+when request comes, pixiu will call PrepareFilterChain function to allow 
filter add itself into request-filter-chain.
+
+```go
+func (f *Filter) PrepareFilterChain(ctx *http.HttpContext) error {
+       ctx.AppendFilterFunc(f.Handle)
+       return nil
+}
 ```
+If not use AppendFilterFunc to add self into filter-chain, then filter will 
not handle the request this time.
 
-### Timeout filter
+Finally pixiu will call Handle function.
 
-api timeout control, independent config for each interface.
+```go
+func (f *Filter) Handle(ctx *http.HttpContext) {
+       f.handleCors(ctx)
+       ctx.Next()
+}
+
+```
 
-#### Basic response
+There are two phase during request handle, pre and post. before calling 
ctx.Next function, there is pre phase,otherwise there is post phase.
 

Review comment:
       `phase` to `phases`, `otherwise` should has black space before

##########
File path: docs/user/config.md
##########
@@ -0,0 +1,130 @@
+
+
+### Config
+ 
+Pixiu supports specifying local config file with argument -c which you can 
find in those samples pixiu dir. 
+

Review comment:
       quote `-c` with anti quotation marks to emphasize

##########
File path: docs/developer/filter.md
##########
@@ -1,49 +1,200 @@
 # Filter
 
-Filter is the composition of filter chain, make use more control.
 
-## Default filter
+Filter provides request handle abstraction. user can combinate many filter 
together into filter-chain.
 
-### Remote filter
+When receive request from listener, filter will handle it in the order at pre 
or post phase.
 

Review comment:
       `receive` to `revieved` and what about changing `phase` to `condition`

##########
File path: docs/user/config.md
##########
@@ -0,0 +1,130 @@
+
+
+### Config
+ 
+Pixiu supports specifying local config file with argument -c which you can 
find in those samples pixiu dir. 
+
+Pixiu use the config abstraction like envoy such as listener, filter, route 
and cluster.
+
+Besides, pixiu provides another dubbo-specific config named api_config which 
dubbo-filter used to  transform http request to dubbo generic call. you can 
find it in those samples pixiu dir too.
+
+The api_config specification you can refer to this document [Api 
Model](api.md).
+
+This document mainly describes the pixiu config abstraction, there is a 
example below:
+```yaml
+
+static_resources:
+  listeners:
+    - name: "net/http"
+      address:
+        socket_address:
+          protocol_type: "HTTP"
+          address: "0.0.0.0"
+          port: 8888
+      filter_chains:
+        - filter_chain_match:
+          domains:
+            - api.dubbo.com
+            - api.pixiu.com
+          filters:
+            - name: dgp.filter.httpconnectionmanager
+              config:
+                route_config:
+                  routes:
+                    - match:
+                        prefix: "/user"
+                      route:
+                        cluster: "user"
+                        cluster_not_found_response_code: 505
+                http_filters:
+                  - name: dgp.filter.http.httpproxy
+                    config:
+                  - name: dgp.filter.http.response
+                    config:
+  clusters:
+    - name: "user"
+      lb_policy: "lb"
+      endpoints:
+        - id: 1
+          socket_address:
+            address: 127.0.0.1
+            port: 1314
+```
+The more detail will be found in pkg/model/bootstrap.go
+

Review comment:
       `The more detail` to `More details`

##########
File path: docs/user/config.md
##########
@@ -0,0 +1,130 @@
+
+
+### Config
+ 
+Pixiu supports specifying local config file with argument -c which you can 
find in those samples pixiu dir. 
+
+Pixiu use the config abstraction like envoy such as listener, filter, route 
and cluster.
+

Review comment:
       `use` to `uses`




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to