Skip to content

Commit

Permalink
added docs/plugin-tutorial.md. fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceWangNo1 committed Jun 3, 2019
1 parent 3270fa2 commit d11ae82
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
version = flag.Bool("version", false, "Show version info")

// internal plugin configuration file
jwtCfg = flag.String("jwt", "", "PLugin(JWT): jwt plugin configuration file, json format")
jwtCfg = flag.String("jwt", "", "Plugin(JWT): jwt plugin configuration file, json format")

// metric
metricJob = flag.String("metric-job", "", "prometheus job name")
Expand Down
Binary file added docs/images/defaultFilters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/specs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/plugin-tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tutorial
This tutorial aims to teach you how to make your own plugins.
If you just started dealing with Gateway and want to add a plugin to fulfill your deployment needs, then congradulations, you have come to the right place!
I have gone through a lot of pain trying to figure out how to write my JWT plugin. And thanks to the in-time replies of the maintainer and other members of the community, I finally made it. I wrapped up my weary and yet fruitful journey and published this tutorial in the hope that future newcomers have a detailed reference to look up.
If you encounter any problem going through the tutorial, feel free to create an issue or send me an email to this address **[email protected]** with the subject "Issues with Gateway Tutorial."

## JWT Plugin Example
First of all, since we are developing a JWT plugin to authenticate external requests, most of us have already had some working knowledge of JWT. If not, [this official introduction](https://jwt.io/introduction/) is pretty informative. For Chinese developers, [this link from Ruan Yifeng's blog](http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html) is an excellent concise alternative.

### Source Code Walk-through
**pkg/filter/filter.go** is pretty much an empty abstract from which **\*Filters** structs in **pkg/proxy/filter_\*.go** inherit the **BaseFilter** struct. For example, struct **ValidationFilter** only implementes methods **Init()**, **Name()**, and **Pre()**. These methods in **BaseFilter** are overridden and others remain available.
For JWT plugins, you should name your file like **filter_my_plugin.go** under **pkg/proxy/** and refer to **filter_plugin.go** to write your own.
**\*.so** plugin as mentioned in the [docs/plugin.md](plugin.md), which involves **cgo** is really troublesome and thus highly discouraged.
After you have finished your plugin file, a plugin json configuration file is needed. For more information, please reference to [this json configuration file example](https://github.com/fagongzi/jwt-plugin).
For your JWT plugin to take effect, you need to pass options **--filter JWT** and **--jwt yourJSONConfigurationFilePath**. This is because neither **filter_jwt.go** nor your plugin is in **defaultFilters** in **pkg/proxy/proxy.go**.
![](./images/defaultFilters.png)
If one of the **defaultFilters** is expected to be used, please specify it by **--filter** like **--filter WHITELIST** when launching **proxy** because if there is **--filter**, **defaultFilters** gets discarded.
![](./images/specs.png)

4 changes: 2 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Tutorial
If you have not dealt much with HTTP gateway before and want to deploy one in your company or just play with one, then congradulations, you have come to right place!
If you have not dealt much with HTTP gateway before and want to deploy one in your company or just play with one, then congradulations, you have come to the right place!
This tutorial is very user-friendly. It aims to assist first-timers to have a hands-on experience without going through the pain of searching, asking and wondering.
This was tested on a **MacOS** environment.
If you encounter any problem going through the tutorial, feel free to create an issue or send me an email **[email protected]** with subject "Issues with Gateway Tutorial".
If you encounter any problem going through the tutorial, feel free to create an issue or send me an email to this address **[email protected]** with the subject "Issues with Gateway Tutorial."

## ETCD Setup
ETCD is a distributed key-value storage required to store **Gateway configurations**.
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
// ErrUnknownFilter unknown filter error
ErrUnknownFilter = errors.New("unknow filter")
ErrUnknownFilter = errors.New("unknown filter")
)

const (
Expand Down

0 comments on commit d11ae82

Please sign in to comment.