implementing get cost

This commit is contained in:
Radu Ioan Fericean
2012-05-03 14:33:17 +03:00
parent 43c73bf85e
commit 9b00d43f93
3 changed files with 31 additions and 3 deletions

View File

@@ -143,7 +143,7 @@ func main() {
getter, err := timespans.NewRedisStorage("tcp:127.0.0.1:6379", 10)
defer getter.Close()
if err != nil {
log.Printf("Cannot open storage file: %v", err)
log.Printf("Cannot open storage: %v", err)
os.Exit(1)
}
if !*json {

View File

@@ -1,8 +1,27 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012 Radu Ioan Fericean
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package sessionmanager
import (
"bufio"
"fmt"
"github.com/rif/cgrates/timespans"
"log"
"net"
"regexp"
@@ -16,6 +35,10 @@ func NewEvent() (ev *Event) {
return &Event{Fields: make(map[string]string)}
}
var (
storageGetter, _ = timespans.NewRedisStorage("tcp:127.0.0.1:6379", 10)
)
func (ev *Event) String() (result string) {
for k, v := range ev.Fields {
result += fmt.Sprintf("%s = %s\n", k, v)
@@ -27,6 +50,7 @@ func (ev *Event) String() (result string) {
type SessionManager struct {
conn net.Conn
eventBodyRE *regexp.Regexp
sessions []*Session
}
func (sm *SessionManager) Connect(address, pass string) {
@@ -51,7 +75,11 @@ func (sm *SessionManager) ReadNextEvent() (ev *Event) {
}
ev = NewEvent()
for _, fields := range sm.eventBodyRE.FindAllStringSubmatch(body, -1) {
ev.Fields[fields[1]] = fields[2]
if len(fields) == 3 {
ev.Fields[fields[1]] = fields[2]
} else {
log.Printf("malformed event field: %v", fields)
}
}
return
}

View File

@@ -28,7 +28,7 @@ func TestConnect(t *testing.T) {
sm.Connect("localhost:8021", "ClueCon")
for {
ev := sm.ReadNextEvent()
log.Print(ev.Fields["Event-Name"])
log.Printf("%s : %s", ev.Fields["Event-Name"], ev.Fields["Event-Subclass"])
log.Print(ev)
}
}