-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIZincSearch.go
56 lines (49 loc) · 1.25 KB
/
APIZincSearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
//"encoding/json"
"fmt"
"io"
"log"
"net/http"
//"os"
//"strconv"
"strings"
//"encoding/csv"
)
// type Software struct {
// Name string
// Author string
// }
func main() {
//data := `[{"Name": "AutoCAD","Developer": "Autodesk"},{"Name": "Firefox","Developer": "Mozilla"},{"Name": "Chrome","Developer": "Google"}]`
data := `{
"Athlete": "DEMTSCHENKO, Albert",
"City": "Turin",
"Country": "RUS",
"Discipline": "Luge",
"Event": "Singles",
"Gender": "Men",
"Medal": "Silver",
"Season": "winter",
"Sport": "Luge",
"Year": 2006
}`
req, err := http.NewRequest("POST", "http://localhost:4080/api/games3/_doc", strings.NewReader(data))
if err != nil {
log.Fatal(err)
}
req.SetBasicAuth("admin", "Complexpass#123")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
log.Println(resp.StatusCode)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}