Update README.md

This commit is contained in:
Fatih Arslan 2014-10-28 20:16:26 +02:00
parent 6321ca4452
commit 8a1e78be51

View File

@ -15,7 +15,7 @@ go get github.com/fatih/structs
## Usage and Examples ## Usage and Examples
Just like the standard lib `strings`, `bytes` and co packages, `structs` has Just like the standard lib `strings`, `bytes` and co packages, `structs` has
many global functions to manipulate or organize your struct data Lets define many global functions to manipulate or organize your struct data. Lets define
and declare a struct: and declare a struct:
```go ```go
@ -37,27 +37,27 @@ server := &Server{
```go ```go
// Convert a struct to a map[string]interface{} // Convert a struct to a map[string]interface{}
// => {"Name":"gopher", "ID":123456, "Enabled":true} // => {"Name":"gopher", "ID":123456, "Enabled":true}
m := structs.Map(s) m := structs.Map(server)
// Convert the values of a struct to a []interface{} // Convert the values of a struct to a []interface{}
// => ["gopher", 123456, true] // => ["gopher", 123456, true]
v := structs.Values(s) v := structs.Values(server)
// Convert the values of a struct to a []*Field // Convert the values of a struct to a []*Field
// (see "Field methods" for more info about fields) // (see "Field methods" for more info about fields)
f := structs.Fields(s) // Get a []*Field f := structs.Fields(server) // Get a []*Field
// Return the struct name => "Server" // Return the struct name => "Server"
n := structs.Name(s) // Get the struct name n := structs.Name(server) // Get the struct name
// Check if any field of a struct is initialized or not. // Check if any field of a struct is initialized or not.
h := structs.HasZero(s) // Check if any field is initialized h := structs.HasZero(server) // Check if any field is initialized
// Check if all fields of a struct is initialized or not. // Check if all fields of a struct is initialized or not.
z := structs.IsZero(s) // Check if all fields are initialized z := structs.IsZero(server) // Check if all fields are initialized
// Check if s is a struct or a pointer to struct // Check if server is a struct or a pointer to struct
i := structs.IsStruct(s) i := structs.IsStruct(server)
``` ```
### Struct methods ### Struct methods