本文整理匯總了Golang中github.com/fiorix/go-diameter/diam.Message.FindAVP方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.FindAVP方法的具體用法?Golang Message.FindAVP怎麽用?Golang Message.FindAVP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fiorix/go-diameter/diam.Message
的用法示例。
在下文中一共展示了Message.FindAVP方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testResultCode
func testResultCode(m *diam.Message, want uint32) bool {
rc, err := m.FindAVP("Result-Code")
if err != nil {
return false
}
if code, ok := rc.Data.(datatype.Unsigned32); ok {
return uint32(code) == want
}
return false
}
示例2: metaHandler
// Handler for meta functions
func metaHandler(m *diam.Message, tag, arg string, dur time.Duration) (string, error) {
switch tag {
case META_CCR_USAGE:
var ok bool
var reqType datatype.Enumerated
var reqNr, reqUnit, usedUnit datatype.Unsigned32
if ccReqTypeAvp, err := m.FindAVP("CC-Request-Type", 0); err != nil {
return "", err
} else if ccReqTypeAvp == nil {
return "", errors.New("CC-Request-Type not found")
} else if reqType, ok = ccReqTypeAvp.Data.(datatype.Enumerated); !ok {
return "", fmt.Errorf("CC-Request-Type must be Enumerated and not %v", ccReqTypeAvp.Data.Type())
}
if ccReqNrAvp, err := m.FindAVP("CC-Request-Number", 0); err != nil {
return "", err
} else if ccReqNrAvp == nil {
return "", errors.New("CC-Request-Number not found")
} else if reqNr, ok = ccReqNrAvp.Data.(datatype.Unsigned32); !ok {
return "", fmt.Errorf("CC-Request-Number must be Unsigned32 and not %v", ccReqNrAvp.Data.Type())
}
switch reqType {
case datatype.Enumerated(1), datatype.Enumerated(2):
if reqUnitAVPs, err := m.FindAVPsWithPath([]interface{}{"Requested-Service-Unit", "CC-Time"}, dict.UndefinedVendorID); err != nil {
return "", err
} else if len(reqUnitAVPs) == 0 {
return "", errors.New("Requested-Service-Unit>CC-Time not found")
} else if reqUnit, ok = reqUnitAVPs[0].Data.(datatype.Unsigned32); !ok {
return "", fmt.Errorf("Requested-Service-Unit>CC-Time must be Unsigned32 and not %v", reqUnitAVPs[0].Data.Type())
}
case datatype.Enumerated(3), datatype.Enumerated(4):
if usedUnitAVPs, err := m.FindAVPsWithPath([]interface{}{"Used-Service-Unit", "CC-Time"}, dict.UndefinedVendorID); err != nil {
return "", err
} else if len(usedUnitAVPs) != 0 {
if usedUnit, ok = usedUnitAVPs[0].Data.(datatype.Unsigned32); !ok {
return "", fmt.Errorf("Used-Service-Unit>CC-Time must be Unsigned32 and not %v", usedUnitAVPs[0].Data.Type())
}
}
}
usage := usageFromCCR(int(reqType), int(reqNr), int(reqUnit), int(usedUnit), dur)
return strconv.FormatFloat(usage.Seconds(), 'f', -1, 64), nil
}
return "", nil
}