Exemplo n.º 1
0
func (logger *logger) Start() error {
	logger.started = time.Now()
	if logger.Formatter == nil {
		return fmt.Errorf("Formatter must be set")
	}
	logger.pubSub = pubsub.New()
	RegisterPubSub(logger.pubSub)
	logger.subscription = logger.pubSub.Subscribe(func(m *Message) {
		if message := logger.Formatter(m); message != "" {
			fmt.Fprintln(logger.Output, message)
		}
	})
	return nil
}
Exemplo n.º 2
0
func main() {
	ps := pubsub.New()
	stringSubscription := ps.Subscribe(func(m string) {
		log.Printf("got string %q", m)
	})
	defer stringSubscription.Close()

	userSubscription := ps.Subscribe(func(u *User) {
		log.Printf("got user %+v", u)
	})
	defer userSubscription.Close()

	ps.Publish("hello")
	ps.Publish("world")

	ps.Publish(&User{name: "Hans"})
	ps.Publish(&User{name: "Meyer"})
}