config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

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

View Source
const (
	ConfigFileName = "config.toml"
	ConfigDirName  = "gosuki"
)
View Source
const (
	GlobalConfigName = "global"
)

Variables

View Source
var (
	ConfigFileFlag string
	DBPath         string
)

some useful global flags

View Source
var (
	ConfReadyHooks []Hook
)
View Source
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 ConfigExists(path string) (bool, error)

func DefaultConfPath

func DefaultConfPath() string

func GetGlobalOption

func GetGlobalOption(key string) (any, error)

Get global option

func GetModuleOption

func GetModuleOption(module string, opt string) (any, error)

GetModuleOption returns a module option value given a module name and option name

func Init

func Init(path string)

func LoadFromTomlFile

func LoadFromTomlFile(path string) error

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

func RegisterGlobalOption(key string, val any)

Register a global option ie. under [global] in toml file

func RegisterModuleOpt

func RegisterModuleOpt(module string, opt string, val any) error

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

func RunConfHooks(ctx context.Context, cmd *cli.Command)

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) Get

func (ac AutoConfigurator) Get(opt string) (any, error)

func (AutoConfigurator) MapFrom

func (ac AutoConfigurator) MapFrom(src any) error

func (AutoConfigurator) Set

func (ac AutoConfigurator) Set(opt string, v any) error

type Config

type Config map[string]any

Global config holder

func GetAll

func GetAll() Config

Get all configs as a map[string]any

func MapToOutputConfig added in v1.2.0

func MapToOutputConfig(in Config) (Config, error)

func (Config) Dump

func (c Config) Dump() map[string]any

func (Config) Get

func (c Config) Get(opt string) (any, error)

func (Config) MapFrom

func (c Config) MapFrom(src any) error

func (Config) Set

func (c Config) Set(opt string, v 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.

func GetModule

func GetModule(module string) Configurator

Get the config of a module.

type Hook

type Hook func(context.Context, *cli.Command) error

Jump to

Keyboard shortcuts

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