config

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config contains convenience functions for reading and managing viper configs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read() (*viper.Viper, error)

Read sets default to a viper instance and read user config to override these defaults.

Types

type Cacher added in v0.8.0

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

Cacher is used to cache the construction of an object, such as a connection. It will detect which config values are read when constructing the object. Then, when further requests are made, it will return the same object as long as the config values which were used haven't changed.

func NewCacher added in v0.8.0

func NewCacher(cfg View, newInstance NewInstanceFunc) *Cacher

NewCacher returns a cacher which uses cfg to detect relevant changes, and newInstance to construct the object when nessisary. newInstance MUST use the provided View when constructing the object.

func (*Cacher) ForceReset added in v0.8.0

func (c *Cacher) ForceReset()

ForceReset causes Cacher to forget the cached object. The next call to Get will again use newInstance to create a new object.

func (*Cacher) Get added in v0.8.0

func (c *Cacher) Get() (interface{}, error)

Get returns the cached object if possible, otherwise it calls newInstance to construct the new cached object. When Get is next called, it will detect if any of the configuration values which were used to construct the object have changed. If they have, the cache is invalidated, and a new object is constructed. If newInstance returns an error, Get returns that error and the object will not be cached or returned.

type Mutable

type Mutable interface {
	Set(string, interface{})
	View
}

Mutable is a read-write view of the Open Match configuration.

type NewInstanceFunc added in v0.9.0

type NewInstanceFunc func(cfg View) (interface{}, func(), error)

NewInstanceFunc is used by the cacher to create a new value given the config. It may return an additional function to close or otherwise cleanup if ForceReset is called.

type View

type View interface {
	IsSet(string) bool
	GetString(string) string
	GetInt(string) int
	GetInt64(string) int64
	GetFloat64(string) float64
	GetStringSlice(string) []string
	GetBool(string) bool
	GetDuration(string) time.Duration
}

View is a read-only view of the Open Match configuration. New accessors from Viper should be added here.

func Sub

func Sub(v View, key string) View

Sub returns a subset of configuration filtered by the key.

Jump to

Keyboard shortcuts

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