Middleware Plugin
Bring your own middlewares to pREST
With prestd's middleware plugin system it is possible to create new middlewares to process before reaching the http handler (endpoint).
Naming patterns
The prestd configuration file receives two parameters:
File name: name of the
.so
file to be loaded into the library path (file
in prestd config file), the root directory of middleware is the direct libraries (by default is./lib
) +/middlewares
folderFunction name: function name which will be loaded (
{func}MiddlewareLoad
, is actually the prefix of the function name)
Filename
The file name will be used in the middleware to identify which library will be loaded when the server (prestd) loads.
After the server loads, the library is not loaded again, it is just executed, i.e. if the file (
.so
) is changed after the server loads, the changes are not applied.
Function name
When talking about a compiled library we have no way of identifying its functions. Given this characteristic we have defined some name and behavior patterns to develop libraries for prestd.
function name: {Function Name}MiddlewareLoad
{Function Name}
: The name of the function that will be calledMiddlewareLoad
: The suffix of the function name - it is alwaysnegroni.HandlerFunc
fmt.Sprintf("%sMiddlewareLoad", funcName)
Example
Source code name:
./lib/src/middlewares/hello.go
Library file name:
./lib/middlewares/hello.so
Function name:
HelloMiddlewareLoad