utils

package
v0.11.11 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLog

func AddLog(l1 _log.Logger)

AddLog to add logger chain.

func Error

func Error(str string, args ...interface{})

Error to print error.

func Fatal

func Fatal(str string, args ...interface{})

Fatal to log fatal.

func GetKey

func GetKey(params ...interface{}) string

GetKey to generate cache key.

func GetLogger

func GetLogger(i ...int) _log.Logger

GetLogger to get logger.

func Info

func Info(str string, args ...interface{})

Info to log info.

func InitLog

func InitLog(lvl LogLevel, json, color bool)

InitLog to init global logger.

func Log

func Log(field map[string]interface{})

Log to log with custom field.

func ParseToBoolPtr added in v0.9.0

func ParseToBoolPtr(str string) *bool

ParseToBoolPtr to parse str to bool pointer.

func ParseToTimePtr added in v0.9.0

func ParseToTimePtr(layout, str string) *time.Time

ParseToTimePtr to parse str to time pointer.

func Recoverer

func Recoverer(next http.Handler) http.Handler

Recoverer is custom recoverer middleware. Will return 500.

func RecovererGRPC

func RecovererGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (_ interface{}, err error)

RecovererGRPC is custom recoverer middleware.

func ResponseWithGRPC

func ResponseWithGRPC(code int, err error) error

ResponseWithGRPC to convert http response code and error message to grpc error format.

func ResponseWithJSON

func ResponseWithJSON(w http.ResponseWriter, code int, data interface{}, err error, meta ...interface{})

ResponseWithJSON to write response with JSON format.

func SplitDate

func SplitDate(date string) (year int, month int, day int, err error)

SplitDate will split string format to year,month,day. 2020-01-02 => 2020,1,2 2020-01 => 2020,1,0 2020 => 2020,0,0

func Validate

func Validate(data interface{}) error

Validate to validate struct using validate tag. Use pointer.

Types

type LogLevel added in v0.11.7

type LogLevel int8

LogLevel is level of log that will be printed. Will print level that is higher than your chosen one.

const (
	TraceLevel LogLevel = iota - 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel
	Disabled
)

Available log level.

type Response

type Response struct {
	Status  int         `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data" swaggertype:"object"`
	Meta    interface{} `json:"meta" swaggertype:"object"`
}

Response is standard api response model.

Jump to

Keyboard shortcuts

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