本文整理匯總了Golang中github.com/dgraph-io/dgraph/types.Geo.MarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang Geo.MarshalBinary方法的具體用法?Golang Geo.MarshalBinary怎麽用?Golang Geo.MarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/types.Geo
的用法示例。
在下文中一共展示了Geo.MarshalBinary方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addGeoData
func addGeoData(t *testing.T, ps *store.Store, uid uint64, p geom.T, name string) {
g := types.Geo{p}
value, err := g.MarshalBinary()
require.NoError(t, err)
addEdgeToTypedValue(t, ps, "geometry", uid, types.GeoID, value)
addEdgeToTypedValue(t, ps, "name", uid, types.StringID, []byte(name))
}
示例2: populateGraph
func populateGraph(t *testing.T) (string, string, *store.Store) {
// logrus.SetLevel(logrus.DebugLevel)
dir, err := ioutil.TempDir("", "storetest_")
require.NoError(t, err)
ps, err := store.NewStore(dir)
require.NoError(t, err)
schema.ParseBytes([]byte(schemaStr))
posting.Init(ps)
worker.Init(ps)
group.ParseGroupConfig("")
dir2, err := ioutil.TempDir("", "wal_")
require.NoError(t, err)
worker.StartRaftNodes(dir2)
// So, user we're interested in has uid: 1.
// She has 5 friends: 23, 24, 25, 31, and 101
addEdgeToUID(t, ps, "friend", 1, 23)
addEdgeToUID(t, ps, "friend", 1, 24)
addEdgeToUID(t, ps, "friend", 1, 25)
addEdgeToUID(t, ps, "friend", 1, 31)
addEdgeToUID(t, ps, "friend", 1, 101)
// Now let's add a few properties for the main user.
addEdgeToValue(t, ps, "name", 1, "Michonne")
addEdgeToValue(t, ps, "gender", 1, "female")
var coord types.Geo
err = coord.UnmarshalText([]byte("{\"Type\":\"Point\", \"Coordinates\":[1.1,2.0]}"))
require.NoError(t, err)
gData, err := coord.MarshalBinary()
require.NoError(t, err)
addEdgeToTypedValue(t, ps, "loc", 1, types.GeoID, gData)
data, err := types.Int32(15).MarshalBinary()
require.NoError(t, err)
addEdgeToTypedValue(t, ps, "age", 1, types.Int32ID, data)
addEdgeToValue(t, ps, "address", 1, "31, 32 street, Jupiter")
data, err = types.Bool(true).MarshalBinary()
require.NoError(t, err)
addEdgeToTypedValue(t, ps, "alive", 1, types.BoolID, data)
addEdgeToValue(t, ps, "age", 1, "38")
addEdgeToValue(t, ps, "survival_rate", 1, "98.99")
addEdgeToValue(t, ps, "sword_present", 1, "true")
addEdgeToValue(t, ps, "_xid_", 1, "mich")
// Now let's add a name for each of the friends, except 101.
addEdgeToTypedValue(t, ps, "name", 23, types.StringID, []byte("Rick Grimes"))
addEdgeToValue(t, ps, "age", 23, "15")
err = coord.UnmarshalText([]byte(`{"Type":"Polygon", "Coordinates":[[[0.0,0.0], [2.0,0.0], [2.0, 2.0], [0.0, 2.0]]]}`))
require.NoError(t, err)
gData, err = coord.MarshalBinary()
require.NoError(t, err)
addEdgeToTypedValue(t, ps, "loc", 23, types.GeoID, gData)
addEdgeToValue(t, ps, "address", 23, "21, mark street, Mars")
addEdgeToValue(t, ps, "name", 24, "Glenn Rhee")
addEdgeToValue(t, ps, "name", 25, "Daryl Dixon")
addEdgeToValue(t, ps, "name", 31, "Andrea")
addEdgeToValue(t, ps, "dob", 23, "1910-01-02")
addEdgeToValue(t, ps, "dob", 24, "1909-05-05")
addEdgeToValue(t, ps, "dob", 25, "1909-01-10")
addEdgeToValue(t, ps, "dob", 31, "1901-01-15")
return dir, dir2, ps
}