common_utils

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CheckIfFileExists

func CheckIfFileExists(path string) bool

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 GetCurrentDir

func GetCurrentDir() string

func GetExt

func GetExt(pathOrFilename string) string

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 PanicIfError

func PanicIfError(err error)

func PanicValidationError

func PanicValidationError(errors []ValidationError, statusCode int)

func ValidateBodyPayload

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

func ValidateStruct

func ValidateStruct(data interface{})

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     int    `mapstructure:"S3_PRESIGNED_EXPIRE"`
}

func CheckAndSetConfig

func CheckAndSetConfig(path string, configName string) *BaseConfig

func LoadBaseConfig

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

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