Пример #1
0
func main() {
	flag.Parse()

	if len(ignoreChannels) > 0 {
		common.SetIgnores(ignoreChannels)
	}

	if len(flag.Args()) != 1 {
		log.Fatalf("provide the zmq_notify publisher! like tcp://example.com:2428")
	}

	subscriber, err := NewSubscriber(flag.Args()[0])
	if err != nil {
		log.Fatalf("ERROR: %s", err)
	}
	if err = subscriber.Connect(); err != nil {
		log.Fatalf("ERROR: %s", err)
	}
	if !quiet {
		log.Printf("Connected to [%s]", flag.Args()[0])
	}
	if err = subscriber.SetSubscribe(""); err != nil {
		log.Fatalf("ERROR: %s", err)
	}

	for {
		msg, err := subscriber.RecvMessageBytes(0)
		if err != nil {
			log.Fatalf("ERROR: %s", err)
			break
		}
		noti_msg := common.IrcNotify{}
		json.Unmarshal(msg[0], &noti_msg)
		go common.Display(noti_msg, linger, quiet)
	}
}
Пример #2
0
func main() {
	flag.Parse()

	if len(ignoreChannels) > 0 {
		common.SetIgnores(ignoreChannels)
	}

	var (
		bs  *beanstalk.Conn
		err error
	)

	if len(flag.Args()) >= 1 {
		bs, err = beanstalk.Dial("tcp", flag.Args()[0])

		if err != nil {
			log.Fatal(err)
		}

		if !quiet {
			log.Printf("Connected to [%s]", flag.Args()[0])
		}

		if len(flag.Args()) >= 2 {
			bs.Tube.Name = flag.Args()[1]
		}
	} else {
		log.Fatalf("provide the beanstalk publisher! like example.com:11300")
	}

	//Clear out the old messages before we start back up
	for {
		id, msg, err := bs.Reserve(5 * time.Second)

		if !quiet {
			noti_msg := common.IrcNotify{}
			json.Unmarshal(msg, &noti_msg)

			log.Printf("removing old message [%s]", noti_msg.Message)
		}

		if err != nil {
			break
		}

		err = bs.Delete(id)

		if err != nil {
			log.Fatal(err)
		}
	}

	for {
		id, msg, err := bs.Reserve(5 * time.Second)

		if err == nil {
			noti_msg := common.IrcNotify{}
			json.Unmarshal(msg, &noti_msg)

			go common.Display(noti_msg, linger, quiet)

			err = bs.Delete(id)

			if err != nil {
				log.Fatal(err)
			}
		}

		time.Sleep(500 * time.Millisecond)
	}
}