ledisdb/server/http/base.go

33 lines
685 B
Go

package http
import (
"errors"
"fmt"
"github.com/siddontang/ledisdb/ledis"
"strings"
)
const (
ERR_ARGUMENT_FORMAT = "ERR wrong number of arguments for '%s' command"
MSG_OK = "OK"
)
var (
ErrValue = errors.New("ERR value is not an integer or out of range")
ErrSyntax = errors.New("ERR syntax error")
)
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)]
}