store.go 698 B

1234567891011121314151617181920212223242526272829303132333435
  1. package commands
  2. import (
  3. "fmt"
  4. "git.ali33.ru/fcg-xvii/rest"
  5. )
  6. var (
  7. store = make(map[string]func() rest.IExecuter)
  8. URLPresix = "api"
  9. )
  10. func Register(name string, cmd func() rest.IExecuter) {
  11. store[fmt.Sprintf("/%s/%s", URLPresix, name)] = cmd
  12. }
  13. func RegisterSection(section, name string, cmd func() rest.IExecuter) {
  14. store[fmt.Sprintf("/%s/%s/%s", URLPresix, section, name)] = cmd
  15. }
  16. func GetCommand(command string) (rest.IExecuter, bool) {
  17. if cmd, ok := store[command]; ok {
  18. return cmd(), true
  19. }
  20. return nil, false
  21. }
  22. func ListCommands() []string {
  23. commands := make([]string, len(store), 0)
  24. for name := range store {
  25. commands = append(commands, name)
  26. }
  27. return commands
  28. }