config

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context, cfg Config) context.Context

Context sets the config in the context

Types

type Config

type Config interface {
	Save(context.Context) error
	Values() map[string]map[string]string
	GetValue(string, string) (string, bool)
	SetValue(string, string, string)
	UnsetValue(string, string)
	ExportEnv(context.Context) error
}

Config contains methods to operate on CLI config

func Get

func Get(ctx context.Context) Config

Get gets the config from the context

type IniConfig

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

IniConfig represents a config stored in ini file

func NewIni

func NewIni() (*IniConfig, error)

NewIni finds an existing ini file with config or creates new one and returns IniConfig

func (*IniConfig) ExportEnv

func (c *IniConfig) ExportEnv(ctx context.Context) error

ExportEnv exports values from config file as environmental variables, prefixing each with AKAMAI_<SECTION_NAME> It also attempts migration from previous config versions

func (*IniConfig) GetValue

func (c *IniConfig) GetValue(section, key string) (string, bool)

GetValue fetches a value from provided section under provided key

func (*IniConfig) Save

func (c *IniConfig) Save(ctx context.Context) error

Save stores the ini file in filesystem

func (*IniConfig) SetValue

func (c *IniConfig) SetValue(section, key, value string)

SetValue sets a key in provided section

func (*IniConfig) UnsetValue

func (c *IniConfig) UnsetValue(section, key string)

UnsetValue unsets a key in provided section

func (*IniConfig) Values

func (c *IniConfig) Values() map[string]map[string]string

Values returns a map containing sections from the config. Each section contans a key-value map of its contents

type Mock

type Mock struct {
	mock.Mock
}

Mock impl of Config interface

func (*Mock) ExportEnv

func (m *Mock) ExportEnv(_ context.Context) error

ExportEnv mock

func (*Mock) GetValue

func (m *Mock) GetValue(section string, key string) (string, bool)

GetValue mock

func (*Mock) Save

func (m *Mock) Save(_ context.Context) error

Save mock

func (*Mock) SetValue

func (m *Mock) SetValue(section string, key string, value string)

SetValue mock

func (*Mock) UnsetValue

func (m *Mock) UnsetValue(section string, key string)

UnsetValue mock

func (*Mock) Values

func (m *Mock) Values() map[string]map[string]string

Values mock

Jump to

Keyboard shortcuts

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