From e10d13000f8ec38a8c0d6c327de14fa4be073d0c Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sun, 27 Jul 2014 14:55:29 +0300 Subject: [PATCH] Update README.md --- README.md | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index df3a5f6..ebf5bac 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ go get github.com/fatih/structure ``` ## Examples -Below is an example which converts a **struct** to a **map** ```go +// Lets define and declare a struct type Server struct { Name string ID int32 @@ -23,31 +23,21 @@ s := &Server{ ID: 123456, Enabled: true, } +``` +```go +// convert it to a map[string]interface{} m, err := structure.ToMap(s) if err != nil { panic(err) } fmt.Printf("%#v", m) -// Output: map[string]interface {}{"Name":"Arslan", "ID":123456, "Enabled":true} +// prints: map[string]interface {}{"Name":"Arslan", "ID":123456, "Enabled":true} ``` -Test if the given variable is a struct or not - ```go -type Server struct { - Name string - ID int32 - Enabled bool -} - -s := &Server{ - Name: "Arslan", - ID: 123456, - Enabled: true, -} - +// check if it's a struct or a pointer to struct if structure.IsStruct(s) { fmt.Println("s is a struct") }