Documentation ¶
Index ¶
- Variables
- func CheckAvatarSize(size string) string
- func ClearAvatarFiles(avatar Avatar) error
- func ConvertToSize(pixels int) string
- func DefaultSizeKeys() []string
- func GetFileExt(file io.ReadSeeker) (string, error)
- func GetUploadedFile(c *gin.Context) (io.ReadSeeker, string, error)
- func LoadConfig(path string) error
- func MinInt(x, y int) int
- func Retry(attempts int, callback func() error) (err error)
- func ValidAvatarSize(size string) bool
- type AppError
- type Application
- type Avatar
- type AvatarPostgres
- type DB
- type DynamoDB
- type FileData
- type PostgresDB
- type Sizes
Constants ¶
This section is empty.
Variables ¶
var DefaultSizes = map[string]int{
"small": 128,
"medium": 256,
"large": 512,
"original": 1024,
}
DefaultSizes is the list of sizes
Functions ¶
func CheckAvatarSize ¶
CheckAvatarSize determines if the size is valid and returns the closest identifier if it is not valid
func ClearAvatarFiles ¶
ClearAvatarFiles removes all unneeded files from S3
func ConvertToSize ¶
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 ¶
GetUploadedFile returns the file that was attempted to be uploaded
func ValidAvatarSize ¶
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
type Application ¶
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 ¶
FindAvatar searches the database for an avatar object given a hash string
func (Avatar) BestSize ¶
BestSize determines the best size for the avatar, using the requested size as a reference.
func (Avatar) GetFilename ¶
GetFilename generates the file name of the object for a given size.
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 DynamoDB ¶
type DynamoDB struct {
// contains filtered or unexported fields
}
DynamoDB wraps the dynamo DB library
type FileData ¶
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 ¶
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