本文整理汇总了Golang中github.com/cgrates/cgrates/utils.NewErrMandatoryIeMissing函数的典型用法代码示例。如果您正苦于以下问题:Golang NewErrMandatoryIeMissing函数的具体用法?Golang NewErrMandatoryIeMissing怎么用?Golang NewErrMandatoryIeMissing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewErrMandatoryIeMissing函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AsKamAuthReply
func (kev KamEvent) AsKamAuthReply(maxSessionTime float64, suppliers string, resErr error) (*KamAuthReply, error) {
var err error
kar := &KamAuthReply{Event: CGR_AUTH_REPLY, Suppliers: suppliers}
if resErr != nil {
kar.Error = resErr.Error()
}
if _, hasIt := kev[KAM_TR_INDEX]; !hasIt {
return nil, utils.NewErrMandatoryIeMissing(KAM_TR_INDEX, "")
}
if kar.TransactionIndex, err = strconv.Atoi(kev[KAM_TR_INDEX]); err != nil {
return nil, err
}
if _, hasIt := kev[KAM_TR_LABEL]; !hasIt {
return nil, utils.NewErrMandatoryIeMissing(KAM_TR_LABEL, "")
}
if kar.TransactionLabel, err = strconv.Atoi(kev[KAM_TR_LABEL]); err != nil {
return nil, err
}
if maxSessionTime != -1 { // Convert maxSessionTime from nanoseconds into seconds
maxSessionDur := time.Duration(maxSessionTime)
maxSessionTime = maxSessionDur.Seconds()
}
kar.MaxSessionTime = int(utils.Round(maxSessionTime, 0, utils.ROUNDING_MIDDLE))
return kar, nil
}
示例2: RemActionTiming
// Removes an ActionTimings or parts of it depending on filters being set
func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ActionPlanId"}); len(missing) != 0 { // Only mandatory ActionPlanId
return utils.NewErrMandatoryIeMissing(missing...)
}
if len(attrs.Account) != 0 { // Presence of Account requires complete account details to be provided
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
}
_, err := engine.Guardian.Guard(func() (interface{}, error) {
ats, err := self.RatingDb.GetActionPlans(attrs.ActionPlanId, false)
if err != nil {
return 0, err
} else if len(ats) == 0 {
return 0, utils.ErrNotFound
}
ats = engine.RemActionPlan(ats, attrs.ActionTimingId, utils.AccountKey(attrs.Tenant, attrs.Account))
if err := self.RatingDb.SetActionPlans(attrs.ActionPlanId, ats); err != nil {
return 0, err
}
if len(ats) > 0 { // update cache
self.RatingDb.CacheRatingPrefixValues(map[string][]string{utils.ACTION_PLAN_PREFIX: []string{utils.ACTION_PLAN_PREFIX + attrs.ActionPlanId}})
}
return 0, nil
}, 0, utils.ACTION_PLAN_PREFIX)
if err != nil {
return utils.NewErrServerError(err)
}
if attrs.ReloadScheduler && self.Sched != nil {
self.Sched.LoadActionPlans(self.RatingDb)
self.Sched.Restart()
}
*reply = OK
return nil
}
示例3: RemActionTiming
// Removes an ActionTimings or parts of it depending on filters being set
func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ActionPlanId"}); len(missing) != 0 { // Only mandatory ActionPlanId
return utils.NewErrMandatoryIeMissing(missing...)
}
if len(attrs.Account) != 0 { // Presence of Account requires complete account details to be provided
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
}
_, err := engine.Guardian.Guard(func() (interface{}, error) {
ap, err := self.RatingDb.GetActionPlan(attrs.ActionPlanId, false)
if err != nil {
return 0, err
} else if ap == nil {
return 0, utils.ErrNotFound
}
if attrs.Tenant != "" && attrs.Account != "" {
accID := utils.AccountKey(attrs.Tenant, attrs.Account)
delete(ap.AccountIDs, accID)
err = self.RatingDb.SetActionPlan(ap.Id, ap, true)
goto UPDATE
}
if attrs.ActionTimingId != "" { // delete only a action timing from action plan
for i, at := range ap.ActionTimings {
if at.Uuid == attrs.ActionTimingId {
ap.ActionTimings[i] = ap.ActionTimings[len(ap.ActionTimings)-1]
ap.ActionTimings = ap.ActionTimings[:len(ap.ActionTimings)-1]
break
}
}
err = self.RatingDb.SetActionPlan(ap.Id, ap, true)
goto UPDATE
}
if attrs.ActionPlanId != "" { // delete the entire action plan
ap.ActionTimings = nil // will delete the action plan
err = self.RatingDb.SetActionPlan(ap.Id, ap, true)
goto UPDATE
}
UPDATE:
if err != nil {
return 0, err
}
// update cache
self.RatingDb.CacheRatingPrefixValues("AttrRemActionTimingAPI", map[string][]string{utils.ACTION_PLAN_PREFIX: []string{utils.ACTION_PLAN_PREFIX + attrs.ActionPlanId}})
return 0, nil
}, 0, utils.ACTION_PLAN_PREFIX)
if err != nil {
*reply = err.Error()
return utils.NewErrServerError(err)
}
if attrs.ReloadScheduler && self.Sched != nil {
self.Sched.Reload(true)
}
*reply = OK
return nil
}
示例4: GetTPAccountActions
// Queries specific DerivedCharge on tariff plan
func (self *ApierV1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.TPAccountActions) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
tmpAa := &utils.TPAccountActions{TPid: attrs.TPid}
if err := tmpAa.SetAccountActionsId(attrs.AccountActionsId); err != nil {
return err
}
tmpAaa := engine.APItoModelAccountAction(tmpAa)
if aas, err := self.StorDb.GetTpAccountActions(tmpAaa); err != nil {
return utils.NewErrServerError(err)
} else if len(aas) == 0 {
return utils.ErrNotFound
} else {
tpAaa, err := engine.TpAccountActions(aas).GetAccountActions()
if err != nil {
return err
}
aa := tpAaa[tmpAa.KeyId()]
tpdc := utils.TPAccountActions{
TPid: attrs.TPid,
ActionPlanId: aa.ActionPlanId,
ActionTriggersId: aa.ActionTriggersId,
}
if err := tpdc.SetAccountActionsId(attrs.AccountActionsId); err != nil {
return err
}
*reply = tpdc
}
return nil
}
示例5: GetTPAccountActionsByLoadId
// Queries specific AccountActions profile on tariff plan
func (self *ApierV1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, reply *[]*utils.TPAccountActions) error {
mndtryFlds := []string{"TPid", "LoadId"}
if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory
mndtryFlds = append(mndtryFlds, "Tenant", "Account")
}
if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
aas := engine.APItoModelAccountAction(&attrs)
if aa, err := self.StorDb.GetTpAccountActions(aas); err != nil {
return utils.NewErrServerError(err)
} else if len(aa) == 0 {
return utils.ErrNotFound
} else {
tpAa, err := engine.TpAccountActions(aa).GetAccountActions()
if err != nil {
return err
}
var acts []*utils.TPAccountActions
if len(attrs.Account) != 0 {
acts = []*utils.TPAccountActions{tpAa[attrs.KeyId()]}
} else {
for _, actLst := range tpAa {
acts = append(acts, actLst)
}
}
*reply = acts
}
return nil
}
示例6: GetDestinations
func (self *ApierV2) GetDestinations(attr AttrGetDestinations, reply *[]*engine.Destination) error {
dests := make([]*engine.Destination, 0)
if attr.DestinationIDs == nil {
return utils.NewErrMandatoryIeMissing("DestIDs")
}
if len(attr.DestinationIDs) == 0 {
// get all destination ids
destIDs, err := self.RatingDb.GetKeysForPrefix(utils.DESTINATION_PREFIX)
if err != nil {
return err
}
for _, destID := range destIDs {
attr.DestinationIDs = append(attr.DestinationIDs, destID[len(utils.DESTINATION_PREFIX):])
}
}
for _, destID := range attr.DestinationIDs {
dst, err := self.RatingDb.GetDestination(destID, false, utils.NonTransactional)
if err != nil {
return err
}
dests = append(dests, dst)
}
*reply = dests
return nil
}
示例7: GetAccountActionPlan
func (self *ApierV1) GetAccountActionPlan(attrs AttrAcntAction, reply *[]*AccountActionTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(strings.Join(missing, ","), "")
}
accountATs := make([]*AccountActionTiming, 0) // needs to be initialized if remains empty
allAPs, err := self.RatingDb.GetAllActionPlans()
if err != nil {
return utils.NewErrServerError(err)
}
accID := utils.AccountKey(attrs.Tenant, attrs.Account)
for _, ap := range allAPs {
if ap == nil {
continue
}
if _, exists := ap.AccountIDs[accID]; exists {
for _, at := range ap.ActionTimings {
accountATs = append(accountATs, &AccountActionTiming{
ActionPlanId: ap.Id,
Uuid: at.Uuid,
ActionsId: at.ActionsID,
NextExecTime: at.GetNextStartTime(time.Now()),
})
}
}
}
*reply = accountATs
return nil
}
示例8: ImportTariffPlanFromFolder
func (self *ApierV1) ImportTariffPlanFromFolder(attrs utils.AttrImportTPFromFolder, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "FolderPath"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if len(attrs.CsvSeparator) == 0 {
attrs.CsvSeparator = ","
}
if fi, err := os.Stat(attrs.FolderPath); err != nil {
if strings.HasSuffix(err.Error(), "no such file or directory") {
return utils.ErrInvalidPath
}
return utils.NewErrServerError(err)
} else if !fi.IsDir() {
return utils.ErrInvalidPath
}
csvImporter := engine.TPCSVImporter{
TPid: attrs.TPid,
StorDb: self.StorDb,
DirPath: attrs.FolderPath,
Sep: rune(attrs.CsvSeparator[0]),
Verbose: false,
ImportId: attrs.RunId,
}
if err := csvImporter.Run(); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
示例9: LoadRatingPlan
// Process dependencies and load a specific rating plan from storDb into dataDb.
func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid, self.Config.DefaultTimezone, self.Config.LoadHistorySize)
if loaded, err := dbReader.LoadRatingPlansFiltered(attrs.RatingPlanId); err != nil {
return utils.NewErrServerError(err)
} else if !loaded {
return utils.ErrNotFound
}
//Automatic cache of the newly inserted rating plan
var changedRPlKeys []string
if len(attrs.TPid) != 0 {
if attrs.RatingPlanId != "" {
changedRPlKeys = []string{utils.RATING_PLAN_PREFIX + attrs.RatingPlanId}
} else {
changedRPlKeys = nil
}
}
if err := self.RatingDb.CacheRatingPrefixValues(map[string][]string{
utils.DESTINATION_PREFIX: nil,
utils.RATING_PLAN_PREFIX: changedRPlKeys,
}); err != nil {
return err
}
*reply = OK
return nil
}
示例10: RemoveAccountActionTriggers
func (self *ApierV1) RemoveAccountActionTriggers(attr AttrRemoveAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
_, err := engine.Guardian.Guard(func() (interface{}, error) {
var account *engine.Account
if acc, err := self.AccountDb.GetAccount(accID); err == nil {
account = acc
} else {
return 0, err
}
var newActionTriggers engine.ActionTriggers
for _, at := range account.ActionTriggers {
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
// remove action trigger
continue
}
newActionTriggers = append(newActionTriggers, at)
}
account.ActionTriggers = newActionTriggers
account.InitCounters()
if err := self.AccountDb.SetAccount(account); err != nil {
return 0, err
}
return 0, nil
}, 0, accID)
if err != nil {
*reply = err.Error()
return err
}
*reply = utils.OK
return nil
}
示例11: RemRatingSubjectAliases
// Remove aliases configured for a rating profile subject
func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRatingSubject, reply *string) error {
if missing := utils.MissingStructFields(&tenantRatingSubject, []string{"Tenant", "Subject"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
aliases := engine.GetAliasService()
if aliases == nil {
return errors.New("ALIASES_NOT_ENABLED")
}
var reverseAliases map[string][]*engine.Alias
if err := aliases.Call("AliasesV1.GetReverseAlias", &engine.AttrReverseAlias{Target: "Subject", Alias: tenantRatingSubject.Subject, Context: utils.ALIAS_CONTEXT_RATING}, &reverseAliases); err != nil {
return utils.NewErrServerError(err)
}
var ignr string
for _, aliass := range reverseAliases {
for _, alias := range aliass {
if alias.Tenant != tenantRatingSubject.Tenant {
continue // From another tenant
}
if err := aliases.Call("AliasesV1.RemoveAlias", alias, &ignr); err != nil {
return utils.NewErrServerError(err)
}
}
}
*reply = utils.OK
return nil
}
示例12: RemoveActionTrigger
func (self *ApierV1) RemoveActionTrigger(attr AttrRemoveActionTrigger, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attr.UniqueID == "" {
err := self.RatingDb.RemoveActionTriggers(attr.GroupID, utils.NonTransactional)
if err != nil {
*reply = err.Error()
} else {
*reply = utils.OK
}
return err
} else {
atrs, err := self.RatingDb.GetActionTriggers(attr.GroupID, false, utils.NonTransactional)
if err != nil {
*reply = err.Error()
return err
}
var remainingAtrs engine.ActionTriggers
for _, atr := range atrs {
if atr.UniqueID == attr.UniqueID {
continue
}
remainingAtrs = append(remainingAtrs, atr)
}
// set the cleared list back
err = self.RatingDb.SetActionTriggers(attr.GroupID, remainingAtrs, utils.NonTransactional)
if err != nil {
*reply = err.Error()
} else {
*reply = utils.OK
}
return err
}
}
示例13: GetTPRatingProfile
// Queries specific RatingProfile on tariff plan
func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
tmpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
if err := tmpRpf.SetRatingProfilesId(attrs.RatingProfileId); err != nil {
return err
}
rpf := engine.APItoModelRatingProfile(tmpRpf)
if rpfs, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
return utils.NewErrServerError(err)
} else if len(rpfs) == 0 {
return utils.ErrNotFound
} else {
rpfMap, err := engine.TpRatingProfiles(rpfs).GetRatingProfiles()
if err != nil {
return err
}
rpf := rpfMap[tmpRpf.KeyId()]
tpdc := utils.TPRatingProfile{
TPid: attrs.TPid,
RatingPlanActivations: rpf.RatingPlanActivations,
}
if err := tpdc.SetRatingProfilesId(attrs.RatingProfileId); err != nil {
return err
}
*reply = tpdc
}
return nil
}
示例14: LoadAccountActions
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *string) error {
if len(attrs.TPid) == 0 {
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid, self.Config.DefaultTimezone, self.Config.LoadHistorySize)
tpAa := &utils.TPAccountActions{TPid: attrs.TPid}
tpAa.SetAccountActionsId(attrs.AccountActionsId)
aa := engine.APItoModelAccountAction(tpAa)
if _, err := engine.Guardian.Guard(func() (interface{}, error) {
if err := dbReader.LoadAccountActionsFiltered(aa); err != nil {
return 0, err
}
return 0, nil
}, 0, attrs.AccountActionsId); err != nil {
return utils.NewErrServerError(err)
}
// ToDo: Get the action keys loaded by dbReader so we reload only these in cache
// Need to do it before scheduler otherwise actions to run will be unknown
if err := self.RatingDb.CacheRatingPrefixes(utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.SHARED_GROUP_PREFIX); err != nil {
return err
}
if self.Sched != nil {
self.Sched.Reload(true)
}
*reply = v1.OK
return nil
}
示例15: GetTPRatingProfilesByLoadId
// Queries specific RatingProfile on tariff plan
func (self *ApierV1) GetTPRatingProfilesByLoadId(attrs utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error {
mndtryFlds := []string{"TPid", "LoadId"}
if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory
mndtryFlds = append(mndtryFlds, "Tenant", "TOR", "Direction", "Subject")
}
if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
rpf := engine.APItoModelRatingProfile(&attrs)
if dr, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
return utils.NewErrServerError(err)
} else if dr == nil {
return utils.ErrNotFound
} else {
rpfMap, err := engine.TpRatingProfiles(dr).GetRatingProfiles()
if err != nil {
return err
}
var rpfs []*utils.TPRatingProfile
if len(attrs.Subject) != 0 {
rpfs = []*utils.TPRatingProfile{rpfMap[attrs.KeyId()]}
} else {
for _, rpfLst := range rpfMap {
rpfs = append(rpfs, rpfLst)
}
}
*reply = rpfs
}
return nil
}