Skip to content

yangchenxing/go-map2struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-map2struct

Go Report Card Build Status GoDoc Coverage Status

go-map2struct convert map[string]interface{} to struct.

Example

type Foo struct {
  IntA      int
  IntB      uint32
  IntC      int64
  IntHex    uint32
  IntOct    uint16
  FloatA    float32
  BoolA     bool
  BoolB     bool
  DurationA time.Duration
  TimeA     time.Time
  EmbedA    Bar
}
type Bar struct {
  I int
}
src := map[string]interface{}{
  "IntA":      1,
  "IntB":      2,
  "IntC":      "3",
  "IntHex":    "0x0fffffff",
  "IntOct":    "0755",
  "FloatA":    1.0,
  "BoolA":     false,
  "BoolB":     "true",
  "DurationA": "1h",
  "TimeA":     now.Format("2006-01-02:15:04:05-0700"),
  "EmbedA": map[string]interface{}{
    "I": "99",
  },
}
var dest Foo
UnmarshalMap(dest, src)

About

convert map to struct

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages