[docs] restructure the example code, and add 'enter'/'leave' middleware examples