Update README.md
This commit is contained in:
parent
e7708e7aa2
commit
30e8ac277e
16
README.md
16
README.md
@ -8,10 +8,11 @@ Structure contains various utilitis to work with Go (Golang) structs.
|
|||||||
go get github.com/fatih/structure
|
go get github.com/fatih/structure
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Usage and Examples
|
||||||
|
|
||||||
|
Lets define and declare a struct
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Lets define and declare a struct
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Name string
|
Name string
|
||||||
ID int32
|
ID int32
|
||||||
@ -25,8 +26,9 @@ s := &Server{
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Convert it to a map[string]interface{}
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// convert it to a map[string]interface{}
|
|
||||||
m, err := structure.ToMap(s)
|
m, err := structure.ToMap(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -36,9 +38,10 @@ if err != nil {
|
|||||||
fmt.Printf("%#v", m)
|
fmt.Printf("%#v", m)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Convert to a `[]interface{}`. Slice values are **sorted** by default according
|
||||||
|
to the field names.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// convert it to a []interface{}. Slice values are sorted according to the
|
|
||||||
// field names.
|
|
||||||
m, err := structure.ToSlice(s)
|
m, err := structure.ToSlice(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -48,8 +51,9 @@ if err != nil {
|
|||||||
fmt.Printf("%#v", m)
|
fmt.Printf("%#v", m)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Check if it's a struct or a pointer to struct
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// check if it's a struct or a pointer to struct
|
|
||||||
if structure.IsStruct(s) {
|
if structure.IsStruct(s) {
|
||||||
fmt.Println("s is a struct")
|
fmt.Println("s is a struct")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user