config_file_manager

package
v0.0.0-...-bee8048 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventConfigChanged = "config file changed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

func (*Config) Group

func (c *Config) Group(s string) Object

func (*Config) GroupKeys

func (c *Config) GroupKeys() []string

func (*Config) Marshal

func (c *Config) Marshal() ([]byte, error)

func (*Config) Unmarshal

func (c *Config) Unmarshal(data []byte) error

type Dependency

type Dependency = Manager

type HasConfig

type HasConfig interface {
	ConfigFileName() string   // ConfigFilePath returns the path to the configuration file.
	Config() (*Config, error) // Config retrieves the configuration from the file.
}

HasConfig represents a something with a configuration file path and retrieval methods.

type HasDefaultConfig

type HasDefaultConfig interface {
	HasConfig
	DefaultConfig() Config // DefaultConfig returns the default configuration.
}

HasDefaultConfig represents something with a default configuration.

type Manager

type Manager interface {
	GetPath(path string) string
	ConfigDirectory() string                   // ConfigDirectory returns the directory path where configurations are stored.
	SetConfigDirectory(string) error           // SetConfigDirectory sets the directory path for configurations.
	Configs() map[string]*Config               // Configs returns all configurations stored in the service.
	GetConfig(string) (*Config, error)         // GetConfig retrieves a configuration by its path.
	CreateConfig(path string) (*Config, error) // CreateConfig creates a new configuration file at the specified path.
	LoadConfig(string) (*Config, error)        // LoadConfig loads a configuration from the specified path.
	SaveConfig(string) error                   // SaveConfig saves a configuration to the specified path.
}

Manager represents something that manages configurations.

type Object

type Object map[string]interface{}

func (Object) Get

func (n Object) Get(key string) interface{}

func (Object) GetBool

func (n Object) GetBool(key string) bool

func (Object) GetDuration

func (n Object) GetDuration(key string) time.Duration

func (Object) GetInt

func (n Object) GetInt(key string) int

func (Object) GetString

func (n Object) GetString(key string) string

func (Object) GetStrings

func (n Object) GetStrings(key string) []string

func (Object) IsSet

func (n Object) IsSet(key string) bool

func (Object) Keys

func (n Object) Keys() (keys []string)

func (Object) Marshal

func (n Object) Marshal() ([]byte, error)

func (Object) Set

func (n Object) Set(key string, value interface{})

func (Object) SetDefault

func (n Object) SetDefault(key string, defaultValue interface{})

func (Object) Unmarshal

func (n Object) Unmarshal(data []byte) error

type Service

type Service struct {
	RootDirectory string
	// contains filtered or unexported fields
}

Service is a config file manager that marshals to and from json files.

func (*Service) ConfigDirectory

func (s *Service) ConfigDirectory() string

ConfigDirectory returns the directory path where the service's configurations are stored. If the directory is not set, it returns a default.

func (*Service) Configs

func (s *Service) Configs() map[string]*Config

Configs returns a map of all configurations stored in the service.

func (*Service) CreateConfig

func (s *Service) CreateConfig(path string) (*Config, error)

CreateConfig creates a new configuration file at the specified path. It locks the service's mutex to ensure safe concurrent access.

func (*Service) GetConfig

func (s *Service) GetConfig(path string) (*Config, error)

GetConfig retrieves a configuration by its path from the service's internal map. It locks the service's mutex to ensure safe concurrent access.

func (*Service) GetPath

func (s *Service) GetPath(name string) string

GetPath returns the absolute path for a given incoming file

func (*Service) Init

func (s *Service) Init(mesh servicemesh.Mesh)

Init satisfies the servicemesh.Service interface

func (*Service) LoadConfig

func (s *Service) LoadConfig(path string) (*Config, error)

LoadConfig loads a configuration from the specified path. It locks the service's mutex to ensure safe concurrent access.

func (*Service) Logger

func (s *Service) Logger() *slog.Logger

Logger satisfies the servicemesh.HasLogger interface

func (*Service) Name

func (s *Service) Name() string

Name satisfies the servicemesh.Service interface

func (*Service) Ready

func (s *Service) Ready() bool

func (*Service) SaveConfig

func (s *Service) SaveConfig(path string) error

SaveConfig saves a configuration to the specified path. It locks the service's mutex to ensure safe concurrent access.

func (*Service) SetConfigDirectory

func (s *Service) SetConfigDirectory(dir string) error

SetConfigDirectory sets the directory path where the service's configurations should be stored. It locks the service's mutex to ensure safe concurrent access.

func (*Service) SetLogger

func (s *Service) SetLogger(l *slog.Logger)

SetLogger satisfies the servicemesh.HasLogger interface

Jump to

Keyboard shortcuts

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