paycloudgohelper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONFIG_PARTNERS        = "config_partners"
	CONFIG_PAYMENT_METHODS = "config_payment_methods"
)
View Source
const (
	// Localize log levels from zerolog
	LevelDebug = level(zerolog.DebugLevel)
	LevelInfo  = level(zerolog.InfoLevel)
	LevelWarn  = level(zerolog.WarnLevel)
	LevelError = level(zerolog.ErrorLevel)
	LevelFatal = level(zerolog.FatalLevel)
)
View Source
const (
	Numeric string = "^-?[0-9]+$"
	Key     string = "^[-a-zA-Z0-9_-]+$"
)

Variables

View Source
var (
	RedisPoolClient      *redis.Client
	RedisDefaultDuration = 180 * time.Second
)

Functions

func AddValidatorLibs

func AddValidatorLibs()

func DeleteRedis

func DeleteRedis(id string) (err error)

func GetRedis

func GetRedis(id string) (result string, err error)

func GetRedisClient

func GetRedisClient(redisHost, redisPort, redisPassword string, redisDb int) (*redis.Client, error)

func InitLogger

func InitLogger()

func InitRedis

func InitRedis(ctx context.Context, opt *redis.Options) (*redis.Client, error)

func JSONEncode

func JSONEncode(obj interface{}) string

func JSONMarshalNoEsc

func JSONMarshalNoEsc(t interface{}) ([]byte, error)

func JsonMinify

func JsonMinify(jsonB []byte) ([]byte, error)

func LoggerErrorHub

func LoggerErrorHub(err interface{})

func ReadBody

func ReadBody(c echo.Context, idem string) (map[string]interface{}, string, error)

read body payload and validate with the key

func StoreRedis

func StoreRedis(id string, data interface{}, duration time.Duration) (err error)

func VerifCsrf

func VerifCsrf(next echo.HandlerFunc) echo.HandlerFunc

func VerifIdemKey

func VerifIdemKey(next echo.HandlerFunc) echo.HandlerFunc

func VerifyMD5

func VerifyMD5(idemKey string, request []byte) (string, error)

generate md5 hash and compare the result with current key submitted

Types

type Headers

type Headers struct {
	IdempotencyKey string `json:"idem_key"`
	Session        string `json:"session"`
	Csrf           string `json:"csrf"`
}

func (*Headers) ValidateHeaderCsrf

func (h *Headers) ValidateHeaderCsrf() interface{}

func (*Headers) ValidateHeaderIdem

func (h *Headers) ValidateHeaderIdem() interface{}

type Logger

type Logger interface {
	Debug() *zerolog.Event
	Info() *zerolog.Event
	Warn() *zerolog.Event
	Error() *zerolog.Event
	Fatal() *zerolog.Event
	With() zerolog.Context
}

Logger has selective logger method signatures

func FromContext

func FromContext(ctx context.Context) Logger

FromContext retrives the logger from context. In absence of logger in context, this creates a new logger with Stdout as output stream and default log level specified in constants.

func FromRawLogger

func FromRawLogger(l zerolog.Logger) Logger

FromRawLogger creates Logger type from zerolog Logger

func NewLogger

func NewLogger(ctx context.Context, out io.Writer, level level) (context.Context, Logger)

NewLogger creates a new logger with specified output stream and level. This returns the updated context which has key struct as key and logger as value. The same logger instance can be retrieved from this context.

type ResponseApi

type ResponseApi struct {
	Code    int         `json:"code"`
	Status  string      `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func (*ResponseApi) Accepted

func (r *ResponseApi) Accepted(data interface{})

func (*ResponseApi) BadRequest

func (r *ResponseApi) BadRequest(message string, err interface{})

BadRequest is method for bad request

func (*ResponseApi) InternalServerError

func (r *ResponseApi) InternalServerError(err error)

InternalServerError is method for internal server error

func (*ResponseApi) Out

func (r *ResponseApi) Out(code int, message, status string, data interface{})

func (*ResponseApi) Success

func (r *ResponseApi) Success(message string, data interface{})

func (*ResponseApi) Unauthorized

func (r *ResponseApi) Unauthorized(message string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳