tested Msgpack, updated radix path, compilation for go tip

This commit is contained in:
Radu Ioan Fericean
2013-02-03 13:17:39 +02:00
parent 470bd0d030
commit a03a2220b7
5 changed files with 40 additions and 17 deletions

View File

@@ -40,21 +40,33 @@ type Action struct {
type actionTypeFunc func(*UserBalance, *Action) error
var (
actionTypeFuncMap = map[string]actionTypeFunc{
"LOG": logAction,
"RESET_TRIGGERS": resetTriggersAction,
"SET_POSTPAID": setPostpaidAction,
"RESET_POSTPAID": resetPostpaidAction,
"SET_PREPAID": setPrepaidAction,
"RESET_PREPAID": resetPrepaidAction,
"TOPUP_RESET": topupResetAction,
"TOPUP": topupAction,
"DEBIT": debitAction,
"RESET_COUNTER": resetCounterAction,
"RESET_COUNTERS": resetCountersAction,
func getActionFunc(typ string)(actionTypeFunc, bool) {
switch typ {
case "LOG":
return logAction, true
case "RESET_TRIGGERS":
return resetTriggersAction, true
case "SET_POSTPAID":
return setPostpaidAction, true
case "RESET_POSTPAID":
return resetPostpaidAction, true
case "SET_PREPAID":
return setPrepaidAction, true
case "RESET_PREPAID":
return resetPrepaidAction, true
case "TOPUP_RESET":
return topupResetAction, true
case "TOPUP":
return topupAction, true
case "DEBIT":
return debitAction, true
case "RESET_COUNTER":
return resetCounterAction, true
case "RESET_COUNTERS":
return resetCountersAction, true
}
)
return nil, false
}
func logAction(ub *UserBalance, a *Action) (err error) {
Logger.Info(fmt.Sprintf("%v %v %v", a.BalanceId, a.Units, a.MinuteBucket))

View File

@@ -212,7 +212,7 @@ func (at *ActionTiming) Execute() (err error) {
return
}
for _, a := range aac {
actionFunction, exists := actionTypeFuncMap[a.ActionType]
actionFunction, exists := getActionFunc(a.ActionType)
if !exists {
Logger.Crit(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType))
return

View File

@@ -46,7 +46,7 @@ func (at *ActionTrigger) Execute(ub *UserBalance) (err error) {
return
}
for _, a := range aac {
actionFunction, exists := actionTypeFuncMap[a.ActionType]
actionFunction, exists := getActionFunc(a.ActionType)
if !exists {
Logger.Warning(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType))
return

View File

@@ -22,6 +22,7 @@ import (
"bytes"
"encoding/gob"
"encoding/json"
"github.com/vmihailenco/msgpack"
"strings"
)
@@ -99,6 +100,16 @@ func (jbm *JSONBufMarshaler) Unmarshal(data []byte, v interface{}) error {
return json.NewDecoder(&jbm.buf).Decode(v)
}
type MsgpackMarshaler struct{}
func (jm *MsgpackMarshaler) Marshal(v interface{}) ([]byte, error) {
return msgpack.Marshal(v)
}
func (jm *MsgpackMarshaler) Unmarshal(data []byte, v interface{}) error {
return msgpack.Unmarshal(data, v)
}
type GOBMarshaler struct {
buf bytes.Buffer
}

View File

@@ -21,7 +21,7 @@ package rater
import (
"errors"
"fmt"
"github.com/fzzbt/radix/redis"
"github.com/fzzy/radix/redis"
"time"
)