aboutsummaryrefslogblamecommitdiff
path: root/config.go
blob: 1ec7207a0ee71f8a699c03fc372962e68f2eb152 (plain) (tree)
1
2
3
4
5
6
7
8
9

            

               

              
 
                                                      
                                                      

 

                                               
                                              
 
                             
 


















                                                                















                                                                                
package main

import (
	"bufio"
	"os"
	"sync"

	"go.lindenii.runxiyu.org/lindenii-common/misc"
	"go.lindenii.runxiyu.org/lindenii-common/scfg"
)

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
}

var directories struct {
	inbox misc.Dir_t
}
var directories_mutex sync.RWMutex

func prepare_dirs() error {
	directories_mutex.Lock()
	defer directories_mutex.Unlock()
	var err error
	directories.inbox, err = misc.Open_directory_readonly(config.Inbox_path)
	if err != nil {
		return err
	}
	return nil
}