index.tmpl: Update
[fbfp.git] / config.go
blob15d195a02d5677d3c4be97b8aff24b401cc66d88
1 /*
2 * Handle fbfp's configuration.
4 * Copyright (C) 2024 Runxi Yu <https://runxiyu.org>
5 * SPDX-License-Identifier: AGPL-3.0-or-later
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 package main
23 import (
24 "bufio"
25 "os"
27 "git.sr.ht/~emersion/go-scfg"
31 * config.Openid.Authorize doesn't have to be specified. But if it is
32 * specified, it replaces the once obtained from the
33 * .well-known/openid-configuration endpoint. Because Microsoft doesn't seem to
34 * want to put their v2.0 authorization endpoint anywhere in their
35 * configuration.
38 var config_with_pointers struct {
39 Url *string `scfg:"url"`
40 Prod *bool `scfg:"prod"`
41 Tmpl *string `scfg:"tmpl"`
42 Static *bool `scfg:"static"`
43 Listen struct {
44 Addr *string `scfg:"addr"`
45 Net *string `scfg:"net"`
46 Proto *string `scfg:"proto"`
47 } `scfg:"listen"`
48 Db struct {
49 Type *string `scfg:"type"`
50 Conn *string `scfg:"conn"`
51 } `scfg:"db"`
52 Openid struct {
53 Client *string `scfg:"client"`
54 Endpoint *string `scfg:"endpoint"`
55 Authorize *string `scfg:"authorize"`
56 } `scfg:"openid"`
59 var config struct {
60 Url string
61 Prod bool
62 Tmpl string
63 Static bool
64 Listen struct {
65 Addr string
66 Net string
67 Proto string
69 Db struct {
70 Type string
71 Conn string
73 Openid struct {
74 Client string
75 Endpoint string
76 Authorize string
80 func fbfp_get_config(path string) error {
81 f := er(os.Open(path))
83 err := scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers)
84 if err != nil {
85 return err
89 * TODO: We segfault when there are missing configuration options.
90 * There should be better ways to handle this.
92 config.Url = *(config_with_pointers.Url)
93 config.Prod = *(config_with_pointers.Prod)
94 config.Tmpl = *(config_with_pointers.Tmpl)
95 config.Static = *(config_with_pointers.Static)
96 config.Listen.Addr = *(config_with_pointers.Listen.Addr)
97 config.Listen.Net = *(config_with_pointers.Listen.Net)
98 config.Listen.Proto = *(config_with_pointers.Listen.Proto)
99 config.Db.Type = *(config_with_pointers.Db.Type)
100 config.Db.Conn = *(config_with_pointers.Db.Conn)
101 config.Openid.Client = *(config_with_pointers.Openid.Client)
102 config.Openid.Endpoint = *(config_with_pointers.Openid.Endpoint)
104 if config_with_pointers.Openid.Authorize != nil {
105 config.Openid.Authorize =
106 *(config_with_pointers.Openid.Authorize)
109 return nil