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

import (
	"bufio"
	"go.lindenii.runxiyu.org/lindenii-common/scfg"
	"os"
	"sync"
)

var config struct {
	Server_name string `scfg:"server_name"`
	Inbox_path string `scfg:"inbox_path"`
}
var config_mutex sync.RWMutex

func load_config(path string) error {
	config_file, err := os.Open(path)
	if err != nil {
		return err
	}
	decoder := scfg.NewDecoder(bufio.NewReader(config_file))
	if func() error {
		config_mutex.Lock()
		defer config_mutex.Unlock()
		err = decoder.Decode(&config)
		if err != nil {
			return err
		}
		return nil
	}() != nil {
		return err
	}
	return nil
}