config

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 7 Imported by: 0

README

GIMBAP Config provider

This is a simple configuration provider to use with GIMBAP. It reads configurations from a file and provides them to GIMBAP.

This provider uses the famous Viper under the hood so any configurations that is compatitable with Viper can be used with this provider.

Installation

go get github.com/jhseong7/gimbap-config

Usage

import the ConfigModule provided with this package to the GIMBAP application you intend to use.

import (
  "github.com/jhseong7/gimbap"
  config "github.com/jhseong7/gimbap-config"
)

var AppModule = gimbap.DefineModule(gimbap.ModuleConfig{
  Name: "AppModule",
  SubModules: []*gimbap.Module{
    config.ConfigModule("config.yaml"),
  },
  // other configurations
})

Then you must inject the default options provider to the appmodule.

func main() {
	app := gimbap.CreateApp(gimbap.AppOption{
		AppModule: app.AppModule,
	})

	// Provider the root config for the config service
	app.Provide(config.ConfigOption{ConfigFilePathList: []string{"./.env"}})

  app.Run()
}

then inject the ConfigService to the module you want to use the configurations.

Third-party libraries

  • Library Name: spf13/viper
    • Purpose: Used for reading configurations
    • License: MIT License. Link

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigModule = gimbap.DefineModule(gimbap.ModuleOption{
	Name: "ConfigModule",
	Providers: []*gimbap.Provider{
		ConfigServiceProvider,
	},
})
View Source
var ConfigServiceProvider = gimbap.DefineProvider(gimbap.ProviderOption{
	Name:         "ConfigServiceProvider",
	Instantiator: NewConfigService,
})

Functions

This section is empty.

Types

type ConfigOption

type ConfigOption struct {
	// File path list of the configuration files to use
	ConfigFilePathList []string

	// Raw configuration data
	ConfigData map[string]interface{}

	// Toggle the automatic watching of the configuration file changes
	WatchConfigChange bool

	// Prevent the auto loading of the configuration file. Default is false
	PreventAutoLoad bool
}

type ConfigService

type ConfigService struct {
	// contains filtered or unexported fields
}

func NewConfigService

func NewConfigService(option ConfigOption) *ConfigService

func (*ConfigService) Get

func (c *ConfigService) Get(key string) interface{}

func (*ConfigService) GetBool

func (c *ConfigService) GetBool(key string) bool

func (*ConfigService) GetDuration

func (c *ConfigService) GetDuration(key string) time.Duration

func (*ConfigService) GetFloat64

func (c *ConfigService) GetFloat64(key string) float64

func (*ConfigService) GetInt

func (c *ConfigService) GetInt(key string) int

func (*ConfigService) GetInt32

func (c *ConfigService) GetInt32(key string) int32

func (*ConfigService) GetInt64

func (c *ConfigService) GetInt64(key string) int64

func (*ConfigService) GetString

func (c *ConfigService) GetString(key string) string

func (*ConfigService) GetStringMap

func (c *ConfigService) GetStringMap(key string) map[string]interface{}

func (*ConfigService) GetStringSlice

func (c *ConfigService) GetStringSlice(key string) []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL