dtbgoutils

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DateTime = "2006-01-02 15:04:05"
View Source
const KeyRequestId = "Request-Id"
View Source
const KeyTerminalId = "Terminal-Id"
View Source
const RemoteDefaultReadTimeout = 40 * time.Second

Variables

View Source
var ConfigMapKeys []EnvConfigMap
View Source
var ConfigMapValues = map[EnvConfigMap]string{}
View Source
var ErrorTypeNames = []string{
	"Undefined",
	"User",
	"Hardware",
	"Technical",
	"Internal",
	"Network",
	"Parameter",
	"Host",
	"Protocol",
}
View Source
var GlBuildDate string
View Source
var GlErrorDataMap = map[ErrorCode]ErrorData{
	ErrCodeAuth:       {"Authentication Failed", ErrorTypeInternal},
	ErrCodeBadData:    {"Bad Data %s", ErrorTypeParameter},
	ErrCodeServer:     {"Server Error %s", ErrorTypeTechnical},
	ErrCodeConnection: {"Connection Failure %s", ErrorTypeNetwork},
	ErrCodeNotFound:   {"Not Found %s", ErrorTypeTechnical},
	ErrCodeConfig:     {"Config Error %s", ErrorTypeTechnical},
}
View Source
var GlHeaders = []string{
	KeyRequestId,
	"Device-Id",
	"Operation-Id",
	"Signature",
	"Device-Model",
	"Device-Os",
	"Platform",
	"X-Real-Ip",
	"User-Agent",
	"Cipher-V",
	"Request-T",

	KeyTerminalId,
	"Term-App-Name",
	"Model",
	"terminalModel",
	"pos_firmware",
	"Terminal-Datetime",
	"Remote-Addr",
	"Program-Name",
	"App-build",
	"Manufacturer",
	"Request-t",
	"X-Request-Id",

	"Accept-Language",
	"Accept-Charset",
	"Authorization",
	"Content-Type",
	"application",

	"Brc",

	"Username",
	"Password",

	"ProviderIg",
	"Providerpwd",
	"Userlanguage",
	"Userid",
	"Reader-Id",
}
View Source
var GlHostName string
View Source
var GlProcessName string
View Source
var GlRedisClient *redis.Client
View Source
var GlRunMode string
View Source
var GlVersion string
View Source
var GlogWriter *gelf.Writer
View Source
var HeadersForTrace = []string{
	"X-Request-Id",
	"X-B3-Traceid",
	"X-Ot-Span-Context",
}

Functions

func BHLog

func BHLog(in interface{}) interface{}

BHLog : BoobHolder, BloodyHell, BrokenHearted, BountyHunter, BlackHole,

func GenerateKCV added in v0.0.10

func GenerateKCV(key []byte) string

func GenerateKCVByte added in v0.0.10

func GenerateKCVByte(key []byte, calcSize int) []byte

func GetFileAndLine added in v0.0.8

func GetFileAndLine() string

func GorillaLoggingHandler added in v0.0.13

func GorillaLoggingHandler(router *mux.Router) http.Handler

func LoadErrorMap added in v0.0.5

func LoadErrorMap(errMap map[ErrorCode]ErrorData)

func LogCritical

func LogCritical(format string, args ...interface{})

func LogDebug

func LogDebug(format string, args ...interface{})

func LogError

func LogError(format string, args ...interface{})

func LogFilter

func LogFilter(in interface{}) string

func LogInfo

func LogInfo(format string, args ...interface{})

func LogWarning

func LogWarning(format string, args ...interface{})

func LoggingHandler added in v0.0.13

func LoggingHandler(router *http.ServeMux) http.Handler

func MaskCVV

func MaskCVV(cvv string) string

MaskCVV : 123 -> ***

func MaskDate

func MaskDate(date string) string

MaskDate

06/23 2023-06 2016-02-24T00:30-0800 2009-06-15T13:45:30 2009-06-15T13:45:30.0000000 2009-06-15T13:45:30.0000000Z Mon, 15 Jun 2009 20:45:30 GMT

func MaskName

func MaskName(inData string) string

MaskName : Dorj -> Do**

func MaskPan

func MaskPan(inData string) string

MaskPan :

func MaskPhone

func MaskPhone(inData string) string

MaskPhone :99119911 -> xxxxxx11

func PingHandler added in v0.0.7

func PingHandler(w http.ResponseWriter, r *http.Request)

func ZeroPadding added in v0.0.10

func ZeroPadding(ciphertext []byte, blockSize int) []byte

ZeroPadding :

Types

type BaseErrorType

type BaseErrorType struct {
	Code      ErrorCode     `json:"code"`
	Message   string        `json:"message"`
	Module    string        `json:"module"`
	FormError interface{}   `json:"form_error"`
	Level     ErrorTypeEnum `json:"level"`
}

func HttpRequester

func HttpRequester(rd RequestData, log *strings.Builder) *BaseErrorType

func NewErrorByCode

func NewErrorByCode(code ErrorCode, a ...interface{}) *BaseErrorType

func TripleDesDecrypt added in v0.0.10

func TripleDesDecrypt(ede2Key []byte, src []byte) ([]byte, *BaseErrorType)

func TripleDesEncrypt added in v0.0.10

func TripleDesEncrypt(ede2Key []byte, src []byte) ([]byte, *BaseErrorType)

TripleDesEncrypt :

type DefaultResp added in v0.0.7

type DefaultResp struct {
	Status string `json:"status_code"`
	Msg    string `json:"msg,omitempty"`
}

type EnvConfigMap

type EnvConfigMap string

type ErrorCode

type ErrorCode string
const (
	ErrCodeAuth       ErrorCode = "001"
	ErrCodeBadData    ErrorCode = "002"
	ErrCodeServer     ErrorCode = "005"
	ErrCodeConnection ErrorCode = "006"
	ErrCodeNotFound   ErrorCode = "007"
	ErrCodeConfig     ErrorCode = "008"
)

type ErrorData

type ErrorData struct {
	Message string
	Level   ErrorTypeEnum
}

type ErrorTypeEnum

type ErrorTypeEnum int
const (
	ErrorTypeUndefined ErrorTypeEnum = iota
	ErrorTypeUser
	ErrorTypeHardware
	ErrorTypeTechnical
	ErrorTypeInternal
	ErrorTypeNetwork
	ErrorTypeParameter
	ErrorTypeHost
	ErrorTypeProtocol
)

type LocalizedErrorData

type LocalizedErrorData struct {
	MessageMN string
	MessageEN string
	ErrType   ErrorTypeEnum
}

type Options

type Options struct {
	ProcessName             string
	ConfMapKeyGrayLog       EnvConfigMap
	ConfMapKeyRedisDB       EnvConfigMap
	ConfigMapKeyRedisAddr   EnvConfigMap
	ConfigMapKeyRedisPrefix EnvConfigMap
	ConfigMapKeys           []EnvConfigMap
	ConfigMapValues         map[EnvConfigMap]string
	BaseErrorMap            *map[ErrorCode]ErrorData
	LocalizedErrorMap       *map[string]LocalizedErrorData
	LogHeaders              []string
	ConfigRabbitHost        string
	ConfigRabbitQueue       string
}
var GlOption *Options

func (*Options) Init added in v0.0.5

func (opt *Options) Init()

type PingResp added in v0.0.7

type PingResp struct {
	DefaultResp
	Ret struct {
		ResponseCode string    `json:"response_code,omitempty"`
		ResponseMsg  string    `json:"response_msg,omitempty"`
		BuildDate    string    `json:"build_date"`
		ServiceName  string    `json:"service_name,omitempty"`
		Version      string    `json:"version"`
		RunMode      string    `json:"run_mode"`
		StartTime    time.Time `json:"start_time,omitempty"`
		Info         string    `json:"info,omitempty"`
	} `json:"ret,omitempty"`
}

type ReqInfo

type ReqInfo struct {
	Req          *http.Request     `json:"-"`
	RequestHeads map[string]string `json:"headers,omitempty"`
	StartTime    time.Time         `json:"-"`
	Log          *strings.Builder  `json:"-"`
	Context      context.Context   `json:"-"`
	LocaleCode   string            `json:"locale"`
}

func (*ReqInfo) HttpReq

func (r *ReqInfo) HttpReq(rd RequestData) *BaseErrorType

func (*ReqInfo) LogCritical

func (r *ReqInfo) LogCritical(format string, args ...interface{})

func (*ReqInfo) LogDebug

func (r *ReqInfo) LogDebug(format string, args ...interface{})

func (*ReqInfo) LogError

func (r *ReqInfo) LogError(format string, args ...interface{})

func (*ReqInfo) LogInfo

func (r *ReqInfo) LogInfo(format string, args ...interface{})

func (*ReqInfo) LogWarning

func (r *ReqInfo) LogWarning(format string, args ...interface{})

func (*ReqInfo) ReqInfoFill

func (r *ReqInfo) ReqInfoFill(req *http.Request)

func (*ReqInfo) ReqInfoGenerate

func (r *ReqInfo) ReqInfoGenerate()

func (*ReqInfo) RequestId

func (r *ReqInfo) RequestId() string

func (*ReqInfo) RespGZipJson added in v0.0.15

func (r *ReqInfo) RespGZipJson(w http.ResponseWriter, data interface{})

func (*ReqInfo) RespJson added in v0.0.15

func (r *ReqInfo) RespJson(w http.ResponseWriter, data interface{})

type RequestData

type RequestData struct {
	Req          *http.Request
	ReqInfo      *ReqInfo
	ReqAddr      *EnvConfigMap
	ReqPath      string
	Timeout      *time.Duration
	FullURL      string
	Method       string
	ReqByte      []byte
	RespByte     []byte
	FormData     map[string]string
	Body         interface{}
	Resp         interface{}
	RespText     *strings.Builder
	Client       *http.Client
	CustomHeader *http.Header
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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