1234567891011121314151617181920212223242526272829303132333435 |
- package commands
- import (
- "fmt"
- "git.ali33.ru/fcg-xvii/rest"
- )
- var (
- store = make(map[string]func() rest.IExecuter)
- URLPresix = "api"
- )
- func Register(name string, cmd func() rest.IExecuter) {
- store[fmt.Sprintf("/%s/%s", URLPresix, name)] = cmd
- }
- func RegisterSection(section, name string, cmd func() rest.IExecuter) {
- store[fmt.Sprintf("/%s/%s/%s", URLPresix, section, name)] = cmd
- }
- func GetCommand(command string) (rest.IExecuter, bool) {
- if cmd, ok := store[command]; ok {
- return cmd(), true
- }
- return nil, false
- }
- func ListCommands() []string {
- commands := make([]string, len(store), 0)
- for name := range store {
- commands = append(commands, name)
- }
- return commands
- }
|