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

  • Install
go get github.com/rookie-ninja/rk-boot
go get github.com/rookie-ninja/rk-gf
package main

import (
	"context"
	"github.com/rookie-ninja/rk-boot"
	"github.com/rookie-ninja/rk-gf/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 December 12, 2021 : Update based on rk-boot@v1.4.0 (233e143)