Shutdown hook

How to add shutdown hook function while receiving shutdown signal?

Overview

We need to understand how bootstrapper stop process.

  1. Add shutdown hook functions by user
  2. Call functions as soon as receive signal from outside

Getting started

package main

import (
	"context"
	"github.com/rookie-ninja/rk-boot"
	"github.com/rookie-ninja/rk-echo/interceptor/context"
)

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()
    
    // Add shutdown hook function
	boot.AddShutdownHookFunc("shutdown-hook", func() {
		fmt.Println("shutting down")
	})

	// Bootstrap
	boot.Bootstrap(context.Background())

	// Wait for shutdown sig
	boot.WaitForShutdownSig(context.Background())
}
...
shutting down
...

Cheers

Last modified November 2, 2021 : Add Echo framework documentation (80ec258)