utils

package
v0.0.0-...-68eb7cf Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Origins []string
View Source
var RememberMeTimeout time.Duration
View Source
var SessionCount int
View Source
var SessionTimeout time.Duration

Functions

func BindAndValidate

func BindAndValidate(req interface{}, c echo.Context) (err error, ok bool)

func CleanUpExpiredTokens

func CleanUpExpiredTokens() error

TODO: Use this function in timed tasks

func Contain

func Contain(obj interface{}, target interface{}) bool

func CreateBucket

func CreateBucket(name string) error

func FindProblem

func FindProblem(id string, user *models.User) (*models.Problem, error)

This function checks if the user has permission to get problems which are not public. nil user pointer is regarded as admin(skip the permission judgement).

func FindSubmission

func FindSubmission(id uint, includeProblemSet bool) (*models.Submission, error)

func FindTestCase

func FindTestCase(problemId string, testCaseIdStr string, user *models.User) (*models.TestCase, *models.Problem, error)

This function checks if the user has permission to get problems which are not public. nil user pointer is regarded as admin(skip the permission judgement).

func FindUser

func FindUser(id string) (*models.User, error)

func GenerateInviteCode

func GenerateInviteCode() (code string)

func GetPresignedURL

func GetPresignedURL(bucket string, path string, fileName string) (string, error)

func GetToken

func GetToken(tokenString string) (token models.Token, err error)

func HashPassword

func HashPassword(password string) (hashed string)

func InitOrigin

func InitOrigin()

func IsTokenExpired

func IsTokenExpired(token models.Token) bool

func MustGetObject

func MustGetObject(c echo.Context, bucket string, path string) *minio.Object

func MustPutObject

func MustPutObject(object *multipart.FileHeader, ctx context.Context, bucket string, path string)

func Paginator

func Paginator(query *gorm.DB, limit, offset int, requestURL *url.URL, output interface{}) (total int, prevUrl, nextUrl *string, err error)

func PanicIfDBError

func PanicIfDBError(db *gorm.DB, message string)

func RandStr

func RandStr(n int) string

RandStr generates a string with given length. Only contains a-z and A-Z.

func Sorter

func Sorter(query *gorm.DB, orderBy string, columns ...string) (*gorm.DB, error)

func VerifyPassword

func VerifyPassword(password, hashed string) bool

Types

type HttpError

type HttpError struct {
	Code    int
	Message string
	Err     error
}

func (HttpError) Error

func (e HttpError) Error() string

func (HttpError) Response

func (e HttpError) Response(c echo.Context) error

Jump to

Keyboard shortcuts

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