Documentation
¶
Overview ¶
Copyright (c) 2023 Chakib Ben Ziane <[email protected]> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors). All rights reserved.
SPDX-License-Identifier: AGPL-3.0-or-later
This file is part of GoSuki.
GoSuki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with gosuki. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2024-2025-2025-2025-2025 Chakib Ben Ziane <[email protected]> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors). All rights reserved.
SPDX-License-Identifier: AGPL-3.0-or-later
This file is part of GoSuki.
GoSuki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with gosuki. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2025 Chakib Ben Ziane <[email protected]> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors). All rights reserved.
SPDX-License-Identifier: AGPL-3.0-or-later
This file is part of GoSuki.
GoSuki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with gosuki. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- Variables
- func ConfigExists(path string) (bool, error)
- func DefaultConfPath() string
- func GetGlobalOption(key string) (any, error)
- func GetModuleOption(module string, opt string) (any, error)
- func Init(path string)
- func LoadFromTomlFile(path string) error
- func RegisterConfReadyHooks(hooks ...Hook)
- func RegisterConfigurator(name string, c Configurator)
- func RegisterGlobalOption(key string, val any)
- func RegisterModuleOpt(module string, opt string, val any) error
- func RunConfHooks(ctx context.Context, cmd *cli.Command)
- func StringToDurationFunc() mapstructure.DecodeHookFunc
- type AutoConfigurator
- type Config
- type Configurator
- type Hook
Constants ¶
const ( ConfigFileName = "config.toml" ConfigDirName = "gosuki" )
const (
GlobalConfigName = "global"
)
Variables ¶
var ( ConfigFileFlag string DBPath string )
some useful global flags
var (
ConfReadyHooks []Hook
)
var GlobalConfig = struct { WatchAll bool `toml:"watch-all" mapstructure:"watch-all"` DisabledModules []string `toml:"disabled-modules" mapstructure:"disabled-modules"` }{ true, []string{}, }
Functions ¶
func ConfigExists ¶
func DefaultConfPath ¶
func DefaultConfPath() string
func GetModuleOption ¶
GetModuleOption returns a module option value given a module name and option name
func LoadFromTomlFile ¶
func RegisterConfReadyHooks ¶
func RegisterConfReadyHooks(hooks ...Hook)
Hooks registered here will be executed after the config package has finished loading the conf
func RegisterConfigurator ¶
func RegisterConfigurator(name string, c Configurator)
A configurator can set options available under it's own module scope or under the global scope. A configurator implements the Configurator interface
func RegisterGlobalOption ¶
Register a global option ie. under [global] in toml file
func RegisterModuleOpt ¶
Register a module option ie. under [module] in toml file If the module is not a configurator, a simple map[string]any will be created for it. use GetModuleOption
func RunConfHooks ¶
A call to this func will run all registered config hooks
func StringToDurationFunc ¶
func StringToDurationFunc() mapstructure.DecodeHookFunc
StringToDurationHookFunc returns a mapstructure.DecodeHookFunc that converts strings to time.Duration using https://github.com/hako/durafmt
Types ¶
type AutoConfigurator ¶
type AutoConfigurator struct {
// contains filtered or unexported fields
}
func (AutoConfigurator) Dump ¶
func (ac AutoConfigurator) Dump() map[string]any
func (AutoConfigurator) MapFrom ¶
func (ac AutoConfigurator) MapFrom(src any) error
type Configurator ¶
type Configurator interface {
Set(string, any) error
Get(string) (any, error)
Dump() map[string]any
MapFrom(any) error
}
A Configurator allows multiple packages and modules to set and access configs which can be mapped to any output format (toml, cli flags, env variables ...)
func AsConfigurator ¶
func AsConfigurator(c any) Configurator
AsConfigurator generates implements a default Configurator for a given struct or custom type. Use this to handle module options.