Updat readme.md

This commit is contained in:
Fatih Arslan 2014-07-29 23:38:57 +03:00
parent af17259375
commit 38f7313fbb

View File

@ -20,54 +20,34 @@ type Server struct {
} }
s := &Server{ s := &Server{
Name: "Arslan", Name: "gopher",
ID: 123456, ID: 123456,
Enabled: true, Enabled: true,
} }
``` ```
#### Map()
Convert a struct to a `map[string]interface{}`
```go ```go
// Convert a struct to a map[string]interface{}
// => {"Name":"gopher", "ID":123456, "Enabled":true}
m := structure.Map(s) m := structure.Map(s)
// prints: {"Name":"Arslan", "ID":123456, "Enabled":true} // Convert the values of a struct to a []interface{}
fmt.Printf("%#v", m) // => [true, 123456, "gopher"]
``` v := structure.Values(s)
#### Values() // Convert the fields of a struct to a []string.
// => ["Enabled", "ID", "Name"]
f := structure.Fields(s)
Convert the values of a struct to a `[]interface{}`. Slice values are // Check if the fields of a struct is initialized or not.
**sorted** by default according to the field names. if structure.IsValid(s) {
fmt.Println("s is initialized")
```go
m := structure.Values(s)
// prints: [true, 123456, "Arslan"]
fmt.Printf("%#v", m)
```
#### Fields()
Convert the fields of a struct to a `[]string`. Slice values are **sorted** by
default according to the field names.
```go
m := structure.Fields(s)
// prints: ["Enabled", "ID", "Name"]
fmt.Printf("%#v", m)
```
#### IsStruct()
Check if it's a struct or a pointer to struct
```go
if structure.IsStruct(s) {
fmt.Println("s is a struct")
} }
// Check if it's a struct or a pointer to struct
if structure.IsStruct(s) {
fmt.Println("s is a struct")
}
``` ```