Structure GoDoc Build Status

Structure contains various utilitis to work with Go (Golang) structs.

Install

go get github.com/fatih/structure

Examples

// Lets define and declare a struct
type Server struct {
	Name    string
	ID      int32
	Enabled bool
}

s := &Server{
	Name:    "Arslan",
	ID:      123456,
	Enabled: true,
}
// convert it to a map[string]interface{}
m, err := structure.ToMap(s)
if err != nil {
	panic(err)
}

// prints: map[string]interface {}{"Name":"Arslan", "ID":123456, "Enabled":true}
fmt.Printf("%#v", m)
// convert it to a []interface{}. Slice values are sorted according to the
// field names.
m, err := structure.ToSlice(s)
if err != nil {
	panic(err)
}

// prints: []interface {}{true, 123456, "Arslan"}
fmt.Printf("%#v", m)

```go
// check if it's a struct or a pointer to struct
if structure.IsStruct(s) {
    fmt.Println("s is a struct") 
}
Description
Utilities for Go structs
Readme MIT 200 KiB
Languages
Go 100%