示例#1
0
文件: esbeat.go 项目: lth2015/esbeat
func rander() {
	book.ID = next()
	book.Name = myrand.GenerateRandomStr(STRING_SIZE)
	book.Author = myrand.GenerateRandomStr(STRING_SIZE)
	book.ISBN = myrand.GenerateRandomStr(STRING_SIZE)
	book.Arrival = mytime.Date()
	book.OnBoard = mytime.TimeStamp()
	// log.Printf("book:> ID=%u, Name=%s, Author=%s, ISBN=%s, Date=%s, OnBoard=%s",
	// book.ID, book.Name, book.Author, book.ISBN, book.Arrival, book.OnBoard)
}
示例#2
0
文件: http.go 项目: lth2015/esbeat
func Post() {
	url := "http://usa1:9200/books/book/c"
	fmt.Println("URL:> ", url)
	h := &http.Header{}
	h.Set("Content-Type", "application/json")

	b := mytypes.Book{
		Name:    "C",
		Author:  "litanhua",
		ISBN:    "ISBN-12342-123-32",
		Arrival: mytime.Date(),
		OnBoard: mytime.TimeStamp(),
	}

	j, err := json.Marshal(&b)
	if err != nil {
		log.Fatal("Error: ", err)
		return
	}

	fmt.Println(string(j))

	resp, err := http.Post(url, "/books/book/c", strings.NewReader(string(j)))
	if err != nil {
		log.Fatal("Error: ", err)
		return
	}

	result, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()

	if err != nil {
		log.Fatal("Error: ", err)
		return
	}

	fmt.Println(string(result))

}