utility

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOG_OK    = "OK"
	LOG_INFO  = "INFO"
	LOG_DEBUG = "DEBUG"
	LOG_ERROR = "ERROR"
)

Variables

This section is empty.

Functions

func Debug

func Debug(code, message string, kv ...KVP)

Debug prints a debug log information.

func EncodeJSON

func EncodeJSON(v any) string

EncodeJSON marshals the body to produce a string format JSON.

func Error

func Error(err error, code, message string, kv ...KVP)

Error prints an error log information.

func Info

func Info(code, message string, kv ...KVP)

Info prints a log information.

func OK

func OK(code, message string, kv ...KVP)

OK prints an OK log information

func ParseJSON

func ParseJSON(data []byte, v any) error

ParseJSON unmarshal the JSON-encoded data and stores the result in the value pointed to by v.

Types

type KVP

type KVP struct {
	Key   string
	Value interface{}
}

KVP is a Key-Value Pair. Also called an attribute-value pair. It's a data representation in computing systems and applications

func (KVP) KeyValue

func (kv KVP) KeyValue() (string, interface{})

KeyValue returns the key and value of KVP

type Logs

type Logs struct {
	Code         string         `json:"log_code"`
	Message      any            `json:"log_msg"`
	ErrorMessage string         `json:"log_errmsg,omitempty"`
	Level        string         `json:"log_level"`
	Keys         map[string]any `json:"log_keys,omitempty"`
	TimeStamp    string         `json:"log_timestamp"`
}

func (*Logs) Print

func (log *Logs) Print()

Print marshal response JSON to print a string format JSON.

func (*Logs) SetKeys

func (l *Logs) SetKeys(key string, value any)

SetKeys checks if Log Keys are empty in order to create an empty map. If it's not empty, set its key-value pair.

func (*Logs) SetTimeStamp

func (l *Logs) SetTimeStamp()

SetTimeStamp sets the current timestamp with the ff. format: 2006-01-02 15:04:05.

Jump to

Keyboard shortcuts

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