structmap: 4d63.com/structmap Index | Examples | Files

package structmap

import "4d63.com/structmap"

Package structmap converts structs to maps, and maps to structs.

Index

Examples

Package Files

structmap.go

func Map Uses

func Map(s interface{}) map[string]interface{}

Map converts a struct to a map of field names to values.

Code:

s := struct {
    A   string
    B   int
}{
    A:  "text",
    B:  123,
}

m := Map(s)

fmt.Println(m["A"], m["B"])

Output:

text 123

func Struct Uses

func Struct(m map[string]interface{}, s interface{})

Struct fills a struct with the values in the map.

Code:

s := struct {
    A   string
    B   int
}{}
m := map[string]interface{}{
    "A": "text",
    "B": 123,
}

Struct(m, &s)

fmt.Println(s)

Output:

{text 123}

Package structmap imports 3 packages (graph). Updated 2017-09-25. Refresh now. Tools for package owners.