Ejemplo n.º 1
0
func (r *RedisStore) HScan(hash string, cursor Cursor, pattern string, count int) (Cursor, interface{}, error) {
	var args []interface{}
	if pattern != "" && count > 0 {
		args = []interface{}{hash, cursor, "MATCH", pattern, "COUNT", count}
	} else if pattern != "" {
		args = []interface{}{hash, cursor, "MATCH", pattern}
	} else if count > 0 {
		args = []interface{}{hash, cursor, "COUNT", count}
	} else {
		args = []interface{}{hash, cursor}
	}
	reply, err := r.exec("HSCAN", args...)
	vals, err := r.Values(reply, err)
	if err != nil {
		return 0, nil, err
	}

	valsLen := len(vals)
	if valsLen == 0 {
		return 0, nil, errors.New("invalid response of hscan commond, no cursor reply")
	}
	cs, err := r.Int(vals[0], nil)
	if err != nil {
		return 0, nil, err
	}
	if valsLen == 1 {
		return 0, nil, nil
	}
	return Cursor(cs), vals[1], nil
}
Ejemplo n.º 2
0
func ReigisterPool(id int, newFunc func() interface{}) error {
	op := _defaultPool.otherPools
	if _, has := op[id]; has {
		return errors.New("Pool for ", id, " already exist")
	}

	op[id] = &sync.Pool{New: newFunc}
	return nil
}
Ejemplo n.º 3
0
		e.comp.Destroy()
	}
}

func (e *CompEnv) underlay() interface{} {
	if e.value != nil {
		return e.value
	}

	return e.comp
}

// =============================================================================
//                                  Component Manager
// =============================================================================
var ErrCompNotFound = errors.New("component not found")

type CompManager struct {
	components map[string]*CompEnv
	anonymous  []Component
	mu         sync.RWMutex
}

func NewCompManager() CompManager {
	return CompManager{
		components: make(map[string]*CompEnv),
	}
}

func (m *CompManager) Get(name string) (interface{}, error) {
	m.mu.RLock()
Ejemplo n.º 4
0
package zerver

import (
	"io"
	"log"
	"net/url"
	"strings"

	"github.com/cosiner/gohper/errors"
	"github.com/cosiner/gohper/strings2"
	"github.com/cosiner/gohper/unsafe2"
)

var (
	ErrConflictPathVar = errors.New("There is a similar route pattern which use same wildcard" +
		" or catchall at the same position, " +
		"this means one of them will nerver be matched, " +
		"please check your routes")
	ErrHandlerExists = errors.New("pattern handler already exists.")
)

type (
	Router interface {
		Component

		PrintRouteTree(w io.Writer)

		Filter(pattern string, f Filter) error
		FilterFunc(pattern string, f FilterFunc) error
		Handler(pattern string, h Handler) error
		TaskHandler(pattern string, th TaskHandler) error
		WsHandler(pattern string, th WsConn) error