Exemplo n.º 1
0
func main() {
	configData, _ := ioutil.ReadFile("./config.json")
	fmt.Println(string(configData))
	configJson, _ := simplejson.NewJson(configData)
	conn, err := amqp.Dial(configJson.Get("conn").MustString())
	file := configJson.Get("file").MustString()
	exchange := configJson.Get("exchange").MustString()
	routekey := configJson.Get("routekey").MustString()
	interval := configJson.Get("sendInterval").MustInt64()

	failOnError(err, "Failed to connect to RabbitMQ")
	defer conn.Close()

	ch, err := conn.Channel()
	failOnError(err, "Failed to open a channel")
	defer ch.Close()

	//q, err := ch.QueueDeclare(
	//	queue, // name
	//	true, // durable
	//	false, // delete when unused
	//	false, // exclusive
	//	false, // no-wait
	//	nil, // arguments
	//)
	//q, err := ch.QueueDeclare(
	//	"queue.paidorder", // name
	//	true, // durable
	//	false, // delete when unused
	//	false, // exclusive
	//	false, // no-wait
	//	nil, // arguments
	//)
	failOnError(err, "Failed to declare a queue")

	ReadLine(file, func(line []byte) {
		if string(line) == "" {
			return
		}
		err = ch.Publish(
			exchange, // exchange
			routekey, // routing key
			false,    // mandatory
			false,    // immediate
			amqp.Publishing{
				ContentType: "text/plain",
				Body:        line,
			})
		log.Printf(" [x] Sent %s", line)
		failOnError(err, "Failed to publish a message")
		// 1000/num 条/秒
		time.Sleep(time.Millisecond * time.Duration(interval))
	})

}
Exemplo n.º 2
0
func readHeaderFromFile(headerFile string) http.Header {
	//read file , parse the header and cookies
	b, err := ioutil.ReadFile(headerFile)
	if err != nil {
		//make be:  share access error
		log.Println(err.Error())
		return nil
	}
	js, _ := simplejson.NewJson(b)
	//constructed to header

	h := make(http.Header)
	h.Add("User-Agent", js.Get("User-Agent").MustString())
	h.Add("Referer", js.Get("Referer").MustString())
	h.Add("Cookie", js.Get("Cookie").MustString())
	h.Add("Cache-Control", "max-age=0")
	h.Add("Connection", "keep-alive")
	return h
}
Exemplo n.º 3
0
func main() {
	c, err := redis.Dial("tcp", "10.100.51.125:6379")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer c.Close()

	n, err := redis.StringMap(c.Do("HGETALL", "yes_dsp"))
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, value := range n {
		js, err := json.NewJson([]byte(value))
		if err != nil {
			fmt.Println(err)
			continue
		}
		bidurl, err := js.Get("bidURL").String()
		if err != nil {
			fmt.Println(err)
			continue
		}
		purl, err := url.Parse(bidurl)
		if err != nil {
			fmt.Println(err)
			continue
		}
		prefix := purl.Host[0]
		if prefix == '1' || prefix == '2' || prefix == '3' || prefix == '4' || prefix == '5' || prefix == '6' || prefix == '7' || prefix == '8' || prefix == '9' || prefix == '0' {
			continue
		}
		hosts := strings.Split(purl.Host, ":")
		/*if len(hosts) > 1 {
			fmt.Println(hosts[1])
		}*/
		fmt.Println(hosts[0])
	}
}