10000 GitHub - JamesHutch/recode: Struct mapping api for Go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

JamesHutch/recode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

recode

recode is a library to map structs with interface{} Fields to structs with proper types.

Usage

import "github.com/JamesHutch/recode"

recode is used in scenarios where you have input data of unknown type which is mapped into a struct and you wish to remap this into a struct with more type safety

Exports a single Recode() function. Example:

type Input struct {
	Data interface{}
}

type Output struct {
	Data string
}

i := Input{"Hello World"}
recode.Recode(i, &o)
fmt.Print(o.String) // will output: "Hello World"
i = Input{1}
recode.Recode(i, &o)
fmt.Print(o.String) // will output: "1"

(Notable missing features are bool and complex)

License

Apache v2

About

Struct mapping api for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0