本文整理匯總了Golang中github.com/cgrates/cgrates/utils.InfieldJoin函數的典型用法代碼示例。如果您正苦於以下問題:Golang InfieldJoin函數的具體用法?Golang InfieldJoin怎麽用?Golang InfieldJoin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了InfieldJoin函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Subscribe
func (ps *PubSub) Subscribe(si SubscribeInfo, reply *string) error {
ps.mux.Lock()
defer ps.mux.Unlock()
if si.Transport != utils.META_HTTP_POST {
*reply = "Unsupported transport type"
return errors.New(*reply)
}
var expTime time.Time
if si.LifeSpan > 0 {
expTime = time.Now().Add(si.LifeSpan)
}
rsr, err := utils.ParseRSRFields(si.EventFilter, utils.INFIELD_SEP)
if err != nil {
*reply = err.Error()
return err
}
key := utils.InfieldJoin(si.Transport, si.Address)
ps.subscribers[key] = &SubscriberData{
ExpTime: expTime,
Filters: rsr,
}
ps.saveSubscriber(key)
*reply = utils.OK
return nil
}
示例2: Unsubscribe
func (ps *PubSub) Unsubscribe(si SubscribeInfo, reply *string) error {
ps.mux.Lock()
defer ps.mux.Unlock()
if si.Transport != utils.META_HTTP_POST {
*reply = "Unsupported transport type"
return errors.New(*reply)
}
key := utils.InfieldJoin(si.Transport, si.Address)
delete(ps.subscribers, key)
ps.removeSubscriber(key)
*reply = utils.OK
return nil
}
示例3: TestSubscribe
func TestSubscribe(t *testing.T) {
ps := NewPubSub(accountingStorage, false)
var r string
if err := ps.Subscribe(SubscribeInfo{
EventFilter: "EventName/test",
Transport: utils.META_HTTP_POST,
Address: "url",
LifeSpan: time.Second,
}, &r); err != nil {
t.Error("Error subscribing: ", err)
}
if subData, exists := ps.subscribers[utils.InfieldJoin(utils.META_HTTP_POST, "url")]; !exists || subData.ExpTime.IsZero() {
t.Error("Error adding subscriber: ", ps.subscribers)
}
}