utils

package
v0.0.0-...-28e02bd Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BASE string

BASE represents /base path of dbs2go end-point

View Source
var Localhost string

Localhost represents localhost name (with port) which can be used for local HTTP requests

View Source
var ORACLE bool

ORACLE represents a flag that underlying DB is oracle

View Source
var STATICDIR string

STATICDIR holds location of static directory for dbs2go

View Source
var UrlCounter uint32

UrlCounter for profile output

View Source
var VERBOSE int

VERBOSE controls verbosity level of the package

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 Diff

func Diff[T ListEntry](a, b []T) []T

Diff provides a slice of the different elements from a and b

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

type ProcFS struct {
	CpuTotal      float64
	Vsize         float64
	Rss           float64
	OpenFDs       float64
	MaxFDs        float64
	MaxVsize      float64
	UserCPUs      []float64
	SystemCPUs    []float64
	SumUserCPUs   float64
	SumSystemCPUs float64
}

ProcFS represents prometheus profcs metrics

func ProcFSMetrics

func ProcFSMetrics() ProcFS

ProcFSMetrics returns procfs (prometheus) metrics

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