data

package
v0.0.0-...-a39fdf8 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSizes = map[string]int{
	"small":    128,
	"medium":   256,
	"large":    512,
	"original": 1024,
}

DefaultSizes is the list of sizes

Functions

func CheckAvatarSize

func CheckAvatarSize(size string) string

CheckAvatarSize determines if the size is valid and returns the closest identifier if it is not valid

func ClearAvatarFiles

func ClearAvatarFiles(avatar Avatar) error

ClearAvatarFiles removes all unneeded files from S3

func ConvertToSize

func ConvertToSize(pixels int) string

ConvertToSize converts a pixel int to the corresponding size string.

func DefaultSizeKeys

func DefaultSizeKeys() []string

DefaultSizeKeys is the list of acceptable size strings

func GetFileExt

func GetFileExt(file io.ReadSeeker) (string, error)

GetFileExt gets the formatted extension of the supported image file

func GetUploadedFile

func GetUploadedFile(c *gin.Context) (io.ReadSeeker, string, error)

GetUploadedFile returns the file that was attempted to be uploaded

func LoadConfig

func LoadConfig(path string) error

LoadConfig loads external configuration file

func MinInt

func MinInt(x, y int) int

MinInt is a shim for determining the minimum for integers rather than floats

func Retry

func Retry(attempts int, callback func() error) (err error)

Retry allows you to retry commands more than once

func ValidAvatarSize

func ValidAvatarSize(size string) bool

ValidAvatarSize determines if the string is a valid identifier

Types

type AppError

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

AppError handles generic application errors

func (*AppError) Error

func (e *AppError) Error() string

type Application

type Application struct {
	DB    DB
	Debug bool
}

Application holds all the info for the app

type Avatar

type Avatar struct {
	Hash      string    `gorm:"type:varchar(40);not null;primary_key" json:"hash"` // hash identifier of the object
	Type      string    `gorm:"type:char(4);not null" json:"type"`                 // file extension of the avatar
	Sizes     Sizes     `gorm:"-" sql:"-" json:"sizes"`                            // list of available sizes
	CreatedAt time.Time `json:"createdAt"`                                         // when the avatar was first created
	UpdatedAt time.Time `json:"updatedAt"`                                         // last update of the avatar
}

Avatar stores the data for each object

var DefaultAvatar *Avatar

DefaultAvatar is the placeholder when no avatar can be found

func FindAvatar

func FindAvatar(db DB, hash string) *Avatar

FindAvatar searches the database for an avatar object given a hash string

func (Avatar) BestSize

func (a Avatar) BestSize(size string) string

BestSize determines the best size for the avatar, using the requested size as a reference.

func (Avatar) GetFilename

func (a Avatar) GetFilename(size string) string

GetFilename generates the file name of the object for a given size.

func (Avatar) GetPath

func (a Avatar) GetPath(size string) string

GetPath returns the path to the file object for a given size.

func (Avatar) GetURL

func (a Avatar) GetURL(size string, bucket string) string

GetURL gets the full URL of the avatar object for a given size, including the S3 bucket path.

func (*Avatar) Save

func (a *Avatar) Save(db DB) error

Save the avatar to the database

func (Avatar) TableName

func (Avatar) TableName() string

type AvatarPostgres

type AvatarPostgres struct {
	Avatar
	Sizes string `gorm:"column:sizes;type:text;not null" json:"-"` // list of available sizes
}

func (AvatarPostgres) TableName

func (AvatarPostgres) TableName() string

type DB

type DB interface {
	Connect() error
	FindByHash(string) (*Avatar, error)
	Save(*Avatar) error
	Migrate() error
}

type DynamoDB

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

DynamoDB wraps the dynamo DB library

func (*DynamoDB) Connect

func (d *DynamoDB) Connect() error

Connect begins the connection with the database

func (*DynamoDB) FindByHash

func (d *DynamoDB) FindByHash(hash string) (*Avatar, error)

func (*DynamoDB) Migrate

func (d *DynamoDB) Migrate() error

func (*DynamoDB) Save

func (d *DynamoDB) Save(a *Avatar) error

type FileData

type FileData map[string]string

FileData describes the file

func ProcessImageUpload

func ProcessImageUpload(app *Application, avatar Avatar, file io.ReadSeeker) (FileData, error)

ProcessImageUpload processes uploaded images into the appropriate size

type PostgresDB

type PostgresDB struct {
	Gorm *gorm.DB
}

PostgresDB wraps the gorm DB interface

func (*PostgresDB) Connect

func (p *PostgresDB) Connect() error

Connect begins the connection with the database

func (*PostgresDB) FindByHash

func (p *PostgresDB) FindByHash(hash string) (*Avatar, error)

func (*PostgresDB) Migrate

func (p *PostgresDB) Migrate() error

func (*PostgresDB) Save

func (p *PostgresDB) Save(a *Avatar) error

type Sizes

type Sizes []string

Sizes is the available sizes for an avatar object.

Jump to

Keyboard shortcuts

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