2
* ALR - Any Linux Repository
3
* Copyright (C) 2024 Евгений Храмов
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
"github.com/pelletier/go-toml/v2"
27
"plemya-x.ru/alr/internal/types"
28
"plemya-x.ru/alr/pkg/loggerctx"
31
var defaultConfig = &types.Config{
34
IgnorePkgUpdates: []string{},
38
URL: "https://gitea.plemya-x.ru/xpamych/xpamych-alr-repo.git",
48
// Config returns a ALR configuration struct.
49
// The first time it's called, it'll load the config from a file.
50
// Subsequent calls will just return the same value.
51
func Config(ctx context.Context) *types.Config {
53
defer configMtx.Unlock()
54
log := loggerctx.From(ctx)
57
cfgFl, err := os.Open(GetPaths(ctx).ConfigPath)
59
log.Warn("Error opening config file, using defaults").Err(err).Send()
64
// Copy the default configuration into config
65
defCopy := *defaultConfig
69
err = toml.NewDecoder(cfgFl).Decode(config)
71
log.Warn("Error decoding config file, using defaults").Err(err).Send()
72
// Set config back to nil so that we try again next time