~xenrox/10man-api

ref: 709ed844a7b00723a882b61fed6a401b5ce6cd74 10man-api/config/config.go -rw-r--r-- 1.1 KiB
709ed844Thorben Günther Update dependencies 10 months ago
                                                                                
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
48
49
50
51
52
53
54
55
56
57
package config

import (
	"log"
	"strings"

	"git.sr.ht/~emersion/go-scfg"
)

var configPath string = "/etc/10man-api/config"

// ConnectionString is used to connect to the database
var ConnectionString string

// Admins array of steamID64 of users that should become admins
var Admins []string

var Maps []string

func init() {
	cfg, err := scfg.Load(configPath)
	if err != nil {
		log.Fatalf("could not read config file %q", configPath)
	}

	for _, d := range cfg {
		switch d.Name {
		case "connection-string":
			if err := d.ParseParams(&ConnectionString); err != nil {
				log.Fatalf("could not parse connection-string: %v", err)
			}

		case "admins":
			var admins string
			if err := d.ParseParams(&admins); err != nil {
				log.Fatalf("could not parse admins: %v", err)
			}

			Admins = strings.Split(admins, ",")

		case "maps":
			var maps string
			if err := d.ParseParams(&maps); err != nil {
				log.Fatalf("could not parse maps: %v", err)
			}

			Maps = strings.Split(maps, ",")

		default:
			log.Fatalf("illegal config value %q", d.Name)
		}
	}

	if ConnectionString == "" {
		log.Fatalf("could not parse connection-string")
	}
}