optimize project structure

This commit is contained in:
hdt3213
2021-11-08 23:05:53 +08:00
parent 3c5a44b7c0
commit 4163a45278
34 changed files with 82 additions and 56 deletions

28
database/router.go Normal file
View File

@@ -0,0 +1,28 @@
package database
import (
"strings"
)
var cmdTable = make(map[string]*command)
type command struct {
executor ExecFunc
prepare PreFunc // return related keys command
undo UndoFunc
arity int // allow number of args, arity < 0 means len(args) >= -arity
flags int
}
// RegisterCommand registers a new command
// arity means allowed number of cmdArgs, arity < 0 means len(args) >= -arity.
// for example: the arity of `get` is 2, `mget` is -2
func RegisterCommand(name string, executor ExecFunc, prepare PreFunc, rollback UndoFunc, arity int) {
name = strings.ToLower(name)
cmdTable[name] = &command{
executor: executor,
prepare: prepare,
undo: rollback,
arity: arity,
}
}