mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 17:18:44 +05:00
tested Msgpack, updated radix path, compilation for go tip
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package rater
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fzzbt/radix/redis"
|
||||
"github.com/fzzy/radix/redis"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user