common_utils

package
v1.0.72 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TEST        = "test"
	DEVELOPMENT = "development"
	STAGING     = "staging"
	PRODUCTION  = "production"
)

Variables

This section is empty.

Functions

func BuildCacheKey added in v1.0.35

func BuildCacheKey(key string, identifier string, funcName string, args ...any) string

func BuildPrefixKey added in v1.0.35

func BuildPrefixKey(keys ...string) string

func CheckIfFileExists

func CheckIfFileExists(path string) bool

func ComparedPassword added in v1.0.10

func ComparedPassword(hashedPassword string, password string) error

func ConvertInterfaceE

func ConvertInterfaceE(from any, to any) error

func ConvertInterfaceP

func ConvertInterfaceP(from any, to any)

func CreateFile

func CreateFile(path string) (*os.File, error)

func CustomError

func CustomError(message string, statusCode int) error

func CustomErrorWithTrace

func CustomErrorWithTrace(err error, message string, statusCode int) error

func DeferCheck

func DeferCheck(function func() error)

func DeleteFile

func DeleteFile(path string) error

func DownloadFile

func DownloadFile(url, filePath string) error

func EnableCORS added in v1.0.6

func EnableCORS(r *chi.Mux)

func GenerateJsonResponse added in v1.0.6

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

func GetCurrentDir

func GetCurrentDir() string

func GetExt

func GetExt(pathOrFilename string) string

func HashedPassword added in v1.0.9

func HashedPassword(password string) (string, error)

func LogAndPanicIfError

func LogAndPanicIfError(err error, message string)

func LogDebug

func LogDebug(message string, fields ...zap.Field)

func LogError

func LogError(message string, fields ...zap.Field)

func LogFatal

func LogFatal(message string, fields ...zap.Field)

func LogIfError

func LogIfError(err error)

func LogInfo

func LogInfo(message string, fields ...zap.Field)

func LogPanic

func LogPanic(message string, fields ...zap.Field)

func PanicAppError

func PanicAppError(message string, statusCode int)

func PanicIfAppError

func PanicIfAppError(err error, message string, statusCode int)

func PanicIfAppErrorWithTrace added in v1.0.64

func PanicIfAppErrorWithTrace(ctx context.Context, err error, message string, statusCode int)

func PanicIfError

func PanicIfError(err error)

func PanicValidationError

func PanicValidationError(errors []ValidationError, statusCode int)

func ValidateBodyPayload

func ValidateBodyPayload(body io.ReadCloser, output interface{})

func ValidateQueryParamInt added in v1.0.6

func ValidateQueryParamInt(r *http.Request, queryName string) int

func ValidateStruct

func ValidateStruct(data interface{})

func ValidateUrlParamUUID added in v1.0.6

func ValidateUrlParamUUID(r *http.Request, paramName string) uuid.UUID

Types

type AppError

type AppError struct {
	Message    string
	StatusCode int
}

func (*AppError) Error

func (ae *AppError) Error() string

type BaseConfig

type BaseConfig struct {
	ServiceName           string        `mapstructure:"SERVICE_NAME"`
	ServiceEnv            string        `mapstructure:"SERVICE_ENV"`
	ServiceHost           string        `mapstructure:"SERVICE_HOST"`
	ServiceHttpPort       string        `mapstructure:"SERVICE_HTTP_PORT"`
	ServiceGrpcPort       string        `mapstructure:"SERVICE_GRPC_PORT"`
	GcpProjectId          string        `mapstructure:"GCP_PROJECT_ID"`
	PubsubDlq             string        `mapstructure:"PUBSUB_DLQ_TOPIC"`
	RedisHost             string        `mapstructure:"REDIS_HOST"`
	RedisPort             string        `mapstructure:"REDIS_PORT"`
	RedisUser             string        `mapstructure:"REDIS_USER"`
	RedisPassword         string        `mapstructure:"REDIS_PASSWORD"`
	RedisCacheExpire      int           `mapstructure:"REDIS_DEFAULT_CACHE_EXPIRE"`
	MongoHost             string        `mapstructure:"MONGO_HOST"`
	MongoPort             string        `mapstructure:"MONGO_PORT"`
	MongoUser             string        `mapstructure:"MONGO_USER"`
	MongoPassword         string        `mapstructure:"MONGO_PASSWORD"`
	MongoDb               string        `mapstructure:"MONGO_DATABASE"`
	PostgresHost          string        `mapstructure:"POSTGRES_HOST"`
	PostgresPort          string        `mapstructure:"POSTGRES_PORT"`
	PostgresUser          string        `mapstructure:"POSTGRES_USER"`
	PostgresPassword      string        `mapstructure:"POSTGRES_PASSWORD"`
	PostgresDb            string        `mapstructure:"POSTGRES_DATABASE"`
	ElasticsearchHost     string        `mapstructure:"ELASTICSEARCH_HOST"`
	ElasticsearchUser     string        `mapstructure:"ELASTICSEARCH_USER"`
	ElasticsearchPassword string        `mapstructure:"ELASTICSEARCH_PASSWORD"`
	JaegerEnable          bool          `mapstructure:"JAEGER_ENABLE"`
	JaegerHost            string        `mapstructure:"JAEGER_HOST"`
	JaegerPort            string        `mapstructure:"JAEGER_PORT"`
	JaegerLogSpans        bool          `mapstructure:"JAEGER_LOG_SPANS"`
	S3Endpoint            string        `mapstructure:"S3_ENDPOINT"`
	S3AccessKey           string        `mapstructure:"S3_ACCESS_KEY"`
	S3SecretKey           string        `mapstructure:"S3_SECRET_KEY"`
	S3Region              string        `mapstructure:"S3_REGION"`
	S3PublicBucket        string        `mapstructure:"S3_PUBLIC_BUCKET"`
	S3PrivateBucket       string        `mapstructure:"S3_PRIVATE_BUCKET"`
	S3PublicUrl           string        `mapstructure:"S3_PUBLIC_URL"`
	S3PreSignedExpire     time.Duration `mapstructure:"S3_PRESIGNED_EXPIRE"`
	JwtSecretKey          string        `mapstructure:"JWT_SECRET_KEY"`
	JwtAccessTokenExpire  time.Duration `mapstructure:"JWT_ACCESS_TOKEN_EXPIRE"`
	JwtRefreshTokenExpire time.Duration `mapstructure:"JWT_REFRESH_TOKEN_EXPIRE"`
}

func CheckAndSetConfig

func CheckAndSetConfig(path string, configName string) *BaseConfig

func LoadBaseConfig

func LoadBaseConfig(path string, configName string) (*BaseConfig, error)

type Pagination added in v1.0.26

type Pagination[T any] struct {
	Limit      int    `json:"limit,omitempty"`
	Page       int    `json:"page,omitempty"`
	Sort       string `json:"sort,omitempty"`
	TotalRows  int    `json:"totalRows,omitempty"`
	TotalPages int    `json:"totalPages,omitempty"`
	Rows       []T    `json:"rows,omitempty"`
}

func Paginate added in v1.0.26

func Paginate[T any](pagination *Pagination[T], rows []T) *Pagination[T]

func ValidatePagination added in v1.0.26

func ValidatePagination[T any](r *http.Request) *Pagination[T]

type ParamType added in v1.0.6

type ParamType interface {
	uuid.UUID | string
}

type Response added in v1.0.6

type Response[T any] struct {
	StatusCode int    `json:"status_code"`
	Status     string `json:"status"`
	Message    string `json:"message"`
	Data       T      `json:"data,omitempty"`
}

swagger:model Response

type ResponseMap added in v1.0.6

type ResponseMap struct {
	StatusCode int                    `json:"status_code"`
	Status     string                 `json:"status"`
	Message    string                 `json:"message"`
	Data       map[string]interface{} `json:"data,omitempty"`
}

FOR TESTING PURPOSE

type ResponseSlice added in v1.0.6

type ResponseSlice struct {
	StatusCode int                      `json:"status_code"`
	Status     string                   `json:"status"`
	Message    string                   `json:"message"`
	Data       []map[string]interface{} `json:"data,omitempty"`
}

FOR TESTING PURPOSE

type ValidationError

type ValidationError struct {
	Message string
}

func (*ValidationError) Error

func (ve *ValidationError) Error() string

type ValidationErrors

type ValidationErrors struct {
	Errors     []ValidationError
	StatusCode int
}

func (*ValidationErrors) Error

func (ve *ValidationErrors) Error() string

Jump to

Keyboard shortcuts

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