utils

package
v0.0.0-...-9305a47 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteSessionCookie

func DeleteSessionCookie(w http.ResponseWriter)

func GenerateSessionKey

func GenerateSessionKey() (string, error)

func GetCookie

func GetCookie(r *http.Request) *http.Cookie

func GetInt32FromPath

func GetInt32FromPath(r *http.Request, key string) (int32, error)

func GetInt32FromQuery

func GetInt32FromQuery(r *http.Request, key string, defaultValue int32) int32

func GetInt64FromPath

func GetInt64FromPath(r *http.Request, key string) (int64, error)

func GetPagination

func GetPagination(limit, page int32) (newLimit, offset int64)

func GetSessionFromContext

func GetSessionFromContext(ctx context.Context) *entity.Session

func GetUserIDFromContext

func GetUserIDFromContext(ctx context.Context) int64

func HashBcrypt

func HashBcrypt(password string) (string, error)

func HashBcryptCompare

func HashBcryptCompare(password, hash string) bool

func HashSha256

func HashSha256(data string) string

func NewSqlInt64

func NewSqlInt64(val *int64) sql.NullInt64

func NewSqlString

func NewSqlString(val *string) sql.NullString

func ParseJsonFromHTTPRequest

func ParseJsonFromHTTPRequest(r io.ReadCloser, data interface{}) error

func PrepareStringToLike

func PrepareStringToLike(s string) string

func Response

func Response(w http.ResponseWriter, respBody interface{}) error

func ResponseWithMeta

func ResponseWithMeta(w http.ResponseWriter, respBody interface{}, meta *Meta) error

func SetSessionCookie

func SetSessionCookie(session string, w http.ResponseWriter)

func SqlStringToString

func SqlStringToString(val sql.NullString) *string

func UUIDGenerate

func UUIDGenerate() (string, error)

func WriteJSONHTTPResponse

func WriteJSONHTTPResponse(w http.ResponseWriter, httpCode int, data interface{}) error

Types

type JSONResponse

type JSONResponse struct {
	// Body
	Data interface{} `json:"data,omitempty"`
	// Meta
	Meta *Meta `json:"meta,omitempty"`
}

type Meta

type Meta struct {
	Total int32 `json:"total"`
	Limit int32 `json:"limit"`
	Page  int32 `json:"page"`
}

Jump to

Keyboard shortcuts

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