misc

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RFC3339Milli with milli sec precision
	RFC3339Milli = "2006-01-02T15:04:05.000Z07:00"
)

Variables

View Source
var AppStartTime int64

Functions

func AddFileToZip

func AddFileToZip(zipWriter *zip.Writer, filename string) error

AddFileToZip adds file to zip including size header stats

func AppendError added in v0.1.10

func AppendError(callingMethodName string, firstError *error, secondError *error)

AppendError creates or appends second error to first error

func ConcatErrors added in v0.1.10

func ConcatErrors(givenErrors []error) error

func Contains

func Contains(in interface{}, elem interface{}) bool

Contains returns true if an element is present in a iteratee. https://github.com/thoas/go-funk

func ContainsString

func ContainsString(slice []string, str string) bool

func ConvertStringInterfaceToIntArray added in v0.1.10

func ConvertStringInterfaceToIntArray(interfaceT interface{}) ([]int64, error)

func Copy

func Copy(dst, src interface{})

Copy copies the exported fields from src to dest Used for copying the default transport

func CreateTMPDIR

func CreateTMPDIR() (string, error)

CreateTMPDIR creates tmp dir at path configured via RUDDER_TMPDIR env var

func GetChronologicalTimeStamp

func GetChronologicalTimeStamp(receivedAt, sentAt, originalTimestamp time.Time) time.Time

 Returns chronological timestamp of the event using the formula  timestamp = receivedAt - (sentAt - originalTimestamp)

func GetHash added in v0.1.10

func GetHash(s string) int

func GetIPFromReq

func GetIPFromReq(req *http.Request) string

GetIPFromReq gets ip address from request

func GetMD5Hash

func GetMD5Hash(input string) string

GetMD5Hash returns EncodeToString(md5 hash of the input string)

func GetMD5UUID added in v0.1.10

func GetMD5UUID(str string) (uuid.UUID, error)

GetMD5UUID hashes the given string into md5 and returns it as auuid

func GetMacAddress

func GetMacAddress() string

func GetMandatoryJSONFieldNames added in v0.1.10

func GetMandatoryJSONFieldNames(st interface{}) []string

GetMandatoryJSONFieldNames returns all the json field names defined against the json tag for each field.

func GetNodeID added in v0.1.10

func GetNodeID() string

GetNodeID returns the nodeId of the current node

func GetObjectStorageConfig added in v0.1.10

func GetObjectStorageConfig(opts ObjectStorageOptsT) map[string]interface{}

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

GetOutboundIP returns preferred outbound ip of this machine https://stackoverflow.com/a/37382208

func GetParsedTimestamp added in v0.1.10

func GetParsedTimestamp(input interface{}) (time.Time, bool)

GetParsedTimestamp returns the parsed timestamp

func GetRudderEventVal

func GetRudderEventVal(key string, rudderEvent types.SingularEventT) (interface{}, bool)

GetRudderEventVal returns the value corresponding to the key in the message structure

func GetRudderID added in v0.1.10

func GetRudderID(event types.SingularEventT) (string, bool)

GetRudderID return the UserID from the object

func GetRudderObjectStorageAccessKeys added in v0.1.10

func GetRudderObjectStorageAccessKeys() (accessKeyID, accessKey string)

func GetRudderObjectStorageConfig added in v0.1.10

func GetRudderObjectStorageConfig(prefixOverride string) (storageConfig map[string]interface{})

func GetRudderObjectStoragePrefix added in v0.1.10

func GetRudderObjectStoragePrefix() (prefix string)

func GetSpacesLocation added in v0.1.10

func GetSpacesLocation(location string) (region string)

func GetStringifiedData added in v0.1.10

func GetStringifiedData(data interface{}) string

func GetTagName added in v0.1.10

func GetTagName(id string, names ...string) string

GetTagName gets the tag name using a uuid and name

func GetWarehouseURL added in v0.1.10

func GetWarehouseURL() (url string)

func HTTPCallWithRetry added in v0.1.10

func HTTPCallWithRetry(url string, payload []byte) ([]byte, int)

func HTTPCallWithRetryWithTimeout added in v0.1.10

func HTTPCallWithRetryWithTimeout(url string, payload []byte, timeout time.Duration) ([]byte, int)

func HasAWSKeysInConfig added in v0.1.10

func HasAWSKeysInConfig(config interface{}) bool

func HasAWSRegionInConfig added in v0.1.10

func HasAWSRegionInConfig(config interface{}) bool

func IncrementMapByKey

func IncrementMapByKey(m map[string]int, key string, increment int)

IncrementMapByKey starts with 1 and increments the counter of a key

func IntArrayToString added in v0.1.10

func IntArrayToString(a []int64, delim string) string

func IsConfiguredToUseRudderObjectStorage added in v0.1.10

func IsConfiguredToUseRudderObjectStorage(storageConfig map[string]interface{}) bool

func IsValidUUID added in v0.1.10

func IsValidUUID(uuid string) bool

IsValidUUID will check if provided string is a valid UUID

func KeepProcessAlive

func KeepProcessAlive()

func MakeHTTPRequestWithTimeout added in v0.1.10

func MakeHTTPRequestWithTimeout(url string, payload io.Reader, timeout time.Duration) ([]byte, int, error)

func MakeJSONArray added in v0.1.10

func MakeJSONArray(bytesArray [][]byte) []byte

func MakeRetryablePostRequest added in v0.1.10

func MakeRetryablePostRequest(url string, endpoint string, data interface{}) (response []byte, statusCode int, err error)

MakeRetryablePostRequest is Util function to make a post request.

func MapStringKeys

func MapStringKeys(input map[string]interface{}) []string

func MinInt added in v0.1.10

func MinInt(a, b int) int

func ParseRudderEventBatch

func ParseRudderEventBatch(eventPayload json.RawMessage) ([]types.SingularEventT, bool)

ParseRudderEventBatch looks for the batch structure inside event

func PrintMemUsage

func PrintMemUsage()

PrintMemUsage outputs the current, total and OS memory being used. As well as the number of garage collection cycles completed.

func QuoteLiteral added in v0.1.10

func QuoteLiteral(literal string) string

func ReadLines

func ReadLines(path string) ([]string, error)

ReadLines reads a whole file into memory and returns a slice of its lines.

func RecordAppError

func RecordAppError(err error)

RecordAppError appends the error occured to error_store.json

func RemoveFilePaths

func RemoveFilePaths(filepaths ...string)

func ReplaceDB

func ReplaceDB(dbName, targetName string)

ReplaceDB : Rename the OLD DB and create a new one. Since we are not journaling, this should be idemponent

func ReplaceMultiRegex

func ReplaceMultiRegex(str string, expList map[string]string) (string, error)

func RunWithTimeout added in v0.1.10

func RunWithTimeout(f func(), onTimeout func(), d time.Duration)

RunWithTimeout runs provided function f until provided timeout d. If the timeout is reached, onTimeout callback will be called.

func SingleQuoteLiteralJoin added in v0.1.10

func SingleQuoteLiteralJoin(slice []string) string

func SortedMapKeys

func SortedMapKeys(input interface{}) []string

func SortedStructSliceValues

func SortedStructSliceValues(input interface{}, filedName string) []string

func StringKeys

func StringKeys(input interface{}) []string

func TailTruncateStr added in v0.1.10

func TailTruncateStr(str string, count int) string

TailTruncateStr returns the last `count` digits of a string

func TruncateStr

func TruncateStr(str string, limit int) string

func UnZipSingleFile

func UnZipSingleFile(outputfile string, filename string)

UnZipSingleFile unzips zip containing single file into ouputfile path passed

func UpdateJSONWithNewKeyVal added in v0.1.10

func UpdateJSONWithNewKeyVal(params []byte, key string, val interface{}) []byte

UpdateJSONWithNewKeyVal enhances the json passed with key, val

func ZipFiles

func ZipFiles(filename string, files []string) error

ZipFiles compresses files[] into zip at filename

Types

type BufferedWriter added in v0.1.10

type BufferedWriter struct {
	File   *os.File
	Writer *bufio.Writer
}

func CreateBufferedWriter added in v0.1.10

func CreateBufferedWriter(s string) (w BufferedWriter, err error)

func (BufferedWriter) Close added in v0.1.10

func (b BufferedWriter) Close() error

func (BufferedWriter) GetFile added in v0.1.10

func (b BufferedWriter) GetFile() *os.File

func (BufferedWriter) Write added in v0.1.10

func (b BufferedWriter) Write(p []byte) (int, error)

type ErrorStoreT

type ErrorStoreT struct {
	Errors []RudderError
}

ErrorStoreT : DS to store the app errors

type GZipWriter

type GZipWriter struct {
	File      *os.File
	GzWriter  *gzip.Writer
	BufWriter *bufio.Writer
}

func CreateGZ

func CreateGZ(s string) (w GZipWriter, err error)

func (GZipWriter) Close added in v0.1.10

func (w GZipWriter) Close() error

func (GZipWriter) CloseGZ

func (w GZipWriter) CloseGZ() error

func (GZipWriter) GetLoadFile added in v0.1.10

func (w GZipWriter) GetLoadFile() *os.File

func (GZipWriter) Write

func (w GZipWriter) Write(b []byte) (count int, err error)

func (GZipWriter) WriteGZ

func (w GZipWriter) WriteGZ(s string) error

func (GZipWriter) WriteRow added in v0.1.10

func (w GZipWriter) WriteRow(row []interface{}) error

type ObjectStorageOptsT added in v0.1.10

type ObjectStorageOptsT struct {
	Provider                    string
	Config                      interface{}
	UseRudderStorage            bool
	RudderStoragePrefixOverride string
}

type PerfStats

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

PerfStats is the class for managing performance stats. Not multi-threaded safe now

func (*PerfStats) End

func (stats *PerfStats) End(events int)

End marks the end of one round of stat collection. events is number of events processed since start

func (*PerfStats) Print

func (stats *PerfStats) Print()

Print displays the stats

func (*PerfStats) Setup

func (stats *PerfStats) Setup(comp string)

Setup initializes the stat collector

func (*PerfStats) Start

func (stats *PerfStats) Start()

Start marks the start of event collection

func (*PerfStats) Status added in v0.1.10

func (stats *PerfStats) Status() map[string]interface{}

type RudderError

type RudderError struct {
	StartTime         int64
	CrashTime         int64
	ReadableStartTime string
	ReadableCrashTime string
	Message           string
	StackTrace        string
	Code              int
}

RudderError : to store rudder error

type WaitGroup

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

func NewWaitGroup

func NewWaitGroup() *WaitGroup

func (*WaitGroup) Add

func (wg *WaitGroup) Add(delta int)

func (*WaitGroup) Done

func (wg *WaitGroup) Done()

func (*WaitGroup) Err

func (wg *WaitGroup) Err(err error)

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait() error

func (*WaitGroup) WaitForAll

func (wg *WaitGroup) WaitForAll() []error

Jump to

Keyboard shortcuts

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