utils

package module
v0.0.0-...-a4c08c0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TIMEOUT int

TIMEOUT defines timeout for net/url request

View Source
var UrlCounter uint32

UrlCounter for profile output

View Source
var VERBOSE int

VERBOSE defines verbosity level

View Source
var Verbose int

Verbose controls verbosity level of function printouts

Functions

func BasePath

func BasePath(base, api string) string

BasePath function provides end-point path for given api string

func CastFloat

func CastFloat(val interface{}) (float64, error)

CastFloat function to check and cast interface{} to int64 data-type

func CastInt

func CastInt(val interface{}) (int, error)

CastInt function to check and cast interface{} to int data-type

func CastInt64

func CastInt64(val interface{}) (int64, error)

CastInt64 function to check and cast interface{} to int64 data-type

func CastString

func CastString(val interface{}) (string, error)

CastString function to check and cast interface{} to string data-type

func ConvertFloat

func ConvertFloat(val string) string

ConvertFloat converts string representation of float scientific number to string int

func Equal

func Equal[T ListEntry](a, b []T) bool

Equal tells whether a and b contain the same elements. A nil argument is equivalent to an empty slice.

func ErrPropagate

func ErrPropagate(api string)

ErrPropagate helper function which can be used in defer ErrPropagate()

func ErrPropagate2Channel

func ErrPropagate2Channel(api string, ch chan interface{})

ErrPropagate2Channel helper function which can be used in goroutines as ch := make(chan interface{})

go func() {
   defer ErrPropagate2Channel(api, ch)
   someFunction()
}()

func GetHash

func GetHash(data []byte) string

GetHash generates SHA256 hash for given data blob

func GoDeferFunc

func GoDeferFunc(api string, f func())

GoDeferFunc runs any given function in defered go routine

func HttpClient

func HttpClient() *http.Client

HttpClient provides cert/token aware HTTP client

func HttpGet

func HttpGet(rurl string, headers map[string]string) (*http.Response, error)

HttpGet performs HTTP GET request with bearer token

func HttpPost

func HttpPost(rurl string, headers map[string]string, buffer *bytes.Buffer) (*http.Response, error)

HttpPost performs HTTP POST request with bearer token

func HttpPostForm

func HttpPostForm(rurl string, headers map[string]string, formData url.Values) (*http.Response, error)

HttpPostForm performs HTTP POST form request with bearer token

func InList

func InList[T ListEntry](a T, list []T) bool

InList checks item in a list

func Insert

func Insert(arr []interface{}, val interface{}) []interface{}

Insert inserts value into array at zero position

func ListFiles

func ListFiles(dir string) []string

ListFiles lists files in a given directory

func MapIntKeys

func MapIntKeys(rec map[int]interface{}) []int

MapIntKeys returns int keys from a map

func MapKeys

func MapKeys(rec map[string]interface{}) []string

MapKeys returns string keys from a map

func OrderedSet

func OrderedSet[T ListEntry](list []T) []T

OrderedSet implementa ordered set

func ParseTmpl

func ParseTmpl(tdir, tmpl string, data interface{}) (string, error)

ParseTmpl parses template with given data

func PrintSQL

func PrintSQL(stm string, args []interface{}, msg string)

PrintSQL prints SQL/args

func ReadToken

func ReadToken(r string) string

ReadToken function to either read file content or return given string

func RecordSize

func RecordSize(v interface{}) (int64, error)

RecordSize returns actual record size of given interface object

func ReplaceBinds

func ReplaceBinds(stm string) string

ReplaceBinds replaces given pattern in string

func Response

func Response(rurl string, data []byte) []byte

Response represents final response in a form of JSON structure we use custorm representation

func Set

func Set[T ListEntry](arr []T) []T

Set converts input list into set

func Stack

func Stack() string

Stack returns full runtime stack

func UpdateOrderedDict

func UpdateOrderedDict(omap, nmap map[int][]string) map[int][]string

UpdateOrderedDict returns new ordered list from given ordered dicts

Types

type DevNullWriter

type DevNullWriter string

DevNullWriter provides the same functionality as http.ResponseWriter to cover unit tests of DBS APIs. It prints given data directly to stdout.

func (DevNullWriter) Header

func (s DevNullWriter) Header() http.Header

Header implements Header() API of http.ResponseWriter interface

func (DevNullWriter) Write

func (s DevNullWriter) Write(b []byte) (int, error)

Write implements Write API of http.ResponseWriter interface

func (DevNullWriter) WriteHeader

func (s DevNullWriter) WriteHeader(statusCode int)

WriteHeader implements WriteHeader API of http.ResponseWriter interface

type GzipReader

type GzipReader struct {
	*gzip.Reader
	io.Closer
}

GzipReader struct to handle GZip'ed content of HTTP requests

func (GzipReader) Close

func (gz GzipReader) Close() error

Close function closes gzip reader

type GzipWriter

type GzipWriter struct {
	GzipWriter *gzip.Writer
	Writer     http.ResponseWriter
}

GzipWriter provides the same functionality as http.ResponseWriter It compresses data using compress/zip writer and provides headers from given http.ResponseWriter

func (GzipWriter) Header

func (g GzipWriter) Header() http.Header

Header implements Header() API of http.ResponseWriter interface

func (GzipWriter) Write

func (g GzipWriter) Write(b []byte) (int, error)

Write implements Write API of http.ResponseWriter interface

func (GzipWriter) WriteHeader

func (g GzipWriter) WriteHeader(statusCode int)

WriteHeader implements WriteHeader API of http.ResponseWriter interface

type ListEntry

type ListEntry interface {
	int | int64 | float64 | string
}

ListEntry identifies types used by list's generics function

type ResponseType

type ResponseType struct {
	Url        string // response url
	Data       []byte // response data, i.e. what we got with Body of the response
	Error      error  // http error, a non-2xx return code is not an error
	Status     string // http status string
	StatusCode int    // http status code
}

ResponseType structure is what we expect to get for our URL call. It contains a request URL, the data chunk and possible error from remote

func FetchResponse

func FetchResponse(rurl string, args []byte) ResponseType

FetchResponse fetches data for provided URL, args is a json dump of arguments

type StdoutWriter

type StdoutWriter string

StdoutWriter provides the same functionality as http.ResponseWriter to cover unit tests of DBS APIs. It prints given data directly to stdout.

func (StdoutWriter) Header

func (s StdoutWriter) Header() http.Header

Header implements Header() API of http.ResponseWriter interface

func (StdoutWriter) Write

func (s StdoutWriter) Write(b []byte) (int, error)

Write implements Write API of http.ResponseWriter interface

func (StdoutWriter) WriteHeader

func (s StdoutWriter) WriteHeader(statusCode int)

WriteHeader implements WriteHeader API of http.ResponseWriter interface

Jump to

Keyboard shortcuts

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