package borealis import ( "fmt" "github.com/nats-io/nats.go" ) type Bus struct { NATS *nats.EncodedConn } func Connect(url string) (*Bus, error) { conn, err := nats.Connect(url) if err != nil { return nil, fmt.Errorf("failed to connect to the broker: %w", err) } encodedConn, err := nats.NewEncodedConn(conn, nats.JSON_ENCODER) // TODO if err != nil { return nil, fmt.Errorf("failed to configure the bus encoding: %w", err) } return &Bus{NATS: encodedConn}, nil } func (bus *Bus) SendEmail(request *SendEmail) error { envelope := request // TODO if err := bus.NATS.Publish("email.outbound", envelope); err != nil { return fmt.Errorf("failed to enqueue outbound email: %w", err) } return nil } func (bus *Bus) RegisterID(request *RegisterID) error { envelope := request // TODO if err := bus.NATS.Publish("id.register", envelope); err != nil { return fmt.Errorf("failed to enqueue ID registration: %w", err) } return nil } func (bus *Bus) VerifyEmail(request *VerifyEmail) error { envelope := request // TODO if err := bus.NATS.Publish("id.verify", envelope); err != nil { return fmt.Errorf("failed to enqueue ID verification: %w", err) } return nil } func (bus *Bus) GrantAccess(request *GrantAccess) error { envelope := request // TODO if err := bus.NATS.Publish("access.grant", envelope); err != nil { return fmt.Errorf("failed to enqueue access grant: %w", err) } return nil } func (bus *Bus) RevokeAccess(request *RevokeAccess) error { envelope := request // TODO if err := bus.NATS.Publish("access.revoke", envelope); err != nil { return fmt.Errorf("failed to enqueue access revocation: %w", err) } return nil }