Пример #1
0
func init() {
	h := backend.NewHandler()
	h.CommandName = "run"
	h.CommandPattern = "(run)( )(.*)"
	h.Usage = "run"
	h.HandlerFunc = func(cmd *backend.Command) (string, bool) {
		verb := strings.ToLower(cmd.Tokens[0])
		cmdParser := backend.NewCommandParser()
		newCmd, err := cmdParser.Parse(backend.LoadedRequest.Request)
		if err != nil {
			return "Unable to parse loaded query for run command.", false
		}
		dispatcher := backend.NewDispatcher()
		switch verb {
		case "post":
			resp, ok := dispatcher.Dispatch(newCmd)
			return resp, ok
		case "put":
			resp, ok := dispatcher.Dispatch(newCmd)
			return resp, ok
		case "get":
			resp, ok := dispatcher.Dispatch(newCmd)
			return resp, ok
		}
		return "Unable to run loaded query.", false
	}
	backend.HandlerRegistry[h.CommandName] = h
}
Пример #2
0
func reploop() {
	commandParser := backend.NewCommandParser()
	dispatcher := backend.NewDispatcher()
	for {
		fmt.Print("> ")
		in := bufio.NewReader(os.Stdin)
		entered, err := in.ReadString('\n')
		if err != nil {
			fmt.Println(err)
			break
		}
		entry := strings.Trim(entered, "\t \r\n")
		if backend.LogLevel > 0 {
			log(entry, backend.LogLevel)
		}
		command, err := commandParser.Parse(entry)
		if err != nil {
			fmt.Println("Unable to parse command.")
		}
		output, ok := dispatcher.Dispatch(command)
		if len(output) > 0 {
			if !ok {
				fmt.Println(usageMessage(output))
			} else {
				fmt.Println(output)
			}
			fmt.Println("")
		}
	}
}
Пример #3
0
func (c *DocCmd) Get(d backend.Resource) (string, bool) {
	postData := "{\"ids\": " + d.Id + " }"
	urlString := "post " + d.Host + " " + d.Port + " " + d.Index + "/" + d.Endpoint + " " + postData
	fmt.Println("...>>", urlString)

	cmdParser := backend.NewCommandParser()
	newCmd, err := cmdParser.Parse(urlString)
	if err != nil {
		return err.Error(), false
	}
	dispatcher := backend.NewDispatcher()
	res, ok := dispatcher.Dispatch(newCmd)
	return res, ok
}
Пример #4
0
func (c *AliasCmd) Move(dFrom backend.Resource, dTarget backend.Resource) (string, bool) {
	if dFrom.Host == "" || dFrom.Port == "" {
		return "Missing host or port.", false
	}
	postData := "{ \"actions\": [ { \"remove\": { \"alias\": \"" + dFrom.Alias + "\", \"index\": \"" + dFrom.Index + "\" }}, { \"add\": { \"alias\": \"" + dTarget.Alias + "\", \"index\": \"" + dTarget.Index + "\" } } ] }"
	urlString := "post " + dFrom.Host + " " + dFrom.Port + " " + dFrom.Endpoint + " " + postData
	cmdParser := backend.NewCommandParser()
	newCmd, err := cmdParser.Parse(urlString)
	if err != nil {
		return err.Error(), false
	}
	dispatcher := backend.NewDispatcher()
	res, ok := dispatcher.Dispatch(newCmd)
	return res, ok
}