utils

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClaimsKey key = iota
)

Variables

This section is empty.

Functions

func FormatErrorMessage added in v1.3.8

func FormatErrorMessage(field string, err validator.FieldError) string

func GenerateOTP added in v1.4.0

func GenerateOTP(length int) (string, error)

GenerateOTP generates a random OTP of the given length using numeric characters.

func GenerateOrderCode added in v1.4.0

func GenerateOrderCode(length int, charset string) (string, error)

GenerateOrderCode generates a random code of the given length using the provided character set.

func GenerateUniqueNumber

func GenerateUniqueNumber(length int) (string, error)

func GetAuthUser added in v1.4.0

func GetAuthUser(ctx context.Context) (map[string]interface{}, error)

func GetCurrentTime

func GetCurrentTime() time.Time

func GetJSONFieldMap added in v1.3.8

func GetJSONFieldMap(obj interface{}) map[string]string

GetJSONFieldMap uses reflection to map struct fields to their JSON tags

func JsonResponse

func JsonResponse(w http.ResponseWriter, statusCode int, data interface{})

func ResponseValidation

func ResponseValidation(w http.ResponseWriter, statusCode int, errors interface{}) error

func ReturnResponse

func ReturnResponse(w http.ResponseWriter, statusCode int, message string, data interface{})

func Slugify

func Slugify(s string) string

func StringToIntEnv added in v1.4.0

func StringToIntEnv(key string, defaultValue int) int

StringToIntEnv retrieves an environment variable as an integer, returning a default value if the conversion fails.

func ValidateAndCollectErrors added in v1.4.1

func ValidateAndCollectErrors(w http.ResponseWriter, statusCode int, errors map[string]string, error interface{}, obj interface{}) map[string]string

ValidateAndCollectErrors validates the input struct and returns any custom and validation errors found.

func ValidationResponse added in v1.3.8

func ValidationResponse(w http.ResponseWriter, statusCode int, error interface{}, obj interface{})

WriteJSONEValidation dynamically gets JSON tag fields and writes a validation error response

func WriteJSONEValidation

func WriteJSONEValidation(w http.ResponseWriter, statusCode int, error interface{})

func WriteJSONError

func WriteJSONError(w http.ResponseWriter, statusCode int, message string)

WriteJSONError writes a JSON error response with the specified status code and message.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, statusCode int, data interface{})

WriteJSONResponse writes a JSON response with the specified status code.

Types

type Bool added in v1.4.0

type Bool bool

func UnmarshalBool added in v1.4.0

func UnmarshalBool(data []byte) (Bool, error)

UnmarshalBool is a reusable function that unmarshals both boolean and string representations

func (*Bool) UnmarshalJSON added in v1.4.0

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes the unmarshaling for the Bool type

type CustomDateFormat

type CustomDateFormat time.Time

func (CustomDateFormat) MarshalJSON

func (c CustomDateFormat) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

type ErrorResponse

type ErrorResponse struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Errors  interface{} `json:"errors,omitempty"`
}

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

Response represents a standardized JSON response format.

Jump to

Keyboard shortcuts

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