aboutsummaryrefslogtreecommitdiff
path: root/config.go
blob: 255b44e5baff63ebf04b802c30d423d9cf72df0d (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main

import (
	"bufio"
	"os"

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

/*
 * config.Openid.Authorize doesn't have to be specified. But if it is
 * specified, it replaces the once obtained from the
 * .well-known/openid-configuration endpoint. Because Microsoft doesn't seem to
 * want to put their v2.0 authorization endpoint anywhere in their
 * configuration.
 */

var config_with_pointers struct {
	Url    *string `scfg:"url"`
	Static *bool   `scfg:"static"`
	Listen struct {
		Addr  *string `scfg:"addr"`
		Net   *string `scfg:"net"`
		Proto *string `scfg:"proto"`
	} `scfg:"listen"`
	Db struct {
		Type *string `scfg:"type"`
		Conn *string `scfg:"conn"`
	} `scfg:"db"`
	Openid struct {
		Client    *string `scfg:"client"`
		Endpoint  *string `scfg:"endpoint"`
		Authorize *string `scfg:"authorize"`
	} `scfg:"openid"`
}

var config struct {
	Url    string
	Static bool
	Listen struct {
		Addr  string
		Net   string
		Proto string
	}
	Db struct {
		Type string
		Conn string
	}
	Openid struct {
		Client    string
		Endpoint  string
		Authorize string
	}
}

func fbfp_get_config(path string) {
	f, err := os.Open(path)
	e(err)

	err = scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers)
	e(err)

	/*
	 * TODO: We segfault when there are missing configuration options.
	 * There should be better ways to handle this.
	 */
	config.Url = *(config_with_pointers.Url)
	config.Static = *(config_with_pointers.Static)
	config.Listen.Addr = *(config_with_pointers.Listen.Addr)
	config.Listen.Net = *(config_with_pointers.Listen.Net)
	config.Listen.Proto = *(config_with_pointers.Listen.Proto)
	config.Db.Type = *(config_with_pointers.Db.Type)
	config.Db.Conn = *(config_with_pointers.Db.Conn)
	config.Openid.Client = *(config_with_pointers.Openid.Client)
	config.Openid.Endpoint = *(config_with_pointers.Openid.Endpoint)

	if config_with_pointers.Openid.Authorize != nil {
		config.Openid.Authorize =
			*(config_with_pointers.Openid.Authorize)
	}
}