Code Monkey home page Code Monkey logo

entity's Introduction

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

entity's People

Contributors

michaellyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.