about summary refs log tree commit diff
path: root/config.go
blob: b64b574e580b31daa0cb659524aa9c7666f54edf (plain)
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
// Copyright 2022 Terin Stock.
// SPDX-License-Identifier: MPL-2.0

package main

import (
	"os"

	"olympos.io/encoding/edn"
)

type Config struct {
	HTTP      HTTPConfig `edn:"http"`
	CGit      CGitConfig `edn:"cgit"`
	Git       GitConfig  `edn:"git"`
	ReposRoot string     `edn:"repos-root"`
}

type HTTPConfig struct {
	Host string `end:"host"`
	Port int    `end:"port"`
}

type CGitConfig struct {
	CGI        string `edn:"cgi"`
	ConfigFile string `edn:"config-file"`
	AssetsDir  string `edn:"assets-dir"`
}

type GitConfig struct {
	CGI       string `edn:"cgi"`
	ExportAll bool   `edn:"export-all"`
}

func readConfig(path string) (Config, error) {
	cfg := Config{}
	content, err := os.ReadFile(path)
	if err != nil {
		return cfg, err
	}

	err = edn.Unmarshal(content, &cfg)
	return cfg, err
}