Documentation
¶
Overview ¶
this middleware function is to revoke token jwt if status user blocked or suspend
Index ¶
- Constants
- Variables
- func AcquireLock(key string, ttl time.Duration) (bool, error)
- func AcquireLockWithRetry(key string, ttl time.Duration, maxRetries int, retryDelay time.Duration) (*redsync.Mutex, bool, error)
- func AddValidatorLibs()
- func DeleteRedis(id string) (err error)
- func GetAppEnv() string
- func GetAppName() string
- func GetMutex(key string) *redsync.Mutex
- func GetRedis(id string) (result string, err error)
- func GetRedisClient(redisHost, redisPort, redisPassword string, redisDb int) error
- func GetRedisOptions() *redis.Options
- func GetRedisPoolClient() (*redis.Client, error)
- func GetSentryClient() *sentry.Client
- func GetSentryClientOptions() *sentry.ClientOptions
- func GetSentryData() *phsentry.SentryData
- func GetTrxRedisBackoff() int
- func GetTrxRedisLockTimeout() time.Duration
- func InitRedSyncOnce() error
- func InitRedisOptions(rawOpt redis.Options) *redis.Options
- func InitSentry(options phsentry.SentryOptions) *sentry.Client
- func InitSentryOptions(options phsentry.SentryOptions)
- func InitializeApp()
- func InitializeLogger()
- func InitializeRedis(opt redis.Options)
- func JSONEncode(obj interface{}) string
- func JsonMinify(jsonB []byte) ([]byte, error)
- func LogAudittrailData(funcName, desc, source, commType string, key *[]string, ...)
- func LogAudittrailProcess(funcName, desc, info string, key *[]string)
- func LogErr(err error)
- func LogJ(arg interface{})
- func LogJI(arg interface{})
- func LogSetLevel(levelName string)
- func LoggerErrorHub(err interface{}, args ...interface{})
- func NewAmqp(addr string, c *AmqpClient)
- func NewSentryData(dt *phsentry.SentryData)
- func ReadBody(c echo.Context, idem string) (map[string]interface{}, string, error)
- func ReleaseLock(key string) error
- func ReleaseLockWithRetry(mutex *redsync.Mutex, maxRetries int) error
- func RemoveMutex(key string)
- func RevokeToken(next echo.HandlerFunc) echo.HandlerFunc
- func SendSentryDebug(err error, args ...string)
- func SendSentryError(err error, args ...string)
- func SendSentryEvent(event *sentry.Event, args ...string)
- func SendSentryMessage(msg string, args ...string)
- func SendSentryWarning(err error, args ...string)
- func SendToSentryDebug(err error, service, module, function string)
- func SendToSentryError(err error, service, module, function string)
- func SendToSentryEvent(event *sentry.Event, service, module, function string)
- func SendToSentryMessage(message string, service, module, function string)
- func SendToSentryWarning(err error, service, module, function string)
- func SetAppEnv(v string)
- func SetAppName(v string)
- func StoreMutex(key string, mutex *redsync.Mutex)
- func StoreRedis(id string, data interface{}, duration time.Duration) (err error)
- func StoreRedisWithLock(id string, data interface{}, duration time.Duration) (err error)
- func ToJson(data interface{}) string
- func ToJsonIndent(data interface{}) string
- func VerifCsrf(next echo.HandlerFunc) echo.HandlerFunc
- func VerifIdemKey(next echo.HandlerFunc) echo.HandlerFunc
- func VerifyMD5(idemKey string, request []byte) (string, error)
- type AmqpClient
- func (c *AmqpClient) AmqpConfig() amqp.Config
- func (c *AmqpClient) Cc() error
- func (c *AmqpClient) Channel() *amqp.Channel
- func (c *AmqpClient) Close() error
- func (c *AmqpClient) ConnName() string
- func (c *AmqpClient) Consume() (<-chan amqp.Delivery, error)
- func (c *AmqpClient) ErrLog() *log.Logger
- func (c *AmqpClient) InfoLog() *log.Logger
- func (c *AmqpClient) Push(data []byte) error
- func (c *AmqpClient) SetAmqpConfig(amqpConfig *amqp.Config)
- func (c *AmqpClient) UnsafePush(data []byte) error
- type AuditTrailData
- type AuditTrailProcess
- type DataAuditTrailProcess
- type Detail
- type Headers
- type IRqAutoConnect
- type MessagePayloadAudit
- type RabbitMQConnection
- type RabbitMQDefaultPayload
- type Request
- type RequestAndResponse
- type ResponseApi
- func (r *ResponseApi) Accepted(data interface{})
- func (r *ResponseApi) BadRequest(message string, intenalCode string)
- func (r *ResponseApi) InternalServerError(err error)
- func (r *ResponseApi) Out(code int, message, internalCode string, status string, data interface{})
- func (r *ResponseApi) Success(message string, data interface{})
- func (r *ResponseApi) Unauthorized(message string, intenalCode string)
- type ResponseAudit
Constants ¶
const ( CmdAuditTrailProcess = "audit-trail-process" CmdAuditTrailData = "audit-trail-data" )
const ( Numeric string = "^-?[0-9]+$" Key string = "^[-a-zA-Z0-9_-]+$" )
Variables ¶
var ( Log = phlogger.Log LogD = Log.Debugf LogI = Log.Infof LogW = Log.Warnf LogE = Log.Errorf LogF = Log.Fatalf Logf = Log.Logf )
var (
DefaultRedisTimeout = 1000 * time.Millisecond
)
var GinLevel golog.Level = phlogger.GinLevel
Functions ¶
func AcquireLock ¶ added in v1.6.3
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 GetAppName ¶ added in v1.4.0
func GetAppName() string
func GetRedisClient ¶
func GetRedisOptions ¶ added in v1.4.0
func GetRedisPoolClient ¶ added in v1.4.0
func GetSentryClient ¶ added in v1.5.1
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 InitRedSyncOnce ¶ added in v1.6.3
func InitRedSyncOnce() error
InitRedSyncOnce initializes the redSync instance once
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 JSONEncode ¶
func JSONEncode(obj interface{}) string
func JsonMinify ¶
func LogAudittrailData ¶
func LogAudittrailData(funcName, desc, source, commType string, key *[]string, data *RequestAndResponse)
LogAudittrailData add audittrail data
func LogAudittrailProcess ¶
LogAudittrailProcess add audittrail process
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 ReleaseLock ¶ added in v1.6.3
func ReleaseLockWithRetry ¶ added in v1.6.3
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 SendSentryError ¶ added in v1.5.0
func SendSentryEvent ¶ added in v1.5.0
func SendSentryMessage ¶ added in v1.5.0
func SendSentryWarning ¶ added in v1.5.0
func SendToSentryDebug ¶ added in v1.5.1
func SendToSentryError ¶ added in v1.5.1
func SendToSentryEvent ¶ added in v1.5.1
func SendToSentryMessage ¶ added in v1.5.1
func SendToSentryWarning ¶ added in v1.5.1
func SetAppName ¶ added in v1.4.0
func SetAppName(v string)
func StoreMutex ¶ added in v1.6.3
StoreMutex stores a mutex in the map for later release
func StoreRedisWithLock ¶ added in v1.6.3
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
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 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 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