utils

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 27 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 CleanWikiaComment

func CleanWikiaComment(str string) string

CleanWikiaComment to remove wikia comment.

func CleanWikiaTag

func CleanWikiaTag(str, tag string, deleteContent bool) string

CleanWikiaTag to remove wikia tag.

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 GenerateUUID added in v0.18.0

func GenerateUUID() string

GenerateUUID to generate random uuid.

func GetKey

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

GetKey to generate cache key.

func GetLastPathFromURL added in v0.10.0

func GetLastPathFromURL(str string) string

GetLastPathFromURL to get the last path from url.

func GetLogger

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

GetLogger to get logger.

func GetWikiaExternalLink(str string) string

GetWikiaExternalLink to get wikia external link.

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 NormalizeNewLine

func NormalizeNewLine(str string) string

NormalizeNewLine to normalize new line to <br>.

func NormalizeWikiaInternalLink(str string) string

NormalizeWikiaInternalLink to normalize wikia internal link. [[NIJISANJI (main branch)|NIJISANJI]] => [[NIJISANJI]]

func ParseDuration added in v0.10.0

func ParseDuration(durationStr string, startFromTime ...bool) (time.Duration, error)

ParseDuration to parse ISO 8601 duration.

func PtrToBool added in v0.6.0

func PtrToBool(b *bool) bool

PtrToBool to convert pointer to bool.

func QueryToKey added in v0.6.0

func QueryToKey(query interface{}) string

QueryToKey to convert query to key string.

func RandomStr added in v0.18.0

func RandomStr(n int) string

RandomStr to generate random string.

func Recoverer

func Recoverer(next http.Handler) http.Handler

Recoverer is custom recoverer middleware. Will return 500.

func RemoveAllHTMLTag

func RemoveAllHTMLTag(str string) string

RemoveAllHTMLTag to remove all html tag.

func ResponseWithJSON

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

ResponseWithJSON to write response with JSON format.

func ResponseWithPNG added in v0.2.0

func ResponseWithPNG(w http.ResponseWriter, code int, data []byte, err error)

ResponseWithPNG to write response with PNG.

func StrToPtrBool added in v0.6.0

func StrToPtrBool(str string) *bool

StrToPtrBool to convert string to bool pointer.

func StrToStrSlice added in v0.7.0

func StrToStrSlice(str string) []string

StrToStrSlice to convert string to slice of string.

func Validate

func Validate(data interface{}) error

Validate to validate struct using validate tag. Use pointer.

func WikiaExternalLinkToStr

func WikiaExternalLinkToStr(str string) string

WikiaExternalLinkToStr to convert wikia external link to string.

func WikiaInternalLinkToStr

func WikiaInternalLinkToStr(str string) string

WikiaInternalLinkToStr to convert wikia internal link to string.

Types

type LogLevel added in v0.17.1

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