small fixses

This commit is contained in:
Radu Ioan Fericean
2013-05-30 18:26:27 +03:00
parent 6966a85e68
commit 84f489a73a
3 changed files with 13 additions and 6 deletions

View File

@@ -19,10 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package cdrs
import (
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
"github.com/cgrates/cgrates/rater"
"github.com/cgrates/cgrates/utils"
"strconv"
@@ -70,10 +68,7 @@ func (fsCdr FSCdr) New(body []byte) (rater.CDR, error) {
}
func (fsCdr FSCdr) GetCgrId() string {
hasher := sha1.New()
hasher.Write([]byte(fsCdr[FS_IP]))
hasher.Write([]byte(fsCdr[UUID]))
return fmt.Sprintf("%x", hasher.Sum(nil))
return utils.FSCgrId(fsCdr[UUID])
}
func (fsCdr FSCdr) GetAccId() string {
return fsCdr[UUID]

View File

@@ -218,6 +218,7 @@ func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *rater.Cal
if err != nil {
m.loggerDb.LogError(record[m.uuidIndexs[runIdx]], rater.MEDIATOR_SOURCE, err.Error())
} else {
// If the mediator calculated a price it will write it to logdb
m.loggerDb.LogCallCost(record[m.uuidIndexs[runIdx]], rater.MEDIATOR_SOURCE, cc)
}
return

View File

@@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package utils
import (
"crypto/sha1"
"fmt"
)
// Returns first non empty string out of vals. Useful to extract defaults
func FirstNonEmpty(vals ...string) string {
for _, val := range vals {
@@ -27,3 +32,9 @@ func FirstNonEmpty(vals ...string) string {
}
return ""
}
func FSCgrId(uuid string) string {
hasher := sha1.New()
hasher.Write([]byte(uuid))
return fmt.Sprintf("%x", hasher.Sum(nil))
}