ollie/cmd/olliesrv/internal/fs/ctl.go

22 lines
464 B
Go

package fs
import (
"fmt"
"strings"
)
// dispatch routes a command to the matching handler based on the first word.
func dispatch(handlers map[string]func([]string) ([]byte, error), data []byte) ([]byte, error) {
input := strings.TrimSpace(string(data))
if input == "" {
return nil, nil
}
parts := strings.Fields(input)
cmd := parts[0]
h, ok := handlers[cmd]
if !ok {
return nil, fmt.Errorf("unknown ctl command: %s", cmd)
}
return h(parts[1:])
}