
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
4d63.com/structmap
A go package for converting structs to maps, and maps to structs.
I mostly wrote this for fun and to learn how to use reflection in Go. I don't recommend using this package, because like it and similar libraries it is a complex solution where a simpler one can be used instead. See the why not section below.
See the example in Go Doc.
There is a simpler way to solve this problem in many cases:
type S {
A string
B int
}
func (s *S) Map() map[string]interface{} {
return map[string]interface{}{
"A": s.A,
"B": s.B,
}
}
func NewWithMap(m map[string]interface{}) *S {
return &S{
A: m["A"].(string),
B: m["B"].(int),
}
}
func main() {
s := S{
A: "text",
B: 123,
}
m := s.Map()
// m is map[A:text B:123]
s2 := NewWithMap(m)
// s2 is {text 123}
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.