Skip to content

Latest commit

 

History

History
88 lines (73 loc) · 1.6 KB

README.md

File metadata and controls

88 lines (73 loc) · 1.6 KB

Entity

Go Report Card GoDoc

Shortcut to access interfaces.

Installing

go get -u github.com/michaellyu/entity

How To Use

package main

import (
  "github.com/michaellyu/entity"
  "fmt"
)

func main() {
  var data interface{} = map[string]interface{} {
    "name": "Team",
    "city": map[string]interface{} {
      "name": "Tianjin",
    },
    "members": []interface{} {
      map[string]interface{} {
        "name": "Coral",
      },
      map[string]interface{} {
        "name": "Jack",
      },
      map[string]interface{} {
        "name": "Xinxing",
      },
    },
  }
  // new entity
  team := entity.NewEntity(&data)
  // get an interface{}
  name, err := team.Get("name")
  fmt.Println(name, err)
  // get a string
  cityName, _ := team.GetString("city.name")
  fmt.Println(cityName)
  // get a map
  firstMember, _ := team.GetMap("members[0]")
  fmt.Println(firstMember)
  // get an array
  members, _ := team.GetArray("members")
  fmt.Println(members)
  // set a field
  err = team.Set("name", "One Team")
  fmt.Println(err)
}

Start Docker

sudo docker-compose up -d

Run Test

./test

Run Benchmark

./test -bench="."

End

sudo docker-compose down