common

package
v0.0.0-...-fce496f Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasterDBName = "postgres"
)

Variables

View Source
var (
	ErrDatabaseNameIsEmpty = merry.New("database name should be specified")
)

Functions

func CleanPublicURL

func CleanPublicURL(url string) string

func CreateDatabaseIfNotExist

func CreateDatabaseIfNotExist(cfg DatabaseConfig) error

func CurrentTimestamp

func CurrentTimestamp() time.Time

func DecodeImageAndFixOrientation

func DecodeImageAndFixOrientation(reader io.Reader, orientation string) (image.Image, error)

func GenerateRSAKey

func GenerateRSAKey() ([]byte, error)

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func GenerateUUID

func GenerateUUID() string

func GetImageOrientation

func GetImageOrientation(reader io.Reader) string

func LoadRSAKey

func LoadRSAKey(settingRepo SettingRepo, keyPath string) (string, error)

func NullTimeToRPCString

func NullTimeToRPCString(t sql.NullTime) string

func OpenDatabase

func OpenDatabase(cfg DatabaseConfig, migrations ...func(db *sqlx.DB, dialect string) (n int, err error)) (db *sqlx.DB, migrationsCount int, err error)

func ParseTemplates

func ParseTemplates(templatesDir embed.FS, rootDir string) (*template.Template, error)

func RPCStringToTime

func RPCStringToTime(s string) (time.Time, error)

func RSAKeysFromPrivateKeyContent

func RSAKeysFromPrivateKeyContent(privateKeyContent string) (privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey, publicKeyPEM []byte, err error)

func RunInTransaction

func RunInTransaction(db *sqlx.DB, action func(tx *sqlx.Tx) error) error

func TimeToRPCString

func TimeToRPCString(t time.Time) string

func VideoThumbnail

func VideoThumbnail(videoPath string) ([]byte, error)

Types

type Container

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

func CurrentContainer

func CurrentContainer(ctx context.Context) (*Container, error)

func (Container) ID

func (c Container) ID() string

func (Container) ImageCreated

func (c Container) ImageCreated() string

type DatabaseConfig

type DatabaseConfig struct {
	Host     string `yaml:"host" required:"true" env:"KOTO_DB_HOST"`
	Port     int    `yaml:"port" default:"5432" env:"KOTO_DB_PORT"`
	SSLMode  string `yaml:"ssl_mode" env:"KOTO_DB_SSL_MODE"`
	DBName   string `yaml:"db_name" required:"true" env:"KOTO_DB_NAME"`
	User     string `yaml:"user" required:"true" env:"KOTO_DB_USER"`
	Password string `yaml:"password" required:"true" env:"KOTO_DB_PASSWORD"`
}

func (DatabaseConfig) ConnectionString

func (cfg DatabaseConfig) ConnectionString() string

type MailAttachment

type MailAttachment struct {
	Inline   bool
	Data     []byte
	FileName string
	MIMEType string
}

func (MailAttachment) InlineHTML

func (ma MailAttachment) InlineHTML() string

type MailAttachmentList

type MailAttachmentList map[string]MailAttachment

func (MailAttachmentList) InlineHTML

func (ma MailAttachmentList) InlineHTML(key string) string

type MailSender

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

func NewMailSender

func NewMailSender(cfg SMTPConfig) *MailSender

func (*MailSender) Enabled

func (m *MailSender) Enabled() bool

func (*MailSender) SendHTMLEmail

func (m *MailSender) SendHTMLEmail(recipients []string, subject string, message string, attachments MailAttachmentList) error

func (*MailSender) SendTextEmail

func (m *MailSender) SendTextEmail(recipients []string, subject string, message string) error

type Notification

type Notification struct {
	ID        string         `db:"id"`
	UserID    string         `db:"user_id"`
	Text      string         `db:"text"`
	Type      string         `db:"type"`
	Data      types.JSONText `db:"data"`
	CreatedAt time.Time      `db:"created_at"`
	ReadAt    sql.NullTime   `db:"read_at"`
}

type NotificationRepo

type NotificationRepo interface {
	AddNotifications(userIDs []string, text, notificationType string, data map[string]interface{}) error
	Counts(userID string) (total int, unread int, err error)
	Notifications(userID string) ([]Notification, error)
	Clean(userID string, lastKnownID string) error
	MarkRead(userID string, lastKnownID string) error
	DeleteUserNotifications(tx *sqlx.Tx, userID string) error
}

func NewNotifications

func NewNotifications(db *sqlx.DB) NotificationRepo

type S3Cleaner

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

func NewS3Cleaner

func NewS3Cleaner(db *sqlx.DB, s3Storage *S3Storage) *S3Cleaner

func (*S3Cleaner) Clean

func (c *S3Cleaner) Clean(ctx context.Context)

type S3Config

type S3Config struct {
	Endpoint         string `yaml:"endpoint" required:"true" env:"KOTO_S3_ENDPOINT"`
	ExternalEndpoint string `yaml:"external_endpoint" required:"false" env:"KOTO_S3_EXTERNAL_ENDPOINT"`
	Region           string `yaml:"region" env:"KOTO_S3_REGION"`
	Key              string `yaml:"key" required:"true" env:"KOTO_S3_KEY"`
	Secret           string `yaml:"secret" required:"true" env:"KOTO_S3_SECRET"`
	Bucket           string `yaml:"bucket" required:"true" env:"KOTO_S3_BUCKET"`
}

func (S3Config) CreateStorage

func (cfg S3Config) CreateStorage() (*S3Storage, error)

type S3Storage

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

func NewS3Storage

func NewS3Storage(client, externalClient *minio.Client, externalPathPrefix, bucket string) *S3Storage
func (s *S3Storage) CreateLink(ctx context.Context, blobID string, expiration time.Duration) (string, error)
func (s *S3Storage) CreateUploadLink(ctx context.Context, blobID, contentType string, metadata map[string]string) (uploadLink string, formData map[string]string, err error)

func (*S3Storage) Exists

func (s *S3Storage) Exists(ctx context.Context, blobID string) (bool, error)

func (*S3Storage) PutObject

func (s *S3Storage) PutObject(ctx context.Context, blobID string, content []byte, contentType string) error

func (*S3Storage) Read

func (s *S3Storage) Read(ctx context.Context, blobID string, w io.Writer) error

func (*S3Storage) ReadN

func (s *S3Storage) ReadN(ctx context.Context, blobID string, n int) ([]byte, error)

func (*S3Storage) RemoveObject

func (s *S3Storage) RemoveObject(ctx context.Context, blobID string) error

type SMTPConfig

type SMTPConfig struct {
	Host     string `yaml:"host" env:"KOTO_SMTP_HOST"`
	Port     int    `yaml:"port" default:"587" env:"KOTO_SMTP_PORT"`
	User     string `yaml:"user" env:"KOTO_SMTP_USER"`
	Password string `yaml:"password"  env:"KOTO_SMTP_PASSWORD"`
	From     string `yaml:"from"  env:"KOTO_SMTP_FROM"`
}

type Setting

type Setting struct {
	ID    string `db:"id"`
	Value string `db:"value"`
}

type SettingRepo

type SettingRepo interface {
	Get(id string) (string, bool, error)
	Add(id, value string) error
}

func NewSettings

func NewSettings(db *sqlx.DB) SettingRepo

Jump to

Keyboard shortcuts

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