utils

package
v0.0.0-...-2e3f1f0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCaptionTooBig = errors.New("the caption exceeds the maximun length")
View Source
var ErrCommentNotFound = errors.New("comment not found")
View Source
var ErrCommentNotValid = errors.New("the given comment doesn't match the required length")
View Source
var ErrEncodingJson = errors.New("error encoding json")
View Source
var ErrNotPhoto = errors.New("the given file is not an image")
View Source
var ErrPhotoNotFound = errors.New("photo not found")
View Source
var ErrPhotoTooBig = errors.New("the provided photo exceeds the maximum dimension")
View Source
var ErrUnauthoraized = errors.New("unauthorazied operation")
View Source
var ErrUserDetailsNotValid = errors.New("the user's details dont match the required pattern")
View Source
var ErrUserNotFound = errors.New("user not found")
View Source
var ErrUsernameMissing = errors.New("missing required username")
View Source
var ErrUsernameNotValid = errors.New("the username doesnt match the required pattern")
View Source
var ErrUsernameTaken = errors.New("the username is already taken")

Functions

func BytesToBase64

func BytesToBase64(bytes []byte) string

func GetAuthorization

func GetAuthorization(w http.ResponseWriter, r *http.Request, id ...int) (int, error)

func GetHttpParam

func GetHttpParam(w http.ResponseWriter, ps httprouter.Params, name string) (int, error)

func HttpValidateUsername

func HttpValidateUsername(w http.ResponseWriter, username string) bool

Write the right response code based on the validity of the username

func NowFormat

func NowFormat() string

func SetHeaderJson

func SetHeaderJson(w http.ResponseWriter)

func SetHeaderText

func SetHeaderText(w http.ResponseWriter)

func ValidateUsername

func ValidateUsername(username string) error

Database checks if username is between 3 and 16 characters

Types

type Comment

type Comment struct {
	CommentID int    `json:"id"`
	Text      string `json:"text"`
	UserID    int    `json:"user"`
	Username  string `json:"username"`
	PhotoID   int    `json:"photo"`
	Date      string `json:"date"`
}

func (Comment) Validate

func (c Comment) Validate() bool

type Like

type Like struct {
	UserID   int    `json:"user"`
	Username string `json:"username"`
	PhotoID  int    `json:"photo"`
}

type Photo

type Photo struct {
	PhotoID      int    `json:"id"`
	Username     string `json:"username"`
	UserID       int    `json:"user"`
	Image        string `json:"image"`
	Timestamp    string `json:"timestamp"`
	Caption      string `json:"caption"`
	LikeCount    int    `json:"likeCount"`
	CommentCount int    `json:"commentCount"`
	Liked        bool   `json:"liked"`
}

type User

type User struct {
	UserID         int    `json:"id"`
	Username       string `json:"username"`
	Name           string `json:"name"`
	Surname        string `json:"surname"`
	FollowersCount int    `json:"followersCount"`
	FollowingCount int    `json:"followingCount"`
	PhotoCount     int    `json:"photoCount"`
	Followed       bool   `json:"followed"`
	Banned         bool   `json:"banned"`
}

func (User) Validate

func (u User) Validate() bool

Jump to

Keyboard shortcuts

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