util

package
v0.0.0-...-0425f76 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenKey = &tokenContextKey{}
)

Functions

func AddUserPhoto

func AddUserPhoto(roomID string, userID string, photoURL string) error

func ChangeGameMaster

func ChangeGameMaster(roomID string, userID string) error

func CreateRoom

func CreateRoom(roomID string, user model.User) error

func DeleteDir

func DeleteDir(dirName string) error

func DeleteRoom

func DeleteRoom(roomID string, userID string) error

func ErrorJsonResponse

func ErrorJsonResponse(w http.ResponseWriter, status int, err error)

func ExitRoom

func ExitRoom(roomID string, userID string) error

func GeneratePhotoDescription

func GeneratePhotoDescription(photoUrl string) (description model.PhotoDescription, err error)

func GenerateRandomScore

func GenerateRandomScore() float32

GenerateRandomScore generates a random score between 10.0000 ~ 99.9999

func GenerateRoomID

func GenerateRoomID(digits int, id string) (string, error)

func GenerateToken

func GenerateToken(id string) (string, error)

func GetEnv

func GetEnv(keys ...string) map[string]string

func GetEnvVar

func GetEnvVar(name string) string

func GetGameMaster

func GetGameMaster(roomID string, userID string) (string, error)

func GetGameMasterPhotoUrl

func GetGameMasterPhotoUrl(roomID string, gameMasterID string) (string, error)

func GetGameRounds

func GetGameRounds(roomID string) (int, error)

func GetGameStatus

func GetGameStatus(roomID string) (*model.GameStatus, error)

func GetNoGameMasterID

func GetNoGameMasterID(roomID string, gameMasterID string) (string, error)

func GetPhotoDescription

func GetPhotoDescription(roomID string) ([]model.PhotoDescription, error)

func GetPlayerPhotoUrls

func GetPlayerPhotoUrls(roomID string, userID string) ([]string, error)

func GetRoomUsers

func GetRoomUsers(roomID string) (*model.RoomUsers, error)

func GetScore

func GetScore(gameMasterPhotoUrl string, playerPhotoUrl1 string, playerPhotoUrl2 string) (float32, error)

func GetScoreIndex

func GetScoreIndex(roomID string, userID string) (int, error)

func GetSubmitUnixSeconds

func GetSubmitUnixSeconds() int

func GetTotalPlayers

func GetTotalPlayers(roomID string) (int, error)

func GetUserIDs

func GetUserIDs(roomID string) ([]string, error)

func GetUserValue

func GetUserValue(userID string) (string, error)

func IncrementCurrentRound

func IncrementCurrentRound(roomID string) error

func Init

func Init()

func IsRoomExist

func IsRoomExist(roomID string) (bool, error)

func IsUserInRoom

func IsUserInRoom(userID string, roomID string) (bool, error)

func JoinRoom

func JoinRoom(user model.User) error

func LoadImage

func LoadImage(data []byte, fileType string) (image.Image, error)

Readable image formats: jpeg, png

func MakeDir

func MakeDir(dirName string) error

func ReadFormFile

func ReadFormFile(r *http.Request) ([]byte, error)

func Resize

func Resize(data []byte, maxHeight int) []byte

Aspect ratio preserving image resizing

func SanitizeString

func SanitizeString(input string) string

func SaveFile

func SaveFile(data []byte, path string, extension string) (string, error)

func SetPhotoDescription

func SetPhotoDescription(roomID string, description model.PhotoDescription) error

func SetScore

func SetScore(roomID string, userID string, score float32) error

func SetUserID

func SetUserID(userID string) error

func SetUserScore

func SetUserScore(roomID string, userID string) error

func SetUserValue

func SetUserValue(userID string, value string) error

func SuccessJsonResponse

func SuccessJsonResponse(w http.ResponseWriter, res interface{})

func UpdateGameStatus

func UpdateGameStatus(roomID string, status string) error

func UpdateRounds

func UpdateRounds(roomID string, rounds string) error

func UpdateUsername

func UpdateUsername(roomID string, userID string, newUserName string) error

func Validate

func Validate(r *http.Request, validateFuncs ...func(user model.User) error) (model.User, error)

func ValidateFileType

func ValidateFileType(r *http.Request) (string, error)

func ValidateLang

func ValidateLang(user model.User) error

func ValidateMaxFileSize

func ValidateMaxFileSize(r *http.Request) error

func ValidateName

func ValidateName(user model.User) error

func ValidateNewGameMaster

func ValidateNewGameMaster(user model.User) error

func ValidateRoom

func ValidateRoom(user model.User) error

func ValidateRounds

func ValidateRounds(user model.User) error

func ValidateToken

func ValidateToken(ctx context.Context, tokenString string) (context.Context, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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