encodestruct

package module
v0.0.0-...-8e73089 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README ¶

encodestruct 🔃

A package containing functions that might help you encode and decode structs to strings.


The examples show how you may encode a struct into a base64 encoded string using the gob encoder. The package is available if you do not want to copy the few lines required for yourself.

Documentation ¶

Index ¶

Examples ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Decode ¶

func Decode(s string, v interface{})

Decode will convert a base64 encoded string into bytes to decode into the value passed in the parameters using the gob decoder

Example ¶
encoded := "Ov+BAwEBDUNvbXBsZXhTdHJ1Y3QB/4IAAQMBBE5hbWUBDAABA0FnZQEGAAEIQmlydGhkYXkB/4QAAAAQ/4MFAQEEVGltZQH/hAAAACX/ggENamVzc2UgbWljaGFlbAEdAQ8BAAAADp37yWMAAAAA//8A"
var v ComplexStruct
Decode(encoded, &v)
fmt.Printf("%v", v)
Output:

{jesse michael 29 1990-06-04 03:15:47 +0000 UTC}

func Encode ¶

func Encode(v interface{}) string

Encode will convert the passed in value to a []byte using the gob encoder and base64 encode the bytes

Example ¶
t, _ := time.ParseInLocation(time.RFC3339, "1990-06-04T03:15:47.000Z", time.UTC)
v := ComplexStruct{
	Name:     "jesse michael",
	Age:      29,
	Birthday: t,
}

encoded := Encode(&v)
fmt.Println(encoded)
Output:

Ov+BAwEBDUNvbXBsZXhTdHJ1Y3QB/4IAAQMBBE5hbWUBDAABA0FnZQEGAAEIQmlydGhkYXkB/4QAAAAQ/4MFAQEEVGltZQH/hAAAACX/ggENamVzc2UgbWljaGFlbAEdAQ8BAAAADp37yWMAAAAA//8A

Types ¶

This section is empty.

Jump to

Keyboard shortcuts

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