utils

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLog

func AddLog(l1 log.Logger, l2 ...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(t log.LogType, lvl log.LogLevel, json, color bool) (err error)

InitLog to init global logger.

func Log

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

Log to log with custom field.

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 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