summaryrefslogtreecommitdiff
path: root/config.go
blob: eabc8b036e57d08b426a50b0f9a70c2ee7fe6dde (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
package main

import (
	_ "embed"
	"encoding/json"
	"log"
	"os"
)

//go:embed default_config.json
var defaultConfig string

type CeresConfig struct {
	HttpAddress     string `json:"http_address"`
	StorageFilePath string `json:"storage_file_path"`
}

var config CeresConfig

func init() {
	err := json.Unmarshal([]byte(defaultConfig), &config)
	if err != nil {
		log.Fatal(err)
	}
}

func (c *CeresConfig) Read(path string) {
	data, err := os.ReadFile(path)
	if err != nil {
		log.Fatal(err)
	}

	err = json.Unmarshal(data, &c)
	if err != nil {
		log.Fatal(err)
	}
}