Documentation ¶
Overview ¶
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Constants
- type ConfigModel
- func (c *ConfigModel) AllowSubdirs() *ConfigModel
- func (c *ConfigModel) AllowSubdirsByRegex(regex string) *ConfigModel
- func (c *ConfigModel) CreateYamc(reader yamc.DataReader) (*yamc.Yamc, error)
- func (c *ConfigModel) Empty() *ConfigModel
- func (c *ConfigModel) GetAllParsedFiles() []string
- func (c *ConfigModel) GetAsYmac() (*yamc.Yamc, error)
- func (c *ConfigModel) GetConfig(what int) interface{}
- func (c *ConfigModel) GetConfigPath() string
- func (c *ConfigModel) GetFileContent(path string) ([]byte, error)
- func (c *ConfigModel) GetLastUsedReader() yamc.DataReader
- func (c *ConfigModel) GetLoadedFile() string
- func (c *ConfigModel) GetValue(dotedPath string) (any, error)
- func (c *ConfigModel) Init(initFn func(strct *any), noConfigFn func(errCode int) error) *ConfigModel
- func (c *ConfigModel) Load() error
- func (c *ConfigModel) LoadFile(path string) error
- func (c *ConfigModel) NoSubdirs() *ConfigModel
- func (c *ConfigModel) Reset()
- func (c *ConfigModel) Save() error
- func (c *ConfigModel) SetCustomFileLoader(fn func(path string) ([]byte, error)) *ConfigModel
- func (c *ConfigModel) SetExpectNoConfigFiles() *ConfigModel
- func (c *ConfigModel) SetFileAndPathsByFullFilePath(fullPath string) *ConfigModel
- func (c *ConfigModel) SetFilePattern(regex string) *ConfigModel
- func (c *ConfigModel) SetFolderBlackList(blackListedDirs []string) *ConfigModel
- func (c *ConfigModel) SetSingleFile(filename string) *ConfigModel
- func (c *ConfigModel) SetSubDirs(dirs ...string) *ConfigModel
- func (c *ConfigModel) SetTrackFiles() *ConfigModel
- func (c *ConfigModel) SupportMigrate(fileHandelFn func(path string, cfg interface{})) *ConfigModel
- func (c *ConfigModel) ToString(reader yamc.DataReader) (string, error)
- func (c *ConfigModel) UseConfigDir() *ConfigModel
- func (c *ConfigModel) UseHomeDir() *ConfigModel
- func (c *ConfigModel) UseRelativeDir() *ConfigModel
Constants ¶
const ( PATH_UNSET = 0 PATH_HOME = 1 PATH_CONFIG = 2 PATH_ABSOLUTE = 3 ERROR_PATH_NOT_EXISTS = 101 NO_CONFIG_FILES_FOUND = 102 // Flags to get config entries ConfigUseSpecialDir = 1 ConfigAllowSubDirs = 2 ConfigExpectNoFiles = 4 ConfigAllowDirPattern = 8 ConfigFilesPattern = 16 ConfigTrackFiles = 32 ConfigDirBlackList = 64 ConfigSupportMigrate = 128 ConfigHaveCustomLoader = 256 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigModel ¶
type ConfigModel struct {
// contains filtered or unexported fields
}
func New ¶
func New(structure any, read ...yamc.DataReader) *ConfigModel
New creates a New yacl ConfigModel with default properties
func (*ConfigModel) AllowSubdirs ¶
func (c *ConfigModel) AllowSubdirs() *ConfigModel
AllowSubdirs enables scanning subdirectories to find configuration files
func (*ConfigModel) AllowSubdirsByRegex ¶
func (c *ConfigModel) AllowSubdirsByRegex(regex string) *ConfigModel
AllowSubdirsByRegex same as AllowSubDirs but set a regex pattern to Whitelist folder names
func (*ConfigModel) CreateYamc ¶
func (c *ConfigModel) CreateYamc(reader yamc.DataReader) (*yamc.Yamc, error)
CreateYamc creates a Yamc container. it has no caching because this is needed only for some content creation, like saving or parsing. so there is no need to keep them.
func (*ConfigModel) Empty ¶
func (c *ConfigModel) Empty() *ConfigModel
Empty initialize the configuration without any configuration files loading.
func (*ConfigModel) GetAllParsedFiles ¶
func (c *ConfigModel) GetAllParsedFiles() []string
GetAllParsedFiles returns all parsed configuration filenames
func (*ConfigModel) GetAsYmac ¶
func (c *ConfigModel) GetAsYmac() (*yamc.Yamc, error)
GetAsYmac creates a Yamc map from the configuration. we use Json here as Reader
func (*ConfigModel) GetConfig ¶
func (c *ConfigModel) GetConfig(what int) interface{}
GetConfig returns the value of the given config entry
func (*ConfigModel) GetConfigPath ¶
func (c *ConfigModel) GetConfigPath() string
GetConfigPath compose the current used Configuration folder and returns them. anything what can go wrong will end up in a panic
func (*ConfigModel) GetFileContent ¶
func (c *ConfigModel) GetFileContent(path string) ([]byte, error)
GetFileContent returns the file content of the given file path if trackFiles is not enabled, this will return an error
func (*ConfigModel) GetLastUsedReader ¶
func (c *ConfigModel) GetLastUsedReader() yamc.DataReader
return the last used reader for loading the configuration this is nil, if no configuration was loaded
func (*ConfigModel) GetLoadedFile ¶
func (c *ConfigModel) GetLoadedFile() string
GetLoadedFile returns the used configuration filename
func (*ConfigModel) GetValue ¶
func (c *ConfigModel) GetValue(dotedPath string) (any, error)
GetValue parsing a string with dots, to use any part of them to build a route to a specific entry. This is a very basic path building, without any magic. so even a key with dots will be an issue. so the use case depends on the actual structure. Also DO NOT USE THIS FOR READING CONFIG VALUES. use the structure itself. this method is a simple helper for verify data while testing (for example)
func (*ConfigModel) Init ¶
func (c *ConfigModel) Init(initFn func(strct *any), noConfigFn func(errCode int) error) *ConfigModel
Init sets the initialization Callbacks. initFn will be executed to initialize the configuration structure. can be nil noConfigFn is the callback for the cases, the configuration directory is not exists, there are no configurations files found
func (*ConfigModel) Load ¶
func (c *ConfigModel) Load() error
Load start loading all configuration files depends the configured behavior.
func (*ConfigModel) LoadFile ¶
func (c *ConfigModel) LoadFile(path string) error
LoadFile loads and parses a single configuration file. this can be called multiple times with different files. the content is merged (no deep copy, so no list merge for example)
func (*ConfigModel) NoSubdirs ¶
func (c *ConfigModel) NoSubdirs() *ConfigModel
NoSubdirs disables scanning sub folders while looking for configuration files
func (*ConfigModel) Reset ¶
func (c *ConfigModel) Reset()
Reset the configuration. this will clear the usedFile and loadedFiles. this is useful for testing
func (*ConfigModel) Save ¶
func (c *ConfigModel) Save() error
Save is try to write the current configuration on disk. IF we successfully loaded content at least from one configuration file, the last one is used IF we have setup a SingleFile and do not have a usage while loading, then this will be used instead. anything else will report an error
func (*ConfigModel) SetCustomFileLoader ¶
func (c *ConfigModel) SetCustomFileLoader(fn func(path string) ([]byte, error)) *ConfigModel
sets a custome file loader they will be used instead of the default file loader to load the configuration files and return the content as byte array. so some template engines can be used to load the configuration files
func (*ConfigModel) SetExpectNoConfigFiles ¶
func (c *ConfigModel) SetExpectNoConfigFiles() *ConfigModel
SetExpectNoConfigFiles disable the behavior, not existing config files will be handled as error. this also means, it should just ignore this issue. so if this is enabled, it will also not reported to the noConfigFn that might be setup in the Init handler
func (*ConfigModel) SetFileAndPathsByFullFilePath ¶
func (c *ConfigModel) SetFileAndPathsByFullFilePath(fullPath string) *ConfigModel
SetFileAndPathsByFullFilePath sets the file and the path to the file. so the file will be loaded and the path will be used to scan for sub directories. so this is the same as SetSingleFile and SetSubDirs but in one call.
func (*ConfigModel) SetFilePattern ¶
func (c *ConfigModel) SetFilePattern(regex string) *ConfigModel
SetFilePattern defines a regex-pattern for any configuration file any file that is not matching, will be ignored.
func (*ConfigModel) SetFolderBlackList ¶
func (c *ConfigModel) SetFolderBlackList(blackListedDirs []string) *ConfigModel
SetFolderBlackList defines a simple list of sub directories, they should being ignored, while looking for configuration files
func (*ConfigModel) SetSingleFile ¶
func (c *ConfigModel) SetSingleFile(filename string) *ConfigModel
Limits looking for the configurations to one file (base) name. so do not add any path to filename argument. this is not equal to the usage of LoadFile, because if this is combined with scanning sub dirs, any configuration with this file basename will be accepted. if you like to load one specific file so use LoadFile instead. if you like more flexible, depending what files should load, define a regex-pattern and use SetFilePattern
func (*ConfigModel) SetSubDirs ¶
func (c *ConfigModel) SetSubDirs(dirs ...string) *ConfigModel
add the names of the sub directories starting from the base directory. it will be set as string arguments. add any subdirectory separate as argument. do not add "this-dir/next-dir".
func (*ConfigModel) SetTrackFiles ¶
func (c *ConfigModel) SetTrackFiles() *ConfigModel
SetTrackFiles enables the tracking of loaded files. so the file content will be stored in the ConfigModel and can be accessed by GetFileContent
func (*ConfigModel) SupportMigrate ¶
func (c *ConfigModel) SupportMigrate(fileHandelFn func(path string, cfg interface{})) *ConfigModel
func (*ConfigModel) ToString ¶
func (c *ConfigModel) ToString(reader yamc.DataReader) (string, error)
ToString converts the current configuration into a string, depending the submitted reader.
func (*ConfigModel) UseConfigDir ¶
func (c *ConfigModel) UseConfigDir() *ConfigModel
UseConfigDir sets the default config dir as entrypoint (basedir)
func (*ConfigModel) UseHomeDir ¶
func (c *ConfigModel) UseHomeDir() *ConfigModel
UseHomeDir sets the User Home-dir as entrypoint (basedir)
func (*ConfigModel) UseRelativeDir ¶
func (c *ConfigModel) UseRelativeDir() *ConfigModel
UseRelativeDir is just defines no special path usage. mostly it means the current folder is used (relative) but depending on the usage of the lib, it can also still a absolute path.