示例#1
0
//curl -XDELETE 'http://localhost:9200/twitter/tweet/1'
func (c *DocCmd) Delete(d backend.Resource) (string, bool) {
	u := new(url.URL)
	u.Scheme = d.Scheme
	u.Host = d.Host + ":" + d.Port
	u.Path = d.Index + "/" + d.Type + "/" + d.Id
	q := u.Query()
	q.Add("pretty", "true")
	u.RawQuery = q.Encode()

	//urlString = fmt.Sprintf("http://%s:%s/%s/%s/%s", backend.Server.Host, backend.Server.Port, indexName, typeName, id)
	fmt.Println("Request:", u)
	res, err := backend.DeleteHttpResource(u.String())
	if err != nil {
		return err.Error(), false
	}
	return res, true
}
示例#2
0
func (c *IndexCmd) Delete(d backend.Resource) (string, bool) {
	//curl -XDELETE "http://localhost:9200/indexname/"
	u := new(url.URL)
	u.Scheme = d.Scheme
	u.Host = d.Host + ":" + d.Port
	u.Path = d.Index
	q := u.Query()
	q.Add("pretty", "true")
	u.RawQuery = q.Encode()
	fmt.Println("Request:", u)
	err := errors.New("")
	res, err := backend.DeleteHttpResource(u.String())
	if err != nil {
		return err.Error(), false
	}
	return res, true
}
示例#3
0
func init() {
	h := backend.NewHandler()
	h.CommandName = "delete"
	h.CommandPattern = "(delete)( )(.*)"
	// TODO: usage
	h.HandlerFunc = func(cmd *backend.Command) (string, bool) {
		//arg := cmd.Args[0]
		arg := strings.SplitN(cmd.Instruction, " ", 2)[1]
		u := new(url.URL)
		newUrl, err := u.Parse(arg)
		if err != nil {
			return "Unable to parse url: " + err.Error(), false
		}
		fmt.Println("Request:", newUrl)
		res, err := backend.DeleteHttpResource(newUrl.String())
		if err != nil {
			return err.Error(), false
		}
		return res, true
	}
	backend.HandlerRegistry[h.CommandName] = h
}