コード例 #1
0
ファイル: kv_redis.go プロジェクト: cosiner/kv
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
}
コード例 #2
0
ファイル: pool.go プロジェクト: fanbuchi/zerver
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
}
コード例 #3
0
ファイル: component.go プロジェクト: jacobzheng/zerver
		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()
コード例 #4
0
ファイル: router.go プロジェクト: jacobzheng/zerver
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