本文整理汇总了Golang中github.com/buaazp/uq/utils.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: MultiPush
// MultiPush implements MultiPush interface
func (u *UnitedQueue) MultiPush(key string, datas [][]byte) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
for i, data := range datas {
if len(data) <= 0 {
cause := "message " + strconv.Itoa(i) + " has no content"
return utils.NewError(
utils.ErrBadRequest,
cause,
)
}
}
u.topicsLock.RLock()
t, ok := u.topics[key]
u.topicsLock.RUnlock()
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue multiPush`,
)
}
return t.mPush(datas)
}
开发者ID:jnan77,项目名称:uq,代码行数:27,代码来源:uQueue.go
示例2: create
func (u *UnitedQueue) create(key, rec string, fromEtcd bool) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
var topicName, lineName string
var err error
parts := strings.Split(key, "/")
if len(parts) < 1 || len(parts) > 2 {
return utils.NewError(
utils.ErrBadKey,
`create key parts error: `+utils.ItoaQuick(len(parts)),
)
}
topicName = parts[0]
if topicName == "" {
return utils.NewError(
utils.ErrBadKey,
`create topic is nil`,
)
}
if len(parts) == 2 {
lineName = parts[1]
var recycle time.Duration
if rec != "" {
recycle, err = time.ParseDuration(rec)
if err != nil {
return utils.NewError(
utils.ErrBadRequest,
err.Error(),
)
}
}
u.topicsLock.RLock()
t, ok := u.topics[topicName]
u.topicsLock.RUnlock()
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue create`,
)
}
err = t.createLine(lineName, recycle, fromEtcd)
if err != nil {
// log.Printf("create line[%s] error: %s", lineName, err)
return err
}
} else {
err = u.createTopic(topicName, fromEtcd)
if err != nil {
// log.Printf("create topic[%s] error: %s", topicName, err)
return err
}
}
return err
}
开发者ID:jnan77,项目名称:uq,代码行数:60,代码来源:uQueue.go
示例3: Confirm
// Confirm implements Confirm interface
func (u *UnitedQueue) Confirm(key string) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
parts := strings.Split(key, "/")
if len(parts) != 3 {
return utils.NewError(
utils.ErrBadKey,
`confirm key parts error: `+utils.ItoaQuick(len(parts)),
)
}
topicName := parts[0]
lineName := parts[1]
id, err := strconv.ParseUint(parts[2], 10, 0)
if err != nil {
return utils.NewError(
utils.ErrBadKey,
`confirm key parse id error: `+err.Error(),
)
}
u.topicsLock.RLock()
t, ok := u.topics[topicName]
u.topicsLock.RUnlock()
if !ok {
// log.Printf("topic[%s] not existed.", topicName)
return utils.NewError(
utils.ErrTopicNotExisted,
`queue confirm`,
)
}
return t.confirm(lineName, id)
}
开发者ID:jnan77,项目名称:uq,代码行数:35,代码来源:uQueue.go
示例4: Pop
// Pop implements Pop interface
func (u *UnitedQueue) Pop(key string) (string, []byte, error) {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
parts := strings.Split(key, "/")
if len(parts) != 2 {
return "", nil, utils.NewError(
utils.ErrBadKey,
`pop key parts error: `+utils.ItoaQuick(len(parts)),
)
}
tName := parts[0]
lName := parts[1]
u.topicsLock.RLock()
t, ok := u.topics[tName]
u.topicsLock.RUnlock()
if !ok {
// log.Printf("topic[%s] not existed.", tName)
return "", nil, utils.NewError(
utils.ErrTopicNotExisted,
`queue pop`,
)
}
id, data, err := t.pop(lName)
if err != nil {
return "", nil, err
}
return utils.Acatui(key, "/", id), data, nil
}
开发者ID:jnan77,项目名称:uq,代码行数:34,代码来源:uQueue.go
示例5: createTopic
func (u *UnitedQueue) createTopic(name string, fromEtcd bool) error {
u.topicsLock.RLock()
_, ok := u.topics[name]
u.topicsLock.RUnlock()
if ok {
return utils.NewError(
utils.ErrTopicExisted,
`queue createTopic`,
)
}
t, err := u.newTopic(name)
if err != nil {
return err
}
u.topicsLock.Lock()
defer u.topicsLock.Unlock()
u.topics[name] = t
err = u.exportQueue()
if err != nil {
t.remove()
delete(u.topics, name)
return err
}
if !fromEtcd {
u.registerTopic(t.name)
}
log.Printf("topic[%s] created.", name)
return nil
}
开发者ID:jnan77,项目名称:uq,代码行数:33,代码来源:uQueue.go
示例6: onQmpop
func (r *RedisEntry) onQmpop(cmd *command) *reply {
key := cmd.stringAtIndex(1)
n, err := cmd.intAtIndex(2)
if err != nil {
return errorReply(utils.NewError(
utils.ErrBadRequest,
err.Error(),
))
}
ids, values, err := r.messageQueue.MultiPop(key, n)
if err != nil {
return errorReply(err)
}
np := len(ids)
vals := make([]interface{}, np*2)
for i, index := 0, 0; i < np; i++ {
vals[index] = values[i]
index++
vals[index] = ids[i]
index++
}
return multiBulksReply(vals)
}
开发者ID:henser123,项目名称:uq,代码行数:28,代码来源:redisQueue.go
示例7: statHandler
func (s *UnitedAdmin) statHandler(w http.ResponseWriter, req *http.Request, key string) {
if req.Method != "GET" {
http.Error(w, "405 Method Not Allowed!", http.StatusMethodNotAllowed)
return
}
qs, err := s.messageQueue.Stat(key)
if err != nil {
writeErrorHTTP(w, err)
return
}
// log.Printf("qs: %v", qs)
data, err := qs.ToJSON()
if err != nil {
writeErrorHTTP(w, utils.NewError(
utils.ErrInternalError,
err.Error(),
))
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(data)
}
开发者ID:henser123,项目名称:uq,代码行数:26,代码来源:uAdmin.go
示例8: removeTopic
func (u *UnitedQueue) removeTopic(name string, fromEtcd bool) error {
u.topicsLock.Lock()
defer u.topicsLock.Unlock()
t, ok := u.topics[name]
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue remove`,
)
}
delete(u.topics, name)
err := u.exportQueue()
if err != nil {
u.topics[name] = t
return err
}
if !fromEtcd {
u.unRegisterTopic(name)
}
return t.remove()
}
开发者ID:jnan77,项目名称:uq,代码行数:25,代码来源:uQueue.go
示例9: createLine
func (t *topic) createLine(name string, recycle time.Duration, fromEtcd bool) error {
t.linesLock.Lock()
defer t.linesLock.Unlock()
_, ok := t.lines[name]
if ok {
return utils.NewError(
utils.ErrLineExisted,
`topic createLine`,
)
}
l, err := t.newLine(name, recycle)
if err != nil {
return err
}
t.lines[name] = l
err = t.exportTopic()
if err != nil {
t.linesLock.Lock()
delete(t.lines, name)
t.linesLock.Unlock()
return err
}
if !fromEtcd {
t.q.registerLine(t.name, l.name, l.recycle.String())
}
log.Printf("topic[%s] line[%s:%v] created.", t.name, name, recycle)
return nil
}
开发者ID:henser123,项目名称:uq,代码行数:33,代码来源:uTopic.go
示例10: removeLine
func (t *topic) removeLine(name string, fromEtcd bool) error {
t.linesLock.RLock()
defer t.linesLock.RUnlock()
l, ok := t.lines[name]
if !ok {
// log.Printf("topic[%s] line[%s] not existed.", t.name, name)
return utils.NewError(
utils.ErrLineNotExisted,
`topic statLine`,
)
}
delete(t.lines, name)
err := t.exportTopic()
if err != nil {
t.linesLock.Lock()
t.lines[name] = l
t.linesLock.Unlock()
return err
}
if !fromEtcd {
t.q.unRegisterLine(t.name, name)
}
return l.remove()
}
开发者ID:henser123,项目名称:uq,代码行数:27,代码来源:uTopic.go
示例11: pop
func (l *line) pop() (uint64, []byte, error) {
l.inflightLock.Lock()
defer l.inflightLock.Unlock()
now := time.Now()
if l.recycle > 0 {
m := l.inflight.Front()
if m != nil {
msg := m.Value.(*InflightMessage)
exp := time.Unix(0, msg.Exptime)
if now.After(exp) {
// log.Printf("key[%s/%d] is expired.", l.name, msg.Tid)
msg.Exptime = now.Add(l.recycle).UnixNano()
data, err := l.t.getData(msg.Tid)
if err != nil {
return 0, nil, err
}
l.inflight.Remove(m)
l.inflight.PushBack(msg)
// log.Printf("key[%s/%s/%d] poped.", l.t.name, l.name, msg.Tid)
return msg.Tid, data, nil
}
}
}
l.headLock.Lock()
defer l.headLock.Unlock()
tid := l.head
topicTail := l.t.getTail()
if l.head >= topicTail {
// log.Printf("line[%s] is blank. head:%d - tail:%d", l.name, l.head, l.t.tail)
return 0, nil, utils.NewError(
utils.ErrNone,
`line pop`,
)
}
data, err := l.t.getData(tid)
if err != nil {
return 0, nil, err
}
l.head++
if l.recycle > 0 {
msg := new(InflightMessage)
msg.Tid = tid
msg.Exptime = now.Add(l.recycle).UnixNano()
l.inflight.PushBack(msg)
// log.Printf("key[%s/%s/%d] flighted.", l.t.name, l.name, l.head)
l.imap[tid] = true
}
return tid, data, nil
}
开发者ID:henser123,项目名称:uq,代码行数:58,代码来源:uLine.go
示例12: Empty
// Empty implements Empty interface
func (u *UnitedQueue) Empty(key string) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
var topicName, lineName string
parts := strings.Split(key, "/")
if len(parts) < 1 || len(parts) > 2 {
return utils.NewError(
utils.ErrBadKey,
`empty key parts error: `+utils.ItoaQuick(len(parts)),
)
}
topicName = parts[0]
if topicName == "" {
return utils.NewError(
utils.ErrBadKey,
`empty topic is nil`,
)
}
u.topicsLock.RLock()
t, ok := u.topics[topicName]
u.topicsLock.RUnlock()
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue empty`,
)
}
if len(parts) == 2 {
lineName = parts[1]
return t.emptyLine(lineName)
// err = t.emptyLine(lineName)
// if err != nil {
// log.Printf("empty line[%s] error: %s", lineName, err)
// }
// return err
}
return t.empty()
}
开发者ID:jnan77,项目名称:uq,代码行数:45,代码来源:uQueue.go
示例13: delData
func (u *UnitedQueue) delData(key string) error {
err := u.storage.Del(key)
if err != nil {
// log.Printf("key[%s] del data error: %s", key, err)
return utils.NewError(
utils.ErrInternalError,
err.Error(),
)
}
return nil
}
开发者ID:jnan77,项目名称:uq,代码行数:11,代码来源:uQueue.go
示例14: setData
func (u *UnitedQueue) setData(key string, data []byte) error {
err := u.storage.Set(key, data)
if err != nil {
// log.Printf("key[%s] set data error: %s", key, err)
return utils.NewError(
utils.ErrInternalError,
err.Error(),
)
}
return nil
}
开发者ID:jnan77,项目名称:uq,代码行数:11,代码来源:uQueue.go
示例15: getData
func (u *UnitedQueue) getData(key string) ([]byte, error) {
data, err := u.storage.Get(key)
if err != nil {
// log.Printf("key[%s] get data error: %s", key, err)
return nil, utils.NewError(
utils.ErrInternalError,
err.Error(),
)
}
return data, nil
}
开发者ID:jnan77,项目名称:uq,代码行数:11,代码来源:uQueue.go
示例16: Stat
// Stat implements Stat interface
func (u *UnitedQueue) Stat(key string) (*Stat, error) {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
var topicName, lineName string
parts := strings.Split(key, "/")
if len(parts) < 1 || len(parts) > 2 {
return nil, utils.NewError(
utils.ErrBadKey,
`empty key parts error: `+utils.ItoaQuick(len(parts)),
)
}
topicName = parts[0]
if topicName == "" {
return nil, utils.NewError(
utils.ErrBadKey,
`stat topic is nil`,
)
}
u.topicsLock.RLock()
t, ok := u.topics[topicName]
u.topicsLock.RUnlock()
if !ok {
return nil, utils.NewError(
utils.ErrTopicNotExisted,
`queue stat`,
)
}
if len(parts) == 2 {
lineName = parts[1]
return t.statLine(lineName)
}
qs := t.stat()
return qs, nil
}
开发者ID:jnan77,项目名称:uq,代码行数:40,代码来源:uQueue.go
示例17: remove
func (u *UnitedQueue) remove(key string, fromEtcd bool) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
var topicName, lineName string
parts := strings.Split(key, "/")
if len(parts) < 1 || len(parts) > 2 {
return utils.NewError(
utils.ErrBadKey,
`remove key parts error: `+utils.ItoaQuick(len(parts)),
)
}
topicName = parts[0]
if topicName == "" {
return utils.NewError(
utils.ErrBadKey,
`rmove topic is nil`,
)
}
if len(parts) == 1 {
return u.removeTopic(topicName, fromEtcd)
}
u.topicsLock.RLock()
t, ok := u.topics[topicName]
u.topicsLock.RUnlock()
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue remove`,
)
}
lineName = parts[1]
return t.removeLine(lineName, fromEtcd)
}
开发者ID:jnan77,项目名称:uq,代码行数:38,代码来源:uQueue.go
示例18: Push
// Push implements Push interface
func (u *UnitedQueue) Push(key string, data []byte) error {
key = strings.TrimPrefix(key, "/")
key = strings.TrimSuffix(key, "/")
if len(data) <= 0 {
return utils.NewError(
utils.ErrBadRequest,
`message has no content`,
)
}
u.topicsLock.RLock()
t, ok := u.topics[key]
u.topicsLock.RUnlock()
if !ok {
return utils.NewError(
utils.ErrTopicNotExisted,
`queue push`,
)
}
return t.push(data)
}
开发者ID:jnan77,项目名称:uq,代码行数:24,代码来源:uQueue.go
示例19: emptyLine
func (t *topic) emptyLine(name string) error {
t.linesLock.RLock()
l, ok := t.lines[name]
t.linesLock.RUnlock()
if !ok {
// log.Printf("topic[%s] line[%s] not existed.", t.name, name)
return utils.NewError(
utils.ErrLineNotExisted,
`topic emptyLine`,
)
}
return l.empty()
}
开发者ID:henser123,项目名称:uq,代码行数:14,代码来源:uTopic.go
示例20: confirm
func (t *topic) confirm(name string, id uint64) error {
t.linesLock.RLock()
l, ok := t.lines[name]
t.linesLock.RUnlock()
if !ok {
// log.Printf("topic[%s] line[%s] not existed.", t.name, name)
return utils.NewError(
utils.ErrLineNotExisted,
`topic confirm`,
)
}
return l.confirm(id)
}
开发者ID:henser123,项目名称:uq,代码行数:14,代码来源:uTopic.go
注:本文中的github.com/buaazp/uq/utils.NewError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论