ledisdb/server/http/base.go

33 lines
685 B
Go
Raw Normal View History

2014-07-22 07:31:56 +04:00
package http
import (
"errors"
"fmt"
"github.com/siddontang/ledisdb/ledis"
"strings"
)
2014-07-24 07:29:13 +04:00
const (
ERR_ARGUMENT_FORMAT = "ERR wrong number of arguments for '%s' command"
MSG_OK = "OK"
)
2014-07-22 07:31:56 +04:00
2014-07-24 07:29:13 +04:00
var (
ErrValue = errors.New("ERR value is not an integer or out of range")
ErrSyntax = errors.New("ERR syntax error")
)
2014-07-22 07:31:56 +04:00
type commondFunc func(*ledis.DB, ...string) (interface{}, error)
var regCmds = map[string]commondFunc{}
func register(name string, f commondFunc) {
if _, ok := regCmds[strings.ToLower(name)]; ok {
panic(fmt.Sprintf("%s has been registered", name))
}
regCmds[name] = f
}
func lookup(name string) commondFunc {
return regCmds[strings.ToLower(name)]
}