From 6a2d8d4acb57f653d61809159fbe6b4604db9b2d Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Tue, 15 Mar 2022 21:07:49 -0400 Subject: Add utility function for seeking to the end of a file. --- utilities/utilities.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'utilities/utilities.go') diff --git a/utilities/utilities.go b/utilities/utilities.go index 2435f1a..a441453 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -19,9 +19,15 @@ import ( "io" "math" "net/http" + "os" + "reflect" "time" ) +func IsInterfaceNil(ifc interface{}) bool { + return ifc == nil || (reflect.ValueOf(ifc).Kind() == reflect.Ptr && reflect.ValueOf(ifc).IsNil()) +} + func SignedPercentDifference(current float64, previous float64) (difference float64) { return ((current - previous) / (float64(current+previous) / 2.0)) * float64(100) } @@ -68,12 +74,7 @@ func TimedSequentialRTTs(ctx context.Context, client_a *http.Client, client_b *h return responseChannel } -type RandZeroSource struct{} - -func (RandZeroSource) Read(b []byte) (n int, err error) { - for i := range b { - b[i] = 0 - } - - return len(b), nil +func SeekForAppend(file *os.File) (err error) { + _, err = file.Seek(0, 2) + return } -- cgit v1.2.3