Ejemplo n.º 1
0
// Reads the config file.
func ReadConfig(name string) (*Config, error) {
	file, err := os.Open(name)

	if err != nil {
		return nil, err
	}
	defer file.Close()

	c := &Config{conf.NewConfigFile()}

	for sec, opt := range defaults {
		for k, v := range opt {
			c.AddOption(sec, k, v)
		}
	}

	if err = c.Read(file); err != nil {
		return nil, err
	}
	return c, nil
}
Ejemplo n.º 2
0
// Load config from global and user-specific .ini file(s)
func loadConfig() *conf.ConfigFile {
	c := conf.NewConfigFile()
	global, err := os.Open(GlobalConfig)
	if err == nil {
		defer global.Close()
		if err = c.Read(global); err != nil {
			log.Fatalln("ERROR: reading global config: ", err)
			return c
		}
	}

	home := os.Getenv("HOME")
	user, err := os.Open(filepath.Join(home, UserConfig))
	if err == nil {
		defer user.Close()
		if err = c.Read(user); err != nil {
			log.Fatalln("ERROR: reading per user config: ", err)
			return c
		}
	}

	return c
}
Ejemplo n.º 3
0
	"flag"
	"fmt"
	"github.com/snarlysodboxer/sshPortForward"
	"html/template"
	"log"
	"net/http"
	"os"
)

const configHeader = "Configuration file for BTSyncInator:"

var (
	configFilePath = flag.String("config", ".btsyncinator.conf", "path to config file.")
	debug          = flag.Bool("debug", false, "enable debug mode.")
	apiDebug       = flag.Bool("apiDebug", false, "enable debug mode on btsync-api library.")
	config         = conf.NewConfigFile()
	settings       = Settings{}
)

type Settings struct {
	PrivateKeyPath string
	ServeAddress   string
	DigestPath     string
	UseTLS         bool
	TLSKeyPath     string
	TLSCertPath    string
}

func readSlashCreateConfig() {
	if _, err := os.Stat(*configFilePath); os.IsNotExist(err) {
		config.WriteConfigFile(*configFilePath, 0600, configHeader)