tools

package
v0.0.0-...-4d78421 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const SplitStrNum = 2

Variables

This section is empty.

Functions

func CreateDBErrorResponse

func CreateDBErrorResponse(err error) types.ValidationErrorResponse

CreateDBErrorResponse formats a database error into a structured response.

func GetNextPageURL

func GetNextPageURL(r *http.Request, limit, offset, totalRows int) string

func GetPrevPageURL

func GetPrevPageURL(r *http.Request, limit, offset int) string

func GetSessionDetails

func GetSessionDetails(r *http.Request, store *session.Store) (uuid.UUID, uuid.UUID, uuid.UUID, bool)

GetSessionDetails retrieves user ID, organization ID, and business unit ID from the session.

func GetSystemSessionName

func GetSystemSessionName() string

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if the provided error is a ValidationError.

func PaginationParams

func PaginationParams(r *http.Request) (int, int, error)

func ParseBody

func ParseBody(r *http.Request, body any) error

func ParseBodyAndValidate

func ParseBodyAndValidate(w http.ResponseWriter, r *http.Request, body any) error

ParseBodyAndValidate parses the request body into the given struct and validates it using the given validator. If the body is invalid, it writes a 400 response with the validation error.

func RegisterGob

func RegisterGob()

RegisterGob registers the UUID type with gob, so it can be used in sessions.

func ResponseWithError

func ResponseWithError(w http.ResponseWriter, statusCode int, data any)

func ResponseWithJSON

func ResponseWithJSON(w http.ResponseWriter, statusCode int, data any)

func WithTx

func WithTx(ctx context.Context, client *ent.Client, fn func(tx *ent.Tx) error) error

Types

type LocalFileStorage

type LocalFileStorage struct {
	BaseDir string
}

func NewLocalFileStorage

func NewLocalFileStorage() *LocalFileStorage

NewLocalFileStorage initializes a new LocalFileStorage with the base directory.

func (*LocalFileStorage) StoreFile

func (lfs *LocalFileStorage) StoreFile(file multipart.File, orgID uuid.UUID, filename string) (string, error)

StoreFile saves the provided file in an organization-specific subdirectory within the media directory.

type StorageService

type StorageService interface {
	StoreFile(file multipart.File, orgID uuid.UUID, filename string) (string, error)
}

type ValidationError

type ValidationError struct {
	Response types.ValidationErrorResponse
}

func NewValidationError

func NewValidationError(message, code, attr string) *ValidationError

newValidationError creates a new ValidationError with the specified message and code.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type Validator

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

func NewValidator

func NewValidator() (*Validator, error)

func (*Validator) Validate

func (v *Validator) Validate(payload any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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