sdfutil

package
v0.0.0-...-8e95ba3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var LoadLocationFromTZData func(name string, data []byte) (*time.Location, error) = nil

if you use go 1.10 or higher, you can hack this util by these to avoid "TimeZone.zip not found" on Windows

View Source
var TZData []byte = nil

Functions

func Copy

func Copy(dst, src interface{})

Copy deeply copies a src structure to dst. Useful for copying request and response structures.

Can copy between structs of different type, but will only copy fields which are assignable, and exist in both structs. Fields which are not assignable, or do not exist in both structs are ignored.

Example
type Foo struct {
	A int
	B []*string
}

// Create the initial value
str1 := "hello"
str2 := "bye bye"
f1 := &Foo{A: 1, B: []*string{&str1, &str2}}

// Do the copy
var f2 Foo
sdfutil.Copy(&f2, f1)

// Print the result
fmt.Println(sdfutil.Prettify(f2))
Output:

{
  A: 1,
  B: ["hello","bye bye"]
}

func CopyOf

func CopyOf(src interface{}) (dst interface{})

CopyOf returns a copy of src while also allocating the memory for dst. src must be a pointer type or this operation will fail.

Example
type Foo struct {
	A int
	B []*string
}

// Create the initial value
str1 := "hello"
str2 := "bye bye"
f1 := &Foo{A: 1, B: []*string{&str1, &str2}}

// Do the copy
v := sdfutil.CopyOf(f1)
var f2 *Foo = v.(*Foo)

// Print the result
fmt.Println(sdfutil.Prettify(f2))
Output:

{
  A: 1,
  B: ["hello","bye bye"]
}

func DeepEqual

func DeepEqual(a, b interface{}) bool

DeepEqual returns if the two values are deeply equal like reflect.DeepEqual. In addition to this, this method will also dereference the input values if possible so the DeepEqual performed will not fail if one parameter is a pointer and the other is not.

DeepEqual will not perform indirection of nested values of the input parameters.

func GenNonce

func GenNonce() string

func GetMD5Base64

func GetMD5Base64(bytes []byte) (base64Value string)

func GetTimeInFormatISO8601

func GetTimeInFormatISO8601() (timeStr string)

func GetUUIDV4

func GetUUIDV4() (uuidHex string)

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

func SetValueAtPath

func SetValueAtPath(i interface{}, path string, v interface{})

SetValueAtPath sets a value at the case insensitive lexical path inside of a structure.

func StringValue

func StringValue(i interface{}) string

StringValue returns the string representation of a value.

func ValuesAtPath

func ValuesAtPath(i interface{}, path string) ([]interface{}, error)

ValuesAtPath returns a list of values at the case insensitive lexical path inside of a structure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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