Config

How to read configs in local file system.

Overview

Bootstrapper will try to read config files described in [config] section in boot.yaml file and load the file content with viper.

As a result, bellow file type can be supported.

  • JSON
  • TOML
  • YAML
  • HCL
  • envfile
  • Java propertie

Architecture

Locale

ConfigEntry support concept of locale.

Quick start

1.Create config

Create config file and specify in boot.yaml file

config/default.yaml

region: default

boot.yaml

config:
  - name: my-config
    locale: "*::*::*::*"
    path: config/default.yaml
gin:
  - name: greeter
    port: 8080
    enabled: true

2.Refer config path

main.go

package main

import (
	"context"
	"fmt"
	"github.com/rookie-ninja/rk-boot"
	"github.com/rookie-ninja/rk-entry/entry"
	"github.com/rookie-ninja/rk-gin/interceptor/context"
)

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

	// Get ConfigEntry and get viper instance
	fmt.Println(rkentry.GlobalAppCtx.GetConfigEntry("my-config").GetViper().GetString("region"))

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

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

3.Access ConfigEntry

User can access ConfigEntry by calling rkentry.GlobalAppCtx.GetConfigEntry().

Last modified September 24, 2021 : Update based on rk-boot:v1.2.4 (357cf4c)