common

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastAddr

func BroadcastAddr(n *net.IPNet) net.IP

BroadcastAddr returns the last address in the given network, or the broadcast address.

func FormatDateHTML added in v1.0.16

func FormatDateHTML(t *time.Time) string

func GetDatabaseForConfig added in v1.0.4

func GetDatabaseForConfig(cfg *DatabaseConfig) (db *gorm.DB, err error)

func IsIPv6

func IsIPv6(address string) bool

IsIPv6 check if given ip is IPv6

func ListContains added in v1.0.4

func ListContains(lst []string, needle string) bool

ListContains checks if a needle exists in the given list.

func ListToString

func ListToString(lst []string) string

ListToString converts a list of strings into a comma separated string.

func MigrateDatabase added in v1.0.5

func MigrateDatabase(db *gorm.DB, version string) error

func ParseStringList

func ParseStringList(lst string) []string

ParseStringList converts a comma separated string into a list of strings. It also trims spaces from each element of the list.

func SendEmailWithAttachments

func SendEmailWithAttachments(cfg MailConfig, sender, replyTo, subject, body, htmlBody string, receivers []string, attachments []MailAttachment) error

SendEmailWithAttachments sends a mail with optional attachments.

Types

type DatabaseConfig added in v1.0.4

type DatabaseConfig struct {
	Typ      SupportedDatabase `yaml:"typ" envconfig:"DATABASE_TYPE"` //mysql or sqlite
	Host     string            `yaml:"host" envconfig:"DATABASE_HOST"`
	Port     int               `yaml:"port" envconfig:"DATABASE_PORT"`
	Database string            `yaml:"database" envconfig:"DATABASE_NAME"` // On SQLite: the database file-path, otherwise the database name
	User     string            `yaml:"user" envconfig:"DATABASE_USERNAME"`
	Password string            `yaml:"password" envconfig:"DATABASE_PASSWORD"`
}

type DatabaseMigrationInfo added in v1.0.5

type DatabaseMigrationInfo struct {
	Version string `gorm:"primaryKey"`
	Applied time.Time
}

type MailAttachment

type MailAttachment struct {
	Name        string
	ContentType string
	Data        io.Reader
	Embedded    bool
}

type MailAuthType added in v1.0.8

type MailAuthType string
const (
	MailAuthPlain   MailAuthType = "plain"
	MailAuthLogin   MailAuthType = "login"
	MailAuthCramMD5 MailAuthType = "crammd5"
)

type MailConfig

type MailConfig struct {
	Host           string         `yaml:"host" envconfig:"EMAIL_HOST"`
	Port           int            `yaml:"port" envconfig:"EMAIL_PORT"`
	TLS            bool           `yaml:"tls" envconfig:"EMAIL_TLS"` // Deprecated, use MailConfig.Encryption instead.
	Encryption     MailEncryption `yaml:"encryption" envconfig:"EMAIL_ENCRYPTION"`
	CertValidation bool           `yaml:"certcheck" envconfig:"EMAIL_CERT_VALIDATION"`
	Username       string         `yaml:"user" envconfig:"EMAIL_USERNAME"`
	Password       string         `yaml:"pass" envconfig:"EMAIL_PASSWORD"`
	AuthType       MailAuthType   `yaml:"auth" envconfig:"EMAIL_AUTHTYPE"`
}

type MailEncryption added in v1.0.8

type MailEncryption string
const (
	MailEncryptionNone     MailEncryption = "none"
	MailEncryptionTLS      MailEncryption = "tls"
	MailEncryptionStartTLS MailEncryption = "starttls"
)

type Migration added in v1.0.8

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

type SupportedDatabase added in v1.0.4

type SupportedDatabase string
const (
	SupportedDatabaseMySQL  SupportedDatabase = "mysql"
	SupportedDatabaseSQLite SupportedDatabase = "sqlite"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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