util

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hashedPassword string, plain string) error

Compares a password hash with a plain string. Returns nil on success, or an error on failure.

func HashPassword

func HashPassword(plain string) (string, error)

Returns the bcrypt hash of plain

func RandomNumber

func RandomNumber(min, max int64) int64

Return a random number between max and min

func RandomPassword

func RandomPassword() string

Generate a random password with length 20

func RandomString

func RandomString(n int, src string) string

Return a random string

func RandomUsername

func RandomUsername() string

Generate a random username with length 10

Types

type Config

type Config struct {
	DBConnString         string        `mapstructure:"DB_CONNSTRING"`
	DBMigrationFiles     string        `mapstructure:"DB_MIGRATION_FILES"`
	AppURL               string        `mapstructure:"APP_URL"`
	ListenAddr           string        `mapstructure:"LISTEN_ADDR"`
	ListenPort           string        `mapstructure:"LISTEN_PORT"`
	Environment          string        `mapstructure:"ENVIRONMENT"`
	SecretKey            string        `mapstructure:"SECRET_KEY"`
	AccessTokenDuration  time.Duration `mapstructure:"ACCESS_TOKEN_DURATION"`
	RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
	RedisAddress         string        `mapstructure:"REDIS_ADDRESS"`
	EmailSenderName      string        `mapstructure:"EMAIL_SENDER_NAME"`
	GmailSenderAddress   string        `mapstructure:"GMAIL_SENDER_ADDRESS"`
	GmailSenderPassword  string        `mapstructure:"GMAIL_SENDER_PASSWORD"`
	MailhogHost          string        `mapstructure:"MAILHOG_HOST"`
	MailhogSenderAddress string        `mapstructure:"MAILHOG_SENDER_ADDRESS"`
}

func LoadConfig

func LoadConfig(path string) (config Config, err error)

viper loads values etiher from app.env or from environment variables

type EmailSender

type EmailSender interface {
	SendEmail(subject string, content string, to []string, cc []string, bcc []string, attachFiles []string) error
}

func NewGmailSender

func NewGmailSender(senderName string, senderAddress string, senderPassword string) EmailSender

Creates a new Gmail sender

func NewLocalSender

func NewLocalSender(senderName string, senderAddress string, smtpServer string) EmailSender

Creates a new local email sender

type GmailSender

type GmailSender struct {
	// contains filtered or unexported fields
}

func (*GmailSender) SendEmail

func (g *GmailSender) SendEmail(subject string, content string, to []string, cc []string, bcc []string, attachFiles []string) error

Sends an email using a Gmail sender address

type LocalSender

type LocalSender struct {
	// contains filtered or unexported fields
}

func (*LocalSender) SendEmail

func (l *LocalSender) SendEmail(subject string, content string, to []string, cc []string, bcc []string, attachFiles []string) error

Sends and email using a local sender to an unauthenticated SMTP server such as MailHog.

Jump to

Keyboard shortcuts

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