package nats import ( "github.com/nats-io/nats.go" "uvok.de/go/training_fellow/registration" ) type NatsNotifier struct { ServerUrl string } func (notif *NatsNotifier) NotifyNewRegistration(reg *registration.Registration) error { conn, err := nats.Connect(notif.ServerUrl) if err != nil { return err } defer conn.Close() enc_conn, err := nats.NewEncodedConn(conn, nats.JSON_ENCODER) if err != nil { return err } defer enc_conn.Close() err = enc_conn.Publish(NATS_TOPIC_REGISTRATION_NEW, reg) if err != nil { return err } return nil }