notification

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 6 Imported by: 2

README

gFly Notification - Mail

Copyright © 2023, gFly
https://www.gFly.dev
All rights reserved.
Usage

Install

go get -u github.com/gflydev/notification@v1.0.0
go get -u github.com/gflydev/notification/mail@v1.0.1

Quick usage main.go

import (
    notificationMail "github.com/gflydev/notification/mail"
    "github.com/gflydev/notification"
)

notificationMail.AutoRegister()

Notification file

type ResetPassword struct {
}

func (n ResetPassword) ToEmail() notifyMail.Data {
    return notifyMail.Data{
        To:      "vinh@jivecode.com",
        Subject: "Mail title",
        Body:    "Mail body",
    }
}

resetPassword := ResetPassword{}
if err := notification.Send(resetPassword); err != nil {
    log.Error(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(handler fnHandler, interfacePtr any)

Register adds a notification handler factory function to the handlerFactory slice. The handler function creates an INotifiable implementation for a specific notification type. This allows registering different notification channels (Mail, SMS, Slack, etc.). The interfacePtr should be a pointer to an interface (e.g., (*IMailNotification)(nil))

func Send

func Send(notification any) error

Send delivers notifications concurrently through multiple notification handlers (SMS|Mail|Slack|Database). It takes a notification object of any type and sends it through all registered handlers that implement the corresponding notification interfaces. If notifications are disabled via NOTIFICATION_ENABLE env var, it will skip sending and return nil. Returns error.NotImplemented if no valid handlers are found.

Parameters:

  • notification: Any object implementing notification interfaces for registered handlers To send Mail. For example, a struct implementing IMailNotification interface for mail notifications. To send SMS. For example, a struct implementing ISmsNotification interface for sms notifications. To send Slack. For example, a struct implementing ISlackNotification interface for Slack notifications. To send Database. For example, a struct implementing IDatabaseNotification interface for database notifications.

Returns:

  • error: error.NotImplemented if no handlers match, nil on success or disabled notifications

Types

type INotifiable

type INotifiable interface {
	// Notify sends the actual notification through the specific channel
	Notify()
}

INotifiable is the interface that defines a notification that can be sent through different channels like Mail, SMS, Slack, etc. Each notification handler must implement this interface.

Directories

Path Synopsis
mail module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL