ledisdb/server/http/base.go

35 lines
675 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 (
2014-07-24 07:41:53 +04:00
ERR_ARGUMENT_FORMAT = "wrong number of arguments for '%s' command"
2014-07-24 07:29:13 +04:00
MSG_OK = "OK"
)
2014-07-22 07:31:56 +04:00
2014-07-24 07:29:13 +04:00
var (
2014-07-24 07:41:53 +04:00
ErrValue = errors.New("value is not an integer or out of range")
ErrSyntax = errors.New("syntax error")
2014-07-24 07:29:13 +04:00
)
2014-07-22 07:31:56 +04:00
2014-07-25 11:18:39 +04:00
type commandFunc func(*ledis.DB, ...string) (interface{}, error)
2014-07-22 07:31:56 +04:00
2014-07-25 11:18:39 +04:00
var regCmds = map[string]commandFunc{}
2014-07-22 07:31:56 +04:00
2014-07-25 11:18:39 +04:00
func register(name string, f commandFunc) {
2014-07-22 07:31:56 +04:00
if _, ok := regCmds[strings.ToLower(name)]; ok {
panic(fmt.Sprintf("%s has been registered", name))
}
regCmds[name] = f
}
2014-07-25 07:55:56 +04:00
2014-07-25 11:18:39 +04:00
func lookup(name string) commandFunc {
2014-07-22 07:31:56 +04:00
return regCmds[strings.ToLower(name)]
2014-07-25 07:55:56 +04:00
2014-07-22 07:31:56 +04:00
}