当前位置: 首页>>代码示例>>Golang>>正文


Golang ref.Parse函数代码示例

本文整理汇总了Golang中github.com/attic-labs/noms/ref.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: init

// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeEnumType("QuarterEnum", "Q1", "Q2", "Q3", "Q4"),
		types.MakeStructType("Quarter",
			[]types.Field{
				types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
				types.Field{"Quarter", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Key",
			[]types.Field{},
			types.Choices{
				types.Field{"Category", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Quarter", types.MakeType(ref.Ref{}, 1), false},
				types.Field{"Region", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"RoundType", types.MakeType(ref.Ref{}, 3), false},
				types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
			},
		),
		types.MakeEnumType("RoundTypeEnum", "Seed", "SeriesA", "SeriesB", "SeriesC", "SeriesD", "SeriesE", "SeriesF", "SeriesG", "SeriesH", "UnknownRoundType"),
	}, []ref.Ref{
		ref.Parse("sha1-6c64b08a509e25f9814dbf036489267c957a6fd8"),
		ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"),
	})
	__mainPackageInFile_index_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:30,代码来源:index.noms.go

示例2: TestChunkStoreRoot

func (suite *ChunkStoreTestSuite) TestChunkStoreRoot() {
	oldRoot := suite.Store.Root()
	suite.True(oldRoot.IsEmpty())

	bogusRoot := ref.Parse("sha1-81c870618113ba29b6f2b396ea3a69c6f1d626c5") // sha1("Bogus, Dude")
	newRoot := ref.Parse("sha1-907d14fb3af2b0d4f18c2d46abe8aedce17367bd")   // sha1("Hello, World")

	// Try to update root with bogus oldRoot
	result := suite.Store.UpdateRoot(newRoot, bogusRoot)
	suite.False(result)

	// Now do a valid root update
	result = suite.Store.UpdateRoot(newRoot, oldRoot)
	suite.True(result)
}
开发者ID:arv,项目名称:noms-old,代码行数:15,代码来源:chunk_store_test_common.go

示例3: init

// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeEnumType("LocalE", "LocalE1", "Ignored"),
		types.MakeStructType("ImportUser",
			[]types.Field{
				types.Field{"importedStruct", types.MakeType(ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"), 0), false},
				types.Field{"enum", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"),
	})
	__genPackageInFile_struct_with_imports_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:18,代码来源:struct_with_imports.noms.go

示例4: init

// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("Import",
			[]types.Field{
				types.Field{"FileSHA1", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Date", types.MakeType(ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"), 0), false},
				types.Field{"Companies", types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 0)))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"),
		ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"),
	})
	__mainPackageInFile_sha1_6c64b08_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:19,代码来源:sha1_6c64b08.go

示例5: HandleGetHasRefs

func HandleGetHasRefs(w http.ResponseWriter, req *http.Request, ps URLParams, ds DataStore) {
	err := d.Try(func() {
		d.Exp.Equal("POST", req.Method)

		req.ParseForm()
		refStrs := req.PostForm["ref"]
		d.Exp.True(len(refStrs) > 0)

		refs := make([]ref.Ref, len(refStrs))
		for idx, refStr := range refStrs {
			refs[idx] = ref.Parse(refStr)
		}

		w.Header().Add("Content-Type", "text/plain")
		writer := w.(io.Writer)
		if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") {
			w.Header().Add("Content-Encoding", "gzip")
			gw := gzip.NewWriter(w)
			defer gw.Close()
			writer = gw
		}

		sz := chunks.NewSerializer(writer)
		for _, r := range refs {
			has := ds.transitionalChunkStore().Has(r)
			fmt.Fprintf(writer, "%s %t\n", r, has)
		}
		sz.Close()
	})

	if err != nil {
		http.Error(w, fmt.Sprintf("Error: %v", err), http.StatusBadRequest)
		return
	}
}
开发者ID:arv,项目名称:noms-old,代码行数:35,代码来源:handlers.go

示例6: TestTypes

func TestTypes(t *testing.T) {
	assert := assert.New(t)
	vs := NewTestValueStore()

	boolType := MakePrimitiveType(BoolKind)
	uint8Type := MakePrimitiveType(Uint8Kind)
	stringType := MakePrimitiveType(StringKind)
	mapType := MakeCompoundType(MapKind, stringType, uint8Type)
	setType := MakeCompoundType(SetKind, stringType)
	mahType := MakeStructType("MahStruct", []Field{
		Field{"Field1", stringType, false},
		Field{"Field2", boolType, true},
	}, Choices{})
	otherType := MakeStructType("MahOtherStruct", []Field{}, Choices{
		Field{"StructField", mahType, false},
		Field{"StringField", stringType, false},
	})
	pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	trType := MakeType(pkgRef, 42)

	mRef := vs.WriteValue(mapType).TargetRef()
	setRef := vs.WriteValue(setType).TargetRef()
	otherRef := vs.WriteValue(otherType).TargetRef()
	mahRef := vs.WriteValue(mahType).TargetRef()
	trRef := vs.WriteValue(trType).TargetRef()

	assert.True(otherType.Equals(vs.ReadValue(otherRef)))
	assert.True(mapType.Equals(vs.ReadValue(mRef)))
	assert.True(setType.Equals(vs.ReadValue(setRef)))
	assert.True(mahType.Equals(vs.ReadValue(mahRef)))
	assert.True(trType.Equals(vs.ReadValue(trRef)))
}
开发者ID:arv,项目名称:noms-old,代码行数:32,代码来源:type_test.go

示例7: rootByKey

func (l *internalLevelDBStore) rootByKey(key []byte) ref.Ref {
	val, err := l.db.Get(key, nil)
	if err == errors.ErrNotFound {
		return ref.Ref{}
	}
	d.Chk.NoError(err)

	return ref.Parse(string(val))
}
开发者ID:arv,项目名称:noms-old,代码行数:9,代码来源:leveldb_store.go

示例8: TestWriteCompoundBlob

func TestWriteCompoundBlob(t *testing.T) {
	assert := assert.New(t)

	r1 := ref.Parse("sha1-0000000000000000000000000000000000000001")
	r2 := ref.Parse("sha1-0000000000000000000000000000000000000002")
	r3 := ref.Parse("sha1-0000000000000000000000000000000000000003")

	v := newCompoundBlob([]metaTuple{
		newMetaTuple(Uint64(20), nil, newRef(r1, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(40), nil, newRef(r2, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(60), nil, newRef(r3, MakeRefType(typeForBlob))),
	}, NewTestValueStore())
	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(v)

	// the order of the elements is based on the ref of the value.
	assert.EqualValues([]interface{}{BlobKind, true, []interface{}{r1.String(), "20", r2.String(), "40", r3.String(), "60"}}, w.toArray())
}
开发者ID:arv,项目名称:noms-old,代码行数:18,代码来源:encode_noms_value_test.go

示例9: Root

func (h *HTTPStore) Root() ref.Ref {
	// GET http://<host>/root. Response will be ref of root.
	res := h.requestRoot("GET", ref.Ref{}, ref.Ref{})
	defer closeResponse(res)

	d.Chk.Equal(http.StatusOK, res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode))
	data, err := ioutil.ReadAll(res.Body)
	d.Chk.NoError(err)
	return ref.Parse(string(data))
}
开发者ID:arv,项目名称:noms-old,代码行数:10,代码来源:http_store.go

示例10: TestWriteRef

func TestWriteRef(t *testing.T) {
	assert := assert.New(t)

	typ := MakeCompoundType(RefKind, MakePrimitiveType(Uint32Kind))
	r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	v := NewRef(r)

	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(testRef{Value: v, t: typ})
	assert.EqualValues([]interface{}{RefKind, Uint32Kind, r.String()}, w.toArray())
}
开发者ID:arv,项目名称:noms-old,代码行数:11,代码来源:encode_noms_value_test.go

示例11: init

// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("D",
			[]types.Field{
				types.Field{"structField", types.MakeType(ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"), 0), false},
				types.Field{"enumField", types.MakeType(ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"), 1), false},
			},
			types.Choices{},
		),
		types.MakeStructType("DUser",
			[]types.Field{
				types.Field{"Dfield", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"),
	})
	__genPackageInFile_sha1_eda4273_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:23,代码来源:sha1_eda4273.go

示例12: TestWritePackage2

func TestWritePackage2(t *testing.T) {
	assert := assert.New(t)

	setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
	r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	v := Package{[]Type{setTref}, []ref.Ref{r}, &ref.Ref{}}

	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(v)
	assert.EqualValues([]interface{}{PackageKind, []interface{}{SetKind, []interface{}{Uint32Kind}}, []interface{}{r.String()}}, w.toArray())
}
开发者ID:arv,项目名称:noms-old,代码行数:11,代码来源:encode_noms_value_test.go

示例13: TestReadValueRef

func TestReadValueRef(t *testing.T) {
	assert := assert.New(t)
	cs := NewTestValueStore()

	r := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
	a := parseJson(`[%d, %d, %d, "%s"]`, ValueKind, RefKind, Uint32Kind, r.String())
	reader := newJsonArrayReader(a, cs)
	v := reader.readTopLevelValue()
	tr := MakeCompoundType(RefKind, MakePrimitiveType(Uint32Kind))
	assert.True(refFromType(r, tr).Equals(v))
}
开发者ID:arv,项目名称:noms-old,代码行数:11,代码来源:decode_noms_value_test.go

示例14: TestReadPackage2

func TestReadPackage2(t *testing.T) {
	cs := NewTestValueStore()

	rr := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
	setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
	pkg := NewPackage([]Type{setTref}, []ref.Ref{rr})

	a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(Uint32Kind)}}, []interface{}{rr.String()}}
	r := newJsonArrayReader(a, cs)
	v := r.readTopLevelValue().(Package)
	assert.True(t, pkg.Equals(v))
}
开发者ID:arv,项目名称:noms-old,代码行数:12,代码来源:decode_noms_value_test.go

示例15: TestReadCompoundBlob

func TestReadCompoundBlob(t *testing.T) {
	assert := assert.New(t)
	cs := NewTestValueStore()

	r1 := ref.Parse("sha1-0000000000000000000000000000000000000001")
	r2 := ref.Parse("sha1-0000000000000000000000000000000000000002")
	r3 := ref.Parse("sha1-0000000000000000000000000000000000000003")
	a := parseJson(`[%d, true, ["%s", "20", "%s", "40", "%s", "60"]]`, BlobKind, r1, r2, r3)
	r := newJsonArrayReader(a, cs)

	m := r.readTopLevelValue()
	_, ok := m.(compoundBlob)
	assert.True(ok)
	m2 := newCompoundBlob([]metaTuple{
		newMetaTuple(Uint64(20), nil, newRef(r1, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(40), nil, newRef(r2, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(60), nil, newRef(r3, MakeRefType(typeForBlob))),
	}, cs)

	assert.True(m.Type().Equals(m2.Type()))
	assert.Equal(m.Ref().String(), m2.Ref().String())
}
开发者ID:arv,项目名称:noms-old,代码行数:22,代码来源:decode_noms_value_test.go


注:本文中的github.com/attic-labs/noms/ref.Parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。