Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dial tcp 127.0.0.1:9200: connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted. #712

Open
RoRui opened this issue Aug 16, 2023 · 0 comments

Comments

@RoRui
Copy link

RoRui commented Aug 16, 2023

window10

func New() *elasticsearch.Client {
   cfg := elasticsearch.Config{
   	Addresses: []string{
   		"https://127.0.0.1:9200",
   	},
   	Username:               "elastic",
   	Password:               "aaaaaaaa",
   	CertificateFingerprint: "aaaaaaa",
   }
   es, err := elasticsearch.NewClient(cfg)
   if err != nil {
   	log.Fatal(err)
   }
   return es
}

var es = conn.New()
func SaveUrl(r *colly.Response) {
   doc := UrlDoc{}
   doc._id = utils.GetMD5Encode(r.Request.URL.String())
   doc.Url = r.Request.URL.String()
   doc.Code = r.StatusCode
   data, _ := json.Marshal(doc)
   rp, err := es.Index("collected_urls", bytes.NewReader(data), es.Index.WithDocumentID(doc._id))
   if err != nil {
   	log.Fatal(err)
   }
   log.Println(rp.String())	
   defer func(Body io.ReadCloser) {
   	err := Body.Close()
   	if err != nil {
   		log.Fatal(err)
   	}
   }(rp.Body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant