paycloudhelper

package module
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 34 Imported by: 0

README

paycloudhelper

PayCloud Hub Helper Golang

Documentation

Overview

this middleware function is to revoke token jwt if status user blocked or suspend

Index

Constants

View Source
const (
	CmdAuditTrailProcess = "audit-trail-process"
	CmdAuditTrailData    = "audit-trail-data"
)
View Source
const (
	Numeric string = "^-?[0-9]+$"
	Key     string = "^[-a-zA-Z0-9_-]+$"
)

Variables

View Source
var (
	Log  = phlogger.Log
	LogD = Log.Debugf
	LogI = Log.Infof
	LogW = Log.Warnf
	LogE = Log.Errorf
	LogF = Log.Fatalf
	Logf = Log.Logf
)
View Source
var (
	DefaultRedisTimeout = 1000 * time.Millisecond
)

Functions

func AcquireLock added in v1.6.3

func AcquireLock(key string, ttl time.Duration) (bool, error)

AcquireLock acquires a distributed lock using RedSync

func AcquireLockWithRetry added in v1.6.3

func AcquireLockWithRetry(key string, ttl time.Duration, maxRetries int, retryDelay time.Duration) (*redsync.Mutex, bool, error)

AcquireLockWithRetry attempts to acquire a distributed lock with retries key: the lock key ttl: lock time-to-live maxRetries: maximum number of retry attempts retryDelay: delay between retries Returns: - mutex: the lock mutex (nil if not acquired) - acquired: whether the lock was acquired - err: any error that occurred

func AddValidatorLibs

func AddValidatorLibs()

func DeleteRedis

func DeleteRedis(id string) (err error)

func GetAppEnv added in v1.5.1

func GetAppEnv() string

func GetAppName added in v1.4.0

func GetAppName() string

func GetMutex added in v1.6.3

func GetMutex(key string) *redsync.Mutex

GetMutex retrieves a mutex from the map

func GetRedis

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

func GetRedisClient

func GetRedisClient(redisHost, redisPort, redisPassword string, redisDb int) error

func GetRedisOptions added in v1.4.0

func GetRedisOptions() *redis.Options

func GetRedisPoolClient added in v1.4.0

func GetRedisPoolClient() (*redis.Client, error)

func GetSentryClient added in v1.5.1

func GetSentryClient() *sentry.Client

func GetSentryClientOptions added in v1.5.1

func GetSentryClientOptions() *sentry.ClientOptions

func GetSentryData added in v1.5.1

func GetSentryData() *phsentry.SentryData

func GetTrxRedisBackoff added in v1.6.3

func GetTrxRedisBackoff() int

func GetTrxRedisLockTimeout added in v1.6.3

func GetTrxRedisLockTimeout() time.Duration

func InitRedSyncOnce added in v1.6.3

func InitRedSyncOnce() error

InitRedSyncOnce initializes the redSync instance once

func InitRedisOptions added in v1.4.0

func InitRedisOptions(rawOpt redis.Options) *redis.Options

func InitSentry added in v1.5.0

func InitSentry(options phsentry.SentryOptions) *sentry.Client

func InitSentryOptions added in v1.5.1

func InitSentryOptions(options phsentry.SentryOptions)

func InitializeApp added in v1.5.1

func InitializeApp()

func InitializeLogger added in v1.4.0

func InitializeLogger()

func InitializeRedis added in v1.6.3

func InitializeRedis(opt redis.Options)

func JSONEncode

func JSONEncode(obj interface{}) string

func JsonMinify

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

func LogAudittrailData

func LogAudittrailData(funcName, desc, source, commType string, key *[]string, data *RequestAndResponse)

LogAudittrailData add audittrail data

func LogAudittrailProcess

func LogAudittrailProcess(funcName, desc, info string, key *[]string)

LogAudittrailProcess add audittrail process

func LogErr added in v1.4.0

func LogErr(err error)

LogErr Error

func LogJ added in v1.4.0

func LogJ(arg interface{})

LogJ JSON

func LogJI added in v1.4.0

func LogJI(arg interface{})

LogJI as JSON with Indent

func LogSetLevel added in v1.4.0

func LogSetLevel(levelName string)

func LoggerErrorHub

func LoggerErrorHub(err interface{}, args ...interface{})

func NewAmqp added in v1.6.0

func NewAmqp(addr string, c *AmqpClient)

NewAmqp creates a new consumer state instance, and automatically attempts to connect to the server.

func NewSentryData added in v1.5.0

func NewSentryData(dt *phsentry.SentryData)

func ReadBody

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

ReadBody read body payload and validate with the key

func ReleaseLock added in v1.6.3

func ReleaseLock(key string) error

func ReleaseLockWithRetry added in v1.6.3

func ReleaseLockWithRetry(mutex *redsync.Mutex, maxRetries int) error

ReleaseLockWithRetry releases a previously acquired lock with retry mechanism

func RemoveMutex added in v1.6.3

func RemoveMutex(key string)

RemoveMutex removes a mutex from the map

func RevokeToken

func RevokeToken(next echo.HandlerFunc) echo.HandlerFunc

func SendSentryDebug added in v1.5.0

func SendSentryDebug(err error, args ...string)

func SendSentryError added in v1.5.0

func SendSentryError(err error, args ...string)

func SendSentryEvent added in v1.5.0

func SendSentryEvent(event *sentry.Event, args ...string)

func SendSentryMessage added in v1.5.0

func SendSentryMessage(msg string, args ...string)

func SendSentryWarning added in v1.5.0

func SendSentryWarning(err error, args ...string)

func SendToSentryDebug added in v1.5.1

func SendToSentryDebug(err error, service, module, function string)

func SendToSentryError added in v1.5.1

func SendToSentryError(err error, service, module, function string)

func SendToSentryEvent added in v1.5.1

func SendToSentryEvent(event *sentry.Event, service, module, function string)

func SendToSentryMessage added in v1.5.1

func SendToSentryMessage(message string, service, module, function string)

func SendToSentryWarning added in v1.5.1

func SendToSentryWarning(err error, service, module, function string)

func SetAppEnv added in v1.5.1

func SetAppEnv(v string)

func SetAppName added in v1.4.0

func SetAppName(v string)

func StoreMutex added in v1.6.3

func StoreMutex(key string, mutex *redsync.Mutex)

StoreMutex stores a mutex in the map for later release

func StoreRedis

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

func StoreRedisWithLock added in v1.6.3

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

func ToJson added in v1.4.0

func ToJson(data interface{}) string

ToJson Encode json from object to JSON and beautify the output.

func ToJsonIndent added in v1.4.0

func ToJsonIndent(data interface{}) string

ToJsonIndent Encode json from object to JSON and beautify the output.

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)

VerifyMD5 generate md5 hash and compare the result with current key submitted

Types

type AmqpClient added in v1.6.0

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

AmqpClient is the base struct for handling connection recovery, consumption and publishing. Note that this struct has an internal mutex to safeguard against data races. As you develop and iterate over this example, you may need to add further locks, or safeguards, to keep your application safe from data races

func NewAmqpClient added in v1.6.0

func NewAmqpClient(queueName, connName, addr string, config *amqp.Config) *AmqpClient

NewAmqpClient creates a new consumer state instance, and automatically attempts to connect to the server.

func SetUpRabbitMq

func SetUpRabbitMq(host, port, vhost, username, password, auditTrailQue, appName string) *AmqpClient

SetUpRabbitMq service must call this func in main function NOTE : for audittrail purpose

func (*AmqpClient) AmqpConfig added in v1.6.0

func (c *AmqpClient) AmqpConfig() amqp.Config

func (*AmqpClient) Cc added in v1.6.0

func (c *AmqpClient) Cc() error

Cc For debug purpose TODO : debugging close channel

func (*AmqpClient) Channel added in v1.6.0

func (c *AmqpClient) Channel() *amqp.Channel

func (*AmqpClient) Close added in v1.6.0

func (c *AmqpClient) Close() error

Close will cleanly shut down the channel and connection.

func (*AmqpClient) ConnName added in v1.6.0

func (c *AmqpClient) ConnName() string

func (*AmqpClient) Consume added in v1.6.0

func (c *AmqpClient) Consume() (<-chan amqp.Delivery, error)

Consume will continuously put queue items on the channel. It is required to call delivery.Ack when it has been successfully processed, or delivery.Nack when it fails. Ignoring this will cause data to build up on the server.

func (*AmqpClient) ErrLog added in v1.6.0

func (c *AmqpClient) ErrLog() *log.Logger

func (*AmqpClient) InfoLog added in v1.6.0

func (c *AmqpClient) InfoLog() *log.Logger

func (*AmqpClient) Push added in v1.6.0

func (c *AmqpClient) Push(data []byte) error

Push will push data onto the queue, and wait for a confirmation. This will block until the server sends a confirmation. Errors are only returned if the push action itself fails, see UnsafePush.

func (*AmqpClient) SetAmqpConfig added in v1.6.0

func (c *AmqpClient) SetAmqpConfig(amqpConfig *amqp.Config)

func (*AmqpClient) UnsafePush added in v1.6.0

func (c *AmqpClient) UnsafePush(data []byte) error

UnsafePush will push to the queue without checking for confirmation. It returns an error if it fails to connect. No guarantees are provided for whether the server will receive the message.

type AuditTrailData added in v1.6.0

type AuditTrailData struct {
	Subject           string              `json:"Subject,omitempty"`
	Function          string              `json:"Function,omitempty"`
	Description       string              `json:"Description,omitempty"`
	Key               []string            `json:"Key"`    //
	Source            string              `json:"Source"` // internal or external
	CommunicationType string              `json:"CommunicationType"`
	Data              *RequestAndResponse `json:"Data"`
}

type AuditTrailProcess added in v1.6.0

type AuditTrailProcess struct {
	Subject     string                `json:"Subject,omitempty"`
	Function    string                `json:"Function,omitempty"`
	Description string                `json:"Description,omitempty"`
	Key         []string              `json:"Key"`
	Data        DataAuditTrailProcess `json:"Data"`
}

type DataAuditTrailProcess added in v1.6.0

type DataAuditTrailProcess struct {
	Time string `json:"Time"` // time will be handle in library
	Info string `json:"Info"` // message from service/app want to print in log
}

type Detail

type Detail struct {
	StatusCode int         `json:"StatusCode"`
	Message    string      `json:"Message"`
	Data       interface{} `json:"Data,omitempty"`
}

type Headers

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

func (*Headers) ValiadateHeaderCsrf

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

func (*Headers) ValiadateHeaderIdem

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

type IRqAutoConnect added in v1.5.0

type IRqAutoConnect interface {
	StartConnection(username, password, host, port, vhost string) (c *amqp.Connection, err error)
	DeclareQueues(queues ...string) (err error)
	GetRqChannel() *amqp.Channel
	Stop()
	// contains filtered or unexported methods
}

IRqAutoConnect is interface defining method of rabbit mq auto connect

type MessagePayloadAudit

type MessagePayloadAudit struct {
	Id       int         `json:"Id"`
	Command  string      `json:"Command"`
	Time     string      `json:"Time"`
	ModuleId string      `json:"ModuleId"`
	Data     interface{} `json:"Data"`
}

type RabbitMQConnection added in v1.5.0

type RabbitMQConnection struct {
	Host, Port, Username, Password, VirtualHost, QueueName string
}

func (*RabbitMQConnection) GlobalConn added in v1.5.0

func (connection *RabbitMQConnection) GlobalConn()

func (*RabbitMQConnection) QueueConn added in v1.5.0

func (connection *RabbitMQConnection) QueueConn(RQ_QUEUE string)

type RabbitMQDefaultPayload added in v1.5.0

type RabbitMQDefaultPayload struct {
	Route string      `json:"command"`
	Param interface{} `json:"param"`
	Data  interface{} `json:"data"`
}

type Request

type Request struct {
	Time        string      `json:"Time"`
	Path        string      `json:"Path,omitempty"`
	QueryString interface{} `json:"QueryString,omitempty"`
	Header      interface{} `json:"Header,omitempty"`
	Param       interface{} `json:"Param,omitempty"`
	Body        interface{} `json:"Body,omitempty"`
	IpAddress   string      `json:"IpAddress,omitempty"`
	BrowserId   int         `json:"BrowserId,omitempty"`
	Latitude    string      `json:"Latitude,omitempty"`
	Longitude   string      `json:"Longitude,omitempty"`
}

type RequestAndResponse

type RequestAndResponse struct {
	Request  Request       `json:"Request"`
	Response ResponseAudit `json:"Response"`
}

type ResponseApi

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

func (*ResponseApi) Accepted

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

Accepted in process response

func (*ResponseApi) BadRequest

func (r *ResponseApi) BadRequest(message string, intenalCode string)

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, internalCode string, status string, data interface{})

func (*ResponseApi) Success

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

func (*ResponseApi) Unauthorized

func (r *ResponseApi) Unauthorized(message string, intenalCode string)

Unauthorized unauthorized user

type ResponseAudit

type ResponseAudit struct {
	Time   string `json:"Time"`
	Detail Detail `json:"Detail,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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