parse config
This commit is contained in:
parent
c99bb81a88
commit
24a035a161
|
@ -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
|
|
@ -3,8 +3,8 @@ package config
|
|||
// Config is the main configuration type.
|
||||
type Config struct {
|
||||
Info Info // Basic information
|
||||
DefaultNetworks map[string]*Network // List of "default" networks to choose from
|
||||
Users map[string]*User // For now hardcoded list of users XXX fix this
|
||||
Network map[string]*Network // List of "default" networks to choose from
|
||||
User map[string]*User // For now hardcoded list of users XXX fix this
|
||||
Database Database // Database Config
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue