domain

package
v1.0.1-0...-32d7d0a Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogDisabled int = iota
	LogDebug
	LogInfo
	LogError
	LogCritical
)

Variables

View Source
var (
	ErrTooManyRequests = &domainError{
		outerError: outerError{
			StatusCode: http.StatusTooManyRequests,
			AppCode:    0x1,
			UserMsg:    "too many requests",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "too many requests",
		},
	}
	ErrBodyTooLarge = &domainError{
		outerError: outerError{
			StatusCode: http.StatusRequestEntityTooLarge,
			AppCode:    0x2,
			UserMsg:    "body too large",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "body too large",
		},
	}
	ErrWrongContentType = &domainError{
		outerError: outerError{
			StatusCode: http.StatusUnsupportedMediaType,
			AppCode:    0x3,
			UserMsg:    "unsupported media type",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "wrong content type",
		},
	}
	ErrNotEnoughImages = &domainError{
		outerError: outerError{
			StatusCode: http.StatusBadRequest,
			AppCode:    0x4,
			UserMsg:    "not enough images",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "not enough images",
		},
	}
	ErrTooManyImages = &domainError{
		outerError: outerError{
			StatusCode: http.StatusRequestEntityTooLarge,
			AppCode:    0x5,
			UserMsg:    "too many images",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "too many images",
		},
	}
	ErrImageTooLarge = &domainError{
		outerError: outerError{
			StatusCode: http.StatusRequestEntityTooLarge,
			AppCode:    0x6,
			UserMsg:    "image too large",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "image too large",
		},
	}
	ErrNotImage = &domainError{
		outerError: outerError{
			StatusCode: http.StatusUnsupportedMediaType,
			AppCode:    0x7,
			UserMsg:    "unsupported media type",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "not an image",
		},
	}
	ErrDurationNotSet = &domainError{
		outerError: outerError{
			StatusCode: http.StatusBadRequest,
			AppCode:    0x8,
			UserMsg:    "duration not set",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "duration not set",
		},
	}
	ErrDurationInvalid = &domainError{
		outerError: outerError{
			StatusCode: http.StatusBadRequest,
			AppCode:    0x9,
			UserMsg:    "duration invalid",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "duration invalid",
		},
	}
	ErrInvalidId = &domainError{
		outerError: outerError{
			StatusCode: http.StatusBadRequest,
			AppCode:    0x17,
			UserMsg:    "id invalid",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "id invalid",
		},
	}
	ErrAlbumNotFound = &domainError{
		outerError: outerError{
			StatusCode: http.StatusNotFound,
			AppCode:    0xA,
			UserMsg:    "album not found",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "album not found",
		},
	}
	ErrPairNotFound = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0xB,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "pair not found",
		},
	}
	ErrTokenNotFound = &domainError{
		outerError: outerError{
			StatusCode: http.StatusNotFound,
			AppCode:    0xC,
			UserMsg:    "token not found",
		},
		innerError: innerError{
			Level:  LogDebug,
			DevMsg: "token not found",
		},
	}
	ErrImageNotFound = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0xD,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "image not found",
		},
	}
	ErrAlbumAlreadyExists = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0xE,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "album already exists",
		},
	}
	ErrTokenAlreadyExists = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0xF,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "token already exists",
		},
	}
	ErrUnsupportedMediaType = &domainError{
		outerError: outerError{
			StatusCode: http.StatusUnsupportedMediaType,
			AppCode:    0x10,
			UserMsg:    "unsupported media type",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "image rejected by third party",
		},
	}
	ErrThirdPartyUnavailable = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x11,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogCritical,
			DevMsg: "third party is unavailable",
		},
	}
	ErrBadHealthCompressor = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x12,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogCritical,
			DevMsg: "compressor is unavailable",
		},
	}
	ErrBadHealthStorage = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x13,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogCritical,
			DevMsg: "storage is unavailable",
		},
	}
	ErrBadHealthDatabase = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x14,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogCritical,
			DevMsg: "database is unavailable",
		},
	}
	ErrBadHealthCache = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x15,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogCritical,
			DevMsg: "cache is unavailable",
		},
	}
	ErrUnknown = &domainError{
		outerError: outerError{
			StatusCode: http.StatusInternalServerError,
			AppCode:    0x16,
			UserMsg:    "internal server error",
		},
		innerError: innerError{
			Level:  LogError,
			DevMsg: "unknown",
		},
	}
)

Functions

func Wrap

func Wrap(err error, sentinel *domainError) error

Types

type Cacher

type Cacher interface {
	Limiter
	Queuer
	PQueuer
	Stacker
	Tokener
	Checker
}

type Checker

type Checker interface {
	Health(ctx context.Context) (bool, error)
}

type Compresser

type Compresser interface {
	Compress(ctx context.Context, f model.File) (model.File, error)
	Checker
}

type Databaser

type Databaser interface {
	SaveAlbum(ctx context.Context, alb model.Album) error
	CountImages(ctx context.Context, album uint64) (int, error)
	CountImagesCompressed(ctx context.Context, album uint64) (int, error)
	UpdateCompressionStatus(ctx context.Context, album uint64, image uint64) error
	GetImageSrc(ctx context.Context, album uint64, image uint64) (string, error)
	GetImagesIds(ctx context.Context, album uint64) ([]uint64, error)
	SaveVote(ctx context.Context, album uint64, imageFrom uint64, imageTo uint64) error
	GetEdges(ctx context.Context, album uint64) (map[uint64]map[uint64]int, error)
	UpdateRatings(ctx context.Context, album uint64, vector map[uint64]float64) error
	GetImagesOrdered(ctx context.Context, album uint64) ([]model.Image, error)
	DeleteAlbum(ctx context.Context, album uint64) error
	AlbumsToBeDeleted(ctx context.Context) ([]model.Album, error)
	Checker
}

type Error

type Error interface {
	error
	Outer
	Inner
}

type Inner

type Inner interface {
	Inner() innerError
}

type Limiter

type Limiter interface {
	Allow(ctx context.Context, ip uint64) (bool, error)
}

type Outer

type Outer interface {
	Outer() outerError
}

type PQueuer

type PQueuer interface {
	PAdd(ctx context.Context, pqueue uint64, album uint64, expires time.Time) error
	PPoll(ctx context.Context, pqueue uint64) (uint64, time.Time, error)
	PSize(ctx context.Context, pqueue uint64) (int, error)
}

type Queuer

type Queuer interface {
	Add(ctx context.Context, queue uint64, album uint64) error
	Poll(ctx context.Context, queue uint64) (uint64, error)
	Size(ctx context.Context, queue uint64) (int, error)
}

type Servicer

type Servicer interface {
	Album(ctx context.Context, ff []model.File, dur time.Duration) (uint64, error)
	Pair(ctx context.Context, album uint64) (model.Image, model.Image, error)
	Image(ctx context.Context, token uint64) (model.File, error)
	Vote(ctx context.Context, album uint64, tokenFrom uint64, tokenTo uint64) error
	Top(ctx context.Context, album uint64) ([]model.Image, error)
	Progress(ctx context.Context, album uint64) (float64, error)
	Checker
}

type Stacker

type Stacker interface {
	Push(ctx context.Context, album uint64, pairs [][2]uint64) error
	Pop(ctx context.Context, album uint64) (uint64, uint64, error)
}

type Storager

type Storager interface {
	Put(ctx context.Context, album uint64, image uint64, f model.File) (string, error)
	Get(ctx context.Context, album uint64, image uint64) (model.File, error)
	Remove(ctx context.Context, album uint64, image uint64) error
	Checker
}

type Tokener

type Tokener interface {
	Set(ctx context.Context, token uint64, album uint64, image uint64) error
	Get(ctx context.Context, token uint64) (uint64, uint64, error)
	Del(ctx context.Context, token uint64) error
}

Jump to

Keyboard shortcuts

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