utils

package
v0.0.0-...-7fab21c Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SuccessURL = stripe.String(successURL)

	CancelURL = stripe.String(cancelURL)
)
View Source
var ERR_EXPIRED_OTP = "expired_otp"
View Source
var ERR_INCORRECT_EMAIL = "incorrect_email"
View Source
var ERR_INCORRECT_OTP = "incorrect_otp"
View Source
var ERR_INVALID_AUTH = "invalid_auth"
View Source
var ERR_INVALID_CREDENTIALS = "invalid_credentials"
View Source
var ERR_INVALID_DATA_TYPE = "invalid_data_type"
View Source
var ERR_INVALID_ENTRY = "invalid_entry"
View Source
var ERR_INVALID_OWNER = "invalid_owner"
View Source
var ERR_INVALID_PAGE = "invalid_page"
View Source
var ERR_INVALID_REQUEST = "invalid_request"
View Source
var ERR_INVALID_TOKEN = "invalid_token"
View Source
var ERR_INVALID_VALUE = "invalid_value"
View Source
var ERR_NETWORK_FAILURE = "network_failure"
View Source
var ERR_NON_EXISTENT = "non_existent"
View Source
var ERR_NOT_ALLOWED = "not_allowed"
View Source
var ERR_OAUTH = "oauth_error"
View Source
var ERR_REQUEST_LIMIT = "request_limit_hit"
View Source
var ERR_SERVER_ERROR = "server_error"
View Source
var ERR_UNAUTHORIZED_USER = "unauthorized_user"

Error codes

View Source
var ERR_UNVERIFIED_USER = "unverified_user"

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func ConvertStructData

func ConvertStructData(object interface{}, targetStruct interface{}) interface{}

func DateValidator

func DateValidator(fl validator.FieldLevel) bool

Validates if a date has a correct format (ISO8601)

func DeleteFile

func DeleteFile(fileKey string) error

DeleteFile deletes a file from the S3 bucket

func FilteredFields

func FilteredFields(body map[string]interface{}, allowedFields ...string) map[string]interface{}

FilteredFields filters the fields that are allowed to be updated.

func GenerateRandomToken

func GenerateRandomToken(length int, uppercase bool) (string, error)

GenerateRandomToken generates a random token of specified length and case (upper or lower).

func GetFile

func GetFile(fileKey string) ([]byte, error)

GetFile retrieves a file from S3 and returns its content

func GetRandomInt

func GetRandomInt(size int) int64

Generates a random integer with a specified number of digits

func GetRandomString

func GetRandomString(length int) string

func GetStripeAllowedCountries

func GetStripeAllowedCountries() *stripe.CheckoutSessionShippingAddressCollectionParams

func GetStripeShippingOptions

func GetStripeShippingOptions() []*stripe.CheckoutSessionShippingOptionParams

func HashPassword

func HashPassword(password string) string

PASSWORD HASHING

func UploadFile

func UploadFile(file *multipart.FileHeader) (string, error)

UploadFile uploads a file to S3 and returns the URL of the uploaded file

func ValidateDiscountedPrice

func ValidateDiscountedPrice(fl validator.FieldLevel) bool

func ValidateUUID

func ValidateUUID(fl validator.FieldLevel) bool

Types

type CustomValidator

type CustomValidator struct{}

CustomValidator is a custom validator that uses "github.com/go-playground/validator/v10"

func Validator

func Validator() *CustomValidator

New creates a new instance of CustomValidator

func (*CustomValidator) Validate

func (cv *CustomValidator) Validate(i interface{}) *ErrorResponse

Validate performs the validation of the given struct

type ErrorResponse

type ErrorResponse struct {
	Status  string             `json:"status"`
	Code    string             `json:"code"`
	Message string             `json:"message"`
	Data    *map[string]string `json:"data,omitempty"`
}

func ParseUUID

func ParseUUID(input string) (*uuid.UUID, *ErrorResponse)

UUID PARSER

func RequestErr

func RequestErr(code string, message string, opts ...map[string]string) ErrorResponse

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (ErrorResponse) Init

func (obj ErrorResponse) Init() ErrorResponse

type S3Client

type S3Client struct {
	// contains filtered or unexported fields
}

S3Client is a wrapper around the S3 service client

Jump to

Keyboard shortcuts

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