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
38
39
40
41
42
43
44
45
46
47
|
/**
* CQL Minus - cqlminus
*
* 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 config
import (
"encoding/json"
"fmt"
"os"
)
type Config struct {
Endpoint string `json:"endpoint"`
Keyspace string `json:"keyspace"`
Username string `json:"username"`
Password string `json:"password"`
TlsKeyFile string `json:"tlsKeyFile"`
TlsCertificate string `json:"tlsCertificate"`
TlsVerifyServer string `json:"tlsVerifyServer"`
TlsCA string `json:"tlsCA"`
}
func LoadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("reading config file: %w", err)
}
var cfg Config
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parsing config file: %w", err)
}
if cfg.Endpoint == "" {
return nil, fmt.Errorf("please configure server:port as endpoint")
}
return &cfg, nil
}
|