Skip to content

michaellyu/entity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Shortcut to access interfaces.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published