Skip to content

Event directives

Cheikh Seck edited this page Dec 17, 2018 · 2 revisions

This page covers samb event directives. Syntax examples will be displayed for YAML and samb (.se) files. Each directive will have a table, the table will display the directive's name, type and parent. The parent of a directive specifies the directive it is nested in.

Events

Event directives allows users to have custom code run on pre-defined samb events.

App start

Event App start runs on application start. You can use this event to initialize the variables your application will use, this can be composed of database connections, flag variables, caches etc...

Directive name Type Parent
start Go Server

YAML sample :

...
  start:
    do:
      - println("HelloWorld")
      - println("Starting...")
...

.SE sample :

    start {
    	do println("HelloWorld");
    	do println("HelloWorld2");
    }

App stop

Event App stop runs on application exit. You can use this event to clean up the variables your application was using, this can be composed of closing database connections, clearing caches etc...

Directive name Type Parent
shutdown Go Server

YAML sample :

...
  shutdown:
    do:
      - println("HelloWorld")
      - println("Starting...")
...

.SE sample :

    shutdown {
    	do println("HelloWorld");
    	do println("HelloWorld2");
    }

Request panic

Event Request panic runs when a handler invokes builtin Go function panic, with a string as the only parameter. You can use this event to catch and process errors. You must generate the function responsible for handling a request panic. Use command samb-medic, provided in this repository, to generate a request panic (recovery) function. The generated function will have parameters:

  • r : the current request
  • w : response writer
  • m : error string, supplied as a parameter to invocation of builtin function panic.
Directive name Type Parent
recover Go Server

YAML sample :

...
  recover:
    do:
	  # only specify function identifier,
	  # parameters will be appended.
      - jsonPanic
...

.SE sample :

    recover {
    	do jsonPanic;
    }
Clone this wiki locally