New to Go – Quick Debug Question

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/boqked/new_to_go_quick_debug_question/ by 

I’m trying to use the ring queue (here)[github.com/eapache/queue] in my web scraping project. Multiple crawlers will need to import this queuing system, so I want an outward facing Add() function that adds the site to the queue. I mostly have it down, however, the queue contents print twice and I don’t know why. My queue.go file is the main logic, while the test.go file adds some test sites to the queue. Here’s what both look like:

queue.go:

package queue 

import ( “fmt” “github.com/eapache/queue” )

var Queue = queue.New() var Input string = “”

func Main() { for {

} 

}

func Add(site string) { Queue.Add(site) fmt.Println(Queue.Peek()) Queue.Remove() }

test.go:

package test 

import ( “time” “crawler/modules/queue” )

func Main() { queue.Add(“https://reddit.com”) queue.Add(“https://www.google.com”) time.Sleep(2000 * time.Millisecond) queue.Add(“https://twitter.com”) }

Thanks!

submitted by /u/bmw417
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply