util

package
v0.1.1-0...-94ed833 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 14 Imported by: 9

Documentation

Index

Constants

View Source
const (
	//GET is a GET request type
	GET = iota + 1
	//POST is a POST request type
	POST
)

Variables

This section is empty.

Functions

func CreateTestClient

func CreateTestClient(client *http.Client, fn RoundTripFunc)

CreateTestClient returns *http.Client with Transport replaced to avoid making real calls

func FormatERC20Balance

func FormatERC20Balance(balance *big.Int) string

func HTTPWithRetries

func HTTPWithRetries(req *HTTPFetchRequest) ([]byte, error)

HTTPWithRetries will keep trying the given request until non-error result or timeout

func ParseLoggingConfig

func ParseLoggingConfig(file string) error

ParseLoggingConfig parses the given JSON log level config file for use in log configuration

func ParsePayload

func ParsePayload(payload []byte, args [][]string) ([]float64, error)

ParsePayload will extract the value from a query payload

func ParseQueryString

func ParseQueryString(_query string) (url string, args [][]string)

ParseQueryString extracts the url and any args for extract values from query result payload

Types

type ContextKey

type ContextKey string

ContextKey string key for context value lookups

func NewKey

func NewKey(pkg string, name string) ContextKey

NewKey creates a new context string key using a package and name designator

type Entry

type Entry struct {
	Level     string `json:"level"`
	Component string `json:"component"`
}

Entry holds specific component log level

type HTTPFetchRequest

type HTTPFetchRequest struct {
	Method   int
	QueryURL string
	Payload  []byte
	Timeout  time.Duration
}

HTTPFetchRequest holds info for a request

type LogConfig

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

LogConfig holds individual log level settings

func GetLoggingConfig

func GetLoggingConfig() *LogConfig

GetLoggingConfig retrieves a shared logging config

func (*LogConfig) GetLevel

func (cfg *LogConfig) GetLevel(pkg string, component string) LogLevel

GetLevel the log level

type LogLevel

type LogLevel uint

LogLevel represents possible log levels

const (
	//ErrorLogLevel will only log error messages
	ErrorLogLevel LogLevel = iota + 1

	//WarningLogLevel will only log warnings
	WarningLogLevel

	//InfoLogLevel will only log infos
	InfoLogLevel

	//DebugLogLevel will only log debugs
	DebugLogLevel
)

func StringToLevel

func StringToLevel(level string) (LogLevel, error)

StringToLevel converts a string named log level into a level ot use for setting log levels

type Logger

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

Logger is the log implementation that wraps underlying logging mechanism

func NewLogger

func NewLogger(pkg string, component string) *Logger

NewLogger creates a log instance for the given component with the given log level enabled

func (*Logger) Debug

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

Debug log a debug message

func (*Logger) Error

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

Error log an error message

func (*Logger) Info

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

Info message logging

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...interface{})

Warn log a warning message

type QueryStruct

type QueryStruct struct {
	Order     []int
	Arrays    interface{}            `json:"-"`
	Arguments map[string]interface{} `json:"-"`
}

QueryStruct holds query result fields as a map

type RoundTripFunc

type RoundTripFunc func(req *http.Request) *http.Response

RoundTripFunc The mock interface to implement. Can be configured to return a hardcoded response or a response that depends on the request

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip The method called by transport to get a response

Jump to

Keyboard shortcuts

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