Override bootstrapper

Is there any way to override boot.yaml or values in boot.yaml at start time?

Overview

Bootstrapper support two kinds of ways to override bootstrapper configs.

  • Override config file (by --rkboot)
  • Override values in config file (by --rkset)

Quick start

1.Override bootstrapper config file

In order to override bootstrapper file path, --rkboot needs to be passed.

boot.yaml

---
echo:
  - name: greeter
    port: 8080
    enabled: true
    commonService:
      enabled: true

boot-override.yaml

---
echo:
  - name: greeter
    port: 8081
    enabled: true
    commonService:
      enabled: true

main.go

package main

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

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

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

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

Start server with --rkboot args

$ go build main.go
$ ./main --rkboot boot-override.yaml

Send request to 8080

$ curl localhost:8080/rk/v1/healthy
curl: (7) Failed to connect to localhost port 8080: Connection refused

Send request to 8081

$ curl localhost:8081/rk/v1/healthy
{"healthy":true}

Cheers

2.Override values in boot.yaml

In order to override bootstrapper file path, --rkset needs to be passed.

Use comma to separate multiple overrides.

Type Example
Map app.description=“This is description”
List echo[0].name=“alice”,echo[0].port=8081

boot.yaml

---
echo:
  - name: greeter
    port: 8080
    enabled: true
    commonService:
      enabled: true

main.go

package main

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

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

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

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

Start server with --rkset args

$ go build main.go
$ ./main --rkset "echo[0].port=8081"

Send request to 8080

$ curl localhost:8080/rk/v1/healthy
curl: (7) Failed to connect to localhost port 8080: Connection refused

Send request to 8081

$ curl localhost:8081/rk/v1/healthy
{"healthy":true}

Cheers

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