kunt

golang IRC bot
git clone git://git.2f30.org/kunt.git
Log | Files | Refs | LICENSE

commit 2366a5f3147478da15c5532c47e164463b18e0f2
parent 429af281e98b3d9aa856bfec8fa56b4a07b4eb7a
Author: dsp <dsp@2f30.org>
Date:   Wed Apr 30 15:22:42 +0100

initial implementation of json LoadConfig

Diffstat:
src/irc/irc.go | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -11,6 +11,8 @@ import ( "net" "strings" "sync" + "io/ioutil" + "encoding/json" ) type Context struct { @@ -55,6 +57,21 @@ type network struct { channels []Channel // slice of channels } +func LoadConfig(fname string) (con *Config, err error) { + bytes,err := ioutil.ReadFile(fname) + if err != nil { + log.Printf(" [LoadConfig] error reading file %s\n",fname) + return nil,err + } + con = new(Config) + err = json.Unmarshal(bytes,&con) + if err != nil { + log.Printf(" [LoadConfig] error reading file %s\n",fname) + return nil,err + } + return con, nil +} + // Create a new IrcContext func NewIrcContext(ircConfig Config) *Context { network := network{