parse config

This commit is contained in:
Christine Dodrill 2015-10-09 21:44:48 -07:00
parent c99bb81a88
commit 24a035a161
6 changed files with 74 additions and 4 deletions

1
env.sh Normal file
View File

@ -0,0 +1 @@
export GOPATH=$(pwd):$(pwd)/vendor

21
scream.ini Normal file
View File

@ -0,0 +1,21 @@
[info]
port = 5000
locked = true
ircv3 = false
[network "LocalHost"]
host = "127.0.0.1"
ssl = false
port = 6667
[user "Xena"]
authmethod = password # hard-coded as "memes"
id = amusement
numeric = 69
gecos = Xena Xena Xena
autojoin = "#foo,#bar"
[database]
driver = sqlite3
connection = "./var/scream.db"
# Ignore for now

View File

@ -2,10 +2,10 @@ package config
// Config is the main configuration type. // Config is the main configuration type.
type Config struct { type Config struct {
Info Info // Basic information Info Info // Basic information
DefaultNetworks map[string]*Network // List of "default" networks to choose from Network map[string]*Network // List of "default" networks to choose from
Users map[string]*User // For now hardcoded list of users XXX fix this User map[string]*User // For now hardcoded list of users XXX fix this
Database Database // Database Config Database Database // Database Config
} }
// Info is basic information. // Info is basic information.

View File

@ -0,0 +1,31 @@
package config
import (
"os"
"github.com/scalingdata/gcfg"
)
// Load loads the configuration by the given filename, throwing an error if it fails.
func Load(fname string) (c *Config, err error) {
fin, err := os.Open(fname)
if err != nil {
return nil, err
}
defer fin.Close()
c = new(Config)
c.Network = make(map[string]*Network)
c.User = make(map[string]*User)
err = gcfg.ReadInto(c, fin)
if err != nil {
return nil, err
}
for k, user := range c.User {
user.Username = k
}
return c, nil
}

View File

@ -0,0 +1,12 @@
package config
import "testing"
func TestLoadConfig(t *testing.T) {
c, err := Load("../../../scream.ini")
if err != nil {
t.Fatal(err)
}
t.Log(c)
}

5
test.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
source ./env.sh
gt ./...