From c2ee8b5e048d0018ee759f4bb449cf3c6722a1ac Mon Sep 17 00:00:00 2001 From: Daria Mayorova Date: Wed, 10 May 2017 18:55:07 +0200 Subject: [PATCH] [doc] grammar nazi readme fixes --- examples/custom-module/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/custom-module/README.md b/examples/custom-module/README.md index fa2be2f07..42299c2ed 100644 --- a/examples/custom-module/README.md +++ b/examples/custom-module/README.md @@ -1,11 +1,13 @@ # Custom Module -Module is something, that is executed in each nginx phase: init, init_worker, rewrite, access, content, log, post_action, balancer, header_filter, body_filter, ... +Module is something, that is executed in each nginx phase: init, init_worker, rewrite, access, content, log, post_action, balancer, header_filter, body_filter etc. It handles processing of each request. There can be only ONE module that is being executed. -The name of the module that is executed is defined by environment variable `APICAST_MODULE` and defaults to `apicast`. +The name of the module that is executed is defined by the environment variable `APICAST_MODULE` and defaults to `apicast`. -This example implements a module that extends apicast default one and adds more logging. +The example described in this README implements a module that extends the default `apicast` module and adds more logging. + +There is another example of custom module implementation for IP blacklisting in [`blacklist.lua`](blacklist.lua). ## Starting the gateway @@ -13,7 +15,7 @@ This example implements a module that extends apicast default one and adds more APICAST_MODULE=$(pwd)/verbose.lua ../../bin/apicast -c $(pwd)/../configuration/local.json ``` -This starts apicast with module `verbose.lua` instead of the default [`apicast.lua`](https://github.com/3scale/apicast/blob/master/apicast/src/apicast.lua). Using local configuration so no 3scale account is needed. +This starts APIcast with module `verbose.lua` instead of the default [`apicast.lua`](https://github.com/3scale/apicast/blob/master/apicast/src/apicast.lua). Local configuration file is used, so no 3scale account is needed. ## Testing @@ -21,15 +23,13 @@ This starts apicast with module `verbose.lua` instead of the default [`apicast.l curl 'localhost:8080?user_key=foo' ``` -And see in the apicast output: +And see in the APIcast output: ``` 2016/11/16 16:52:00 [warn] 98009#0: *5 [lua] verbose.lua:7: call(): upstream response time: 0.001 upstream connect time: 0.000 while logging request, client: 127.0.0.1, server: _, request: "GET /?user_key=foo HTTP/1.1", upstream: "http://127.0.0.1:8081/?user_key=foo", host: "echo" ``` -## Writing own module - -There is example module of IP blacklist in [`blacklist.lua`](blacklist.lua). +## Writing a custom module To honour the module inheritance, but still be able to override some methods from the `apicast` module, you'll need some clever use of metatables. Here is a recommended skeleton of the module inheritance: @@ -48,11 +48,11 @@ local mt = { __index = setmetatable(_M, { __index = apicast }) } function _M.new() -- this method is going to get called after this file is required - -- so create new table for internal state (global) and set the metatable for inheritance + -- so create a new table for the internal state (global) and set the metatable for inheritance return setmetatable({}, mt) end --- to run some custom code in log phase lets override the method +-- to run some custom code in the log phase let's override the method function _M.log() ngx.log(ngx.WARN, 'upstream response time: ', ngx.var.upstream_response_time, ' ',