本文整理汇总了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)
}
}