utility

package
v0.0.0-...-026aa9f Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AppDir    string
	AppDirErr error
)

Functions

func Add

func Add(num1, num2 interface{}) float64

func AddQueryParam

func AddQueryParam(urlStr *string, paramKey string, paramValue string) error

func CleanStringInput

func CleanStringInput(input string) string

func CompareHash

func CompareHash(str string, hashed string) bool

func ConvertIntValues

func ConvertIntValues(m map[string]interface{})

func ConvertStringInterfaceToStringFloat

func ConvertStringInterfaceToStringFloat(originalMap map[string]interface{}) map[string]float64

func CopyStruct

func CopyStruct(src, dst interface{})

func EmailValid

func EmailValid(email string) (string, bool)

func FindTemplateFilePath

func FindTemplateFilePath(templateName string, templateTypePath string) (string, error)

func FormatDate

func FormatDate(date, currentISOFormat, newISOFormat string) (string, error)

func FormatInspectionPeriod

func FormatInspectionPeriod(t interface{}) string

func GenerateGroupByURL

func GenerateGroupByURL(appUrl, path string, querys map[string]string) string

func GenerateOTP

func GenerateOTP(max int) (int, error)

func GenerateUUID

func GenerateUUID() string

func GetConstants

func GetConstants(pkgImportPath string) (map[string]string, error)

func GetHeader

func GetHeader(c *gin.Context, key string) string

func GetRandomNumbersInRange

func GetRandomNumbersInRange(min, max int) int

func GetUnixString

func GetUnixString(date, currentISOFormat, newISOFormat string) (string, error)

func GetUnixTime

func GetUnixTime(date, currentISOFormat, newISOFormat string) (int, error)

func HashPassword

func HashPassword(str string) (string, error)

func Header2Map

func Header2Map(header http.Header) map[string]interface{}

func InIntSlice

func InIntSlice(value int, strSlice []int) bool

func InStringSlice

func InStringSlice(value string, strSlice []string) bool

func IsValidUUID

func IsValidUUID(id string) bool

func LogAndPrint

func LogAndPrint(logger *Logger, data interface{}, args ...interface{})

func NumberFormat

func NumberFormat(t interface{}) float64

func PercentageOf

func PercentageOf(actualNumber, percentage float64) float64

func PhoneValid

func PhoneValid(phone string) (string, bool)

func RandomString

func RandomString(length int) string

func RemoveKey

func RemoveKey(p interface{}, key string)

func RemoveString

func RemoveString(slice []string, s string) []string

func SpewResultForDebugging

func SpewResultForDebugging(description string, v interface{})

func Stripslashes

func Stripslashes(s string) string

func StructToMap

func StructToMap(obj interface{}) (map[string]interface{}, error)

func URLDecode

func URLDecode(encodedString string) (string, error)

func UrlHasQuery

func UrlHasQuery(urlString string) (bool, error)

func ValidationResponse

func ValidationResponse(err error, validate *validator.Validate) validator.ValidationErrorsTranslations

Types

type AuditLog

type AuditLog struct {
	Date           time.Time   `json:"date"`
	Username       string      `json:"Username"`
	RequestHeader  interface{} `json:"request_header"`
	Request        interface{} `json:"request"`
	StatusCode     int         `json:"status_code"`
	ResponseHeader interface{} `json:"response_header"`
	Response       interface{} `json:"response"`
	ClientID       string      `json:"client_id"`
	Route          string      `json:"route"`
	Duration       float64     `json:"duration (seconds)"`
}

AuditLog Audit log

type LogRecord

type LogRecord struct {
	Level    string // The log level
	Date     string // The time at which the log message was created (nanoseconds)
	Source   string // The message source
	Message  string // The log message
	Category string // The log group
}

type Logger

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

Logger application logger

func NewLogger

func NewLogger() *Logger

NewLogger constructs a logger object

func (*Logger) Audit

func (l *Logger) Audit(record *AuditLog)

Audit : log information on api request and response

func (*Logger) Debug

func (l *Logger) Debug(arg0 interface{}, args ...interface{})

Debug log debug

func (*Logger) Error

func (l *Logger) Error(arg0 interface{}, args ...interface{})

Error log errors

func (*Logger) Fatal

func (l *Logger) Fatal(arg0 interface{}, args ...interface{})

Fatal log fatal errors

func (*Logger) Info

func (l *Logger) Info(arg0 interface{}, args ...interface{})

Info log information

func (*Logger) Warning

func (l *Logger) Warning(arg0 interface{}, args ...interface{})

Warning log warnings

type Response

type Response struct {
	Status     string      `json:"status,omitempty"`
	StatusCode int         `json:"status_code,omitempty"`
	Name       string      `json:"name,omitempty"` //name of the error
	Message    string      `json:"message,omitempty"`
	Error      interface{} `json:"error,omitempty"` //for errors that occur even if request is successful
	Data       interface{} `json:"data,omitempty"`
	Pagination interface{} `json:"pagination,omitempty"`
	Extra      interface{} `json:"extra,omitempty"`
}

func BuildErrorResponse

func BuildErrorResponse(code int, status string, message string, err interface{}, data interface{}, logger ...bool) Response

BuildErrorResponse method is to inject data value to dynamic failed response

func BuildSuccessResponse

func BuildSuccessResponse(code int, message string, data interface{}, pagination ...interface{}) Response

BuildResponse method is to inject data value to dynamic success response

func ResponseMessage

func ResponseMessage(code int, status string, name string, message string, err interface{}, data interface{}, pagination interface{}, extra interface{}) Response

ResponseMessage method for the central response holder

func UnauthorisedResponse

func UnauthorisedResponse(code int, status string, name string, message string) Response

Jump to

Keyboard shortcuts

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