helpers

package
v0.0.0-...-bd0fe52 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Userkey key for the session
	Userkey = "user"
)

Variables

View Source
var ErrDemoExtensionNotTakenIntoAccount = errors.New("extension of the demo is not taken into account")

ErrDemoExtensionNotTakenIntoAccount extension of the demo is not taken into account

View Source
var ErrFileNil = errors.New("file is nil")

ErrFileNil file is nil

View Source
var ErrSessionNotLinked = errors.New("session isn't linked to any user connected")

ErrSessionNotLinked session isn't linked to any user connected

View Source
var MapNames = []string{"inferno",
	"dust2",
	"train",
	"mirage",
	"nuke",
	"overpass",
	"vertigo",
	"cache",
	"cbble",
	"canals",
	"zoo",
	"abbey",
	"biome",
	"militia",
	"agency",
	"office",
	"italy",
	"anubis",
	"chlorine",
	"breach",
	"workout",
	"swamp",
	"mutiny",
	"assault",
	"engage",
	"ancient",
	"apollo",
	"grind",
	"mocha",
}

MapNames slice of all map registered

Functions

func BoolPtr

func BoolPtr(value bool) *bool

BoolPtr permet de récupérer l'adresse d'un bool

func CheckErrorValidator

func CheckErrorValidator(ctx *gin.Context, logBack *custlogger.Logger, err error)

CheckErrorValidator permet de vérifier s'il s'agit d'une du validator ou non

func CheckHashPassword

func CheckHashPassword(passwordStored, passwordSent string) error

CheckHashPassword Permet de comparer un password hashé avec un password clear Ne pas utiliser pour comparer 2 hashs

func DemoFileToByte

func DemoFileToByte(fileDemo *os.File) ([]byte, error)

DemoFileToByte take a demo file in parameter to open it and return it in a decrypted slice of bytes

func DemoFileToReader

func DemoFileToReader(fileDemo *os.File) (io.Reader, error)

DemoFileToReader take a demo file in parameter to open it and return it in a decrypted reader

func DurationPtr

func DurationPtr(value time.Duration) *time.Duration

DurationPtr permet de récupérer l'adresse d'une duration

func FloatPtr

func FloatPtr(value float64) *float64

FloatPtr permet de récupérer l'adresse d'un float64

func Floor

func Floor(nbr float64, precision int) float64

Floor round floor a float to a certain precision

func FmtDuration

func FmtDuration(d time.Duration) string

FmtDuration convert duration to string mm:ss

func GenerateErrorValidator

func GenerateErrorValidator(str string) error

GenerateErrorValidator concat strErrorValidator with the param

func GetUserIDFromContext

func GetUserIDFromContext(ctx *gin.Context) (*uint, error)

GetUserIDFromContext Extrait l'id utilisateur du gin.Context

func HashPassword

func HashPassword(password string) (string, error)

HashPassword Retourne le hash d'un mot de passe passé en param Attention utilise la lib bcrypt : hasher 2 fois le même mdp ne donnera pas le même hash, utiliser la fonction CheckHashPassword

func Int64Ptr

func Int64Ptr(value int64) *int64

Int64Ptr permet de récupérer l'adresse d'un int64

func IntPtr

func IntPtr(value int) *int

IntPtr permet de récupérer l'adresse d'un int

func MakeEasyDetail

func MakeEasyDetail(key ErrorKey, value interface{}) map[ErrorKey]interface{}

MakeEasyDetail créé une map detail avec une clef unique

func Max

func Max(a, b int) int

Max Returns the max of a or b

func NewDemoInfoParserWithoutPanic

func NewDemoInfoParserWithoutPanic(demostream io.Reader, err *error) demoinfocs.Parser

NewDemoInfoParserWithoutPanic without this, if demostream isn't a demo, it panics

func NewGenErrorToError

func NewGenErrorToError(errorNewGen ErrorNewGen) error

NewGenErrorToError permet de vérifier s'il s'agit d'une du validator ou non

func PMod

func PMod(a, b float64) float64

PMod positive modulo

func ParseDemoWithoutPanic

func ParseDemoWithoutPanic(demoData demoinfocs.Parser, err *error)

ParseDemoWithoutPanic without this, if demostream isn't a demo, it panics

func ParseHeaderWithoutPanic

func ParseHeaderWithoutPanic(demoData demoinfocs.Parser, err *error)

ParseHeaderWithoutPanic without this, if demostream isn't a demo, it panics

func ParseMapName

func ParseMapName(rawName string) *string

ParseMapName parse the raw name to a sub name (ex faceit_inferno to inferno)

func RandBool

func RandBool() bool

RandBool return a random bool

func RandDate

func RandDate() *time.Time

RandDate return a random time.Time

func RandUIntPSQL

func RandUIntPSQL() *uint

RandUIntPSQL 0-maxint for psql

func RandomString

func RandomString(n int) string

RandomString Créée une chaine de caractère aléatoire de longueur n constituée de lettres et de nombres

func RandomStringChar

func RandomStringChar(n int) string

RandomStringChar Créée une chaine de caractère aléatoire de longueur n constituée de lettres

func RandomStringCharUpperAndDigits

func RandomStringCharUpperAndDigits(n int) string

RandomStringCharUpperAndDigits create a random string with uppercase letters and digits

func RandomStringNumber

func RandomStringNumber(n int) string

RandomStringNumber Créée une chaine de caractère aléatoire de longueur n constituée uniquement de nombres

func ReturnCORSSetup

func ReturnCORSSetup(ip string) gin.HandlerFunc

ReturnCORSSetup return the CORS setup

func Round

func Round(nbr float64, precision int) float64

Round round a float to a certain precision

func SendData

func SendData(ctx *gin.Context, status int, data interface{})

SendData a

func SendError

func SendError(ctx *gin.Context, logBack *custlogger.Logger, errorNewGen ErrorNewGen,
	details map[ErrorKey]interface{}, errorToLog error)

SendError Permet de renvoyer au front une erreur

func SendRequest

func SendRequest(parameters []byte, methode string, url string) (*http.Response, error)

SendRequest permet d'envoyer une requête

func StrPtr

func StrPtr(value string) *string

StrPtr permet de récupérer l'adresse d'un string

func TimePtr

func TimePtr(value time.Time) *time.Time

TimePtr permet de récupérer l'adresse d'un bool

func ToInt64

func ToInt64(s string) (int64, error)

ToInt64 convert string to int64

func ToUint

func ToUint(s string) (uint, error)

ToUint convert string to uint

func ToUint64

func ToUint64(s string) (uint64, error)

ToUint64 convert string to int64

func TruncatString

func TruncatString(s string, l int) string

TruncatString truncate the string to a certain length

func UInt64Ptr

func UInt64Ptr(value uint64) *uint64

UInt64Ptr permet de récupérer l'adresse d'un uint64

func UintPtr

func UintPtr(value uint) *uint

UintPtr permet de récupérer l'adresse d'un uint

func WeekStart

func WeekStart(year, week int) time.Time

WeekStart return a time.Time from a year and a week

Types

type Descriptions

type Descriptions struct {
	FR  string `json:"fr"`
	ENG string `json:"eng"`
}

Descriptions représente une description d'erreur stockée dans le json

type ErrorKey

type ErrorKey string

ErrorKey represents an error

const (
	// URL : l'erreur concerne l'url
	URL ErrorKey = "URL"
	// PAYLOAD : l'erreur concerne le json
	PAYLOAD ErrorKey = "PAYLOAD"
	// HEADER : l'erreur concerne le header
	HEADER ErrorKey = "HEADER"
	// DATA : plus d'informations sur l'erreur
	DATA ErrorKey = "DATA"
)

type ErrorNewGen

type ErrorNewGen struct {
	Title      string       `json:"title"`
	HTTPStatus int          `json:"HTTPStatus"`
	Descr      Descriptions `json:"descriptions"`

	// Variable plus spécifique au problème
	Details map[ErrorKey]interface{} `json:"details"`
}

ErrorNewGen représente une erreur stockée dans le json

func ErrAuth

func ErrAuth() ErrorNewGen

ErrAuth Authentication error

func ErrBadCredentials

func ErrBadCredentials() ErrorNewGen

ErrBadCredentials Bad login

func ErrBadRequest

func ErrBadRequest() ErrorNewGen

ErrBadRequest bad request

func ErrBadTokenConnection

func ErrBadTokenConnection() ErrorNewGen

ErrBadTokenConnection bad auth token

func ErrDataMissing

func ErrDataMissing() ErrorNewGen

ErrDataMissing 422

func ErrDuplicate

func ErrDuplicate() ErrorNewGen

ErrDuplicate duplicate ressource

func ErrForbidden

func ErrForbidden() ErrorNewGen

ErrForbidden 403

func ErrInternalServerError

func ErrInternalServerError() ErrorNewGen

ErrInternalServerError report error from server

func ErrInvalidInput

func ErrInvalidInput() ErrorNewGen

ErrInvalidInput bad user input

func ErrInvalidInputCookies

func ErrInvalidInputCookies() ErrorNewGen

ErrInvalidInputCookies bad cookie

func ErrInvalidInputJSON

func ErrInvalidInputJSON() ErrorNewGen

ErrInvalidInputJSON bad json parsing

func ErrInvalidInputURL

func ErrInvalidInputURL() ErrorNewGen

ErrInvalidInputURL bad GET data

func ErrNotFound

func ErrNotFound() ErrorNewGen

ErrNotFound 404

func ErrPasswordStrength

func ErrPasswordStrength() ErrorNewGen

ErrPasswordStrength security

func ErrTooManyRequest

func ErrTooManyRequest() ErrorNewGen

ErrTooManyRequest there are too many requests performed

Jump to

Keyboard shortcuts

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