config-service.git

ref: 5c759caf216bf016d9bc3ed716c99e31e3047b4d

./config.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * ConfigService - configservice
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2026
 */

package main

import (
    "encoding/json"
    "errors"
    "os"
)

type ConfigServiceConfig struct {
    Endpoint             string `json:"endpoint"`
    KeepassKeyStoreFile  string `json:"keystore"`
    KeepassSecretKeyFile string `json:"secretkey"`

    //
    ServerTLSCertificate string `json:"server-tls-certificate"`
    ServerTLSKey         string `json:"server-tls-key"`
}

func LoadConfig(filename string) (ConfigServiceConfig, error) {
    var conf ConfigServiceConfig
    raw, err := os.ReadFile(filename)
    if err != nil {
        return conf, errors.New("Error occured while reading config file : " + filename)
    }
    json.Unmarshal(raw, &conf)
    return conf, nil
}