Structure

Structure contains various utilitis to work with Go (Golang) structs.
Install
go get github.com/fatih/structure
Examples
Below is an example which converts a struct to a map
type Server struct {
Name string
ID int32
Enabled bool
}
s := &Server{
Name: "Arslan",
ID: 123456,
Enabled: true,
}
m, err := structure.ToMap(s)
if err != nil {
panic(err)
}
fmt.Printf("%#v", m)
// Output: map[string]interface {}{"Name":"Arslan", "ID":123456, "Enabled":true}
Test if the given variable is a struct or not
type Server struct {
Name string
ID int32
Enabled bool
}
s := &Server{
Name: "Arslan",
ID: 123456,
Enabled: true,
}
if structure.IsStruct(s) {
fmt.Println("s is a struct")
}
Languages
Go
100%