• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.MakeCompoundType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestSkipDuplicateTypes

func TestSkipDuplicateTypes(t *testing.T) {
	assert := assert.New(t)
	dir, err := ioutil.TempDir("", "codegen_test_")
	assert.NoError(err)
	defer os.RemoveAll(dir)

	leaf1 := types.NewPackage([]types.Type{
		types.MakeEnumType("E1", "a", "b"),
		types.MakeStructType("S1", []types.Field{
			types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
			types.Field{"e", types.MakeType(ref.Ref{}, 0), false},
		}, types.Choices{}),
	}, []ref.Ref{})
	leaf2 := types.NewPackage([]types.Type{
		types.MakeStructType("S2", []types.Field{
			types.Field{"f", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint16Kind)), false},
		}, types.Choices{}),
	}, []ref.Ref{})

	written := map[string]bool{}
	tag1 := code.ToTag(leaf1.Ref())
	leaf1Path := filepath.Join(dir, tag1+".go")
	generateAndEmit(tag1, leaf1Path, written, depsMap{}, pkg.Parsed{Package: leaf1, Name: "p"})

	tag2 := code.ToTag(leaf2.Ref())
	leaf2Path := filepath.Join(dir, tag2+".go")
	generateAndEmit(tag2, leaf2Path, written, depsMap{}, pkg.Parsed{Package: leaf2, Name: "p"})

	code, err := ioutil.ReadFile(leaf2Path)
	assert.NoError(err)
	assert.NotContains(string(code), "type ListOfUint16")
}
开发者ID:arv,项目名称:noms-old,代码行数:32,代码来源:codegen_test.go


示例2: 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("StructWithRef",
			[]types.Field{
				types.Field{"r", types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.Float32Kind))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{})
	__genPackageInFile_ref_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:14,代码来源:ref.noms.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.MakeStructType("A",
			[]types.Field{
				types.Field{"A", types.MakeCompoundType(types.ListKind, types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.BlobKind))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{})
	__genPackageInFile_sha1_b3ecb0f_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:14,代码来源:sha1_b3ecb0f.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("Commit",
			[]types.Field{
				types.Field{"value", types.MakePrimitiveType(types.ValueKind), false},
				types.Field{"parents", types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Ref{}, 0))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{})
	__datasPackageInFile_types_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:15,代码来源:types.noms.go


示例5: 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("User",
			[]types.Field{
				types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Name", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Photos", types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"), 0))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"),
	})
	__mainPackageInFile_facebook_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:18,代码来源:facebook.noms.go


示例6: 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


示例7: Read

// Read takes a CSV reader and reads it into a typed List of structs. Each row gets read into a struct named structName, described by headers. If the original data contained headers it is expected that the input reader has already read those and are pointing at the first data row.
// If kinds is non-empty, it will be used to type the fields in the generated structs; otherwise, they will be left as string-fields.
// In addition to the list, Read returns the typeRef for the structs in the list, and last the typeDef of the structs.
func Read(r *csv.Reader, structName string, headers []string, kinds KindSlice, vrw types.ValueReadWriter) (l types.List, typeRef, typeDef types.Type) {
	typeRef, typeDef = MakeStructTypeFromHeaders(headers, structName, kinds)
	valueChan := make(chan types.Value, 128) // TODO: Make this a function param?
	listType := types.MakeCompoundType(types.ListKind, typeRef)
	listChan := types.NewStreamingTypedList(listType, vrw, valueChan)

	structFields := typeDef.Desc.(types.StructDesc).Fields

	for {
		row, err := r.Read()
		if err == io.EOF {
			close(valueChan)
			break
		} else if err != nil {
			panic(err)
		}

		fields := make(map[string]types.Value)
		for i, v := range row {
			if i < len(headers) {
				f := structFields[i]
				fields[f.Name] = StringToType(v, f.T.Kind())
			}
		}
		valueChan <- types.NewStruct(typeRef, typeDef, fields)
	}

	return <-listChan, typeRef, typeDef
}
开发者ID:arv,项目名称:noms-old,代码行数:32,代码来源:read.go


示例8: 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("Tree",
			[]types.Field{
				types.Field{"children", types.MakeCompoundType(types.ListKind, types.MakeType(ref.Ref{}, 0)), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{})
	__genPackageInFile_struct_recursive_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:14,代码来源:struct_recursive.noms.go


示例9: 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("StructWithDupList",
			[]types.Field{
				types.Field{"l", types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.Uint8Kind)), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{})
	__genPackageInFile_struct_with_dup_list_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:14,代码来源:struct_with_dup_list.noms.go


示例10: 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("RemotePhoto",
			[]types.Field{
				types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Title", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Date", types.MakeType(ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"), 0), false},
				types.Field{"Geoposition", types.MakeType(ref.Parse("sha1-0cac0f1ed4777b6965548b0dfe6965a9f23af76c"), 0), false},
				types.Field{"Sizes", types.MakeCompoundType(types.MapKind, types.MakeType(ref.Ref{}, 2), types.MakePrimitiveType(types.StringKind)), false},
				types.Field{"Tags", types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.StringKind)), false},
				types.Field{"Faces", types.MakeCompoundType(types.SetKind, types.MakeType(ref.Ref{}, 1)), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Face",
			[]types.Field{
				types.Field{"Top", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Left", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Width", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Height", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"PersonName", types.MakePrimitiveType(types.StringKind), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Size",
			[]types.Field{
				types.Field{"Width", types.MakePrimitiveType(types.Uint32Kind), false},
				types.Field{"Height", types.MakePrimitiveType(types.Uint32Kind), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"),
		ref.Parse("sha1-0cac0f1ed4777b6965548b0dfe6965a9f23af76c"),
	})
	__commonPackageInFile_photo_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:40,代码来源:photo.noms.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("StructWithUnionField",
			[]types.Field{
				types.Field{"a", types.MakePrimitiveType(types.Float32Kind), false},
			},
			types.Choices{
				types.Field{"b", types.MakePrimitiveType(types.Float64Kind), false},
				types.Field{"c", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"d", types.MakePrimitiveType(types.BlobKind), false},
				types.Field{"e", types.MakePrimitiveType(types.ValueKind), false},
				types.Field{"f", types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.Uint8Kind)), false},
			},
		),
	}, []ref.Ref{})
	__genPackageInFile_struct_with_union_field_CachedRef = types.RegisterPackage(&p)
}
开发者ID:arv,项目名称:noms-old,代码行数:20,代码来源:struct_with_union_field.noms.go


示例12: TestUserName

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

	imported := types.NewPackage([]types.Type{
		types.MakeEnumType("E1", "a", "b"),
		types.MakeStructType("S1", []types.Field{
			types.Field{"f", types.MakePrimitiveType(types.BoolKind), false},
		}, types.Choices{}),
	}, []ref.Ref{})

	res := testResolver{assert, map[ref.Ref]types.Package{imported.Ref(): imported}}

	localStructName := "Local"
	resolved := types.MakeStructType(localStructName, []types.Field{
		types.Field{"a", types.MakePrimitiveType(types.Int8Kind), false},
	}, types.Choices{})

	g := Generator{R: &res}
	assert.Equal(localStructName, g.UserName(resolved))

	listOfImported := types.MakeCompoundType(types.ListKind, types.MakeType(imported.Ref(), 1))
	assert.Equal(fmt.Sprintf("ListOfS1"), g.UserName(listOfImported))
}
开发者ID:arv,项目名称:noms-old,代码行数:23,代码来源:generate_test.go


示例13: init

func init() {
	__typeForSetOfBool = types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.BoolKind))
	types.RegisterValue(__typeForSetOfBool, builderForSetOfBool, readerForSetOfBool)
}
开发者ID:arv,项目名称:noms-old,代码行数:4,代码来源:set.noms.go


示例14: init

func init() {
	__typeForMapOfRefOfKeyToSetOfRefOfRound = types.MakeCompoundType(types.MapKind, types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_index_CachedRef, 2)), types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 1))))
	types.RegisterValue(__typeForMapOfRefOfKeyToSetOfRefOfRound, builderForMapOfRefOfKeyToSetOfRefOfRound, readerForMapOfRefOfKeyToSetOfRefOfRound)
}
开发者ID:arv,项目名称:noms-old,代码行数:4,代码来源:index.noms.go


示例15: init

func init() {
	__typeForListOfD = types.MakeCompoundType(types.ListKind, types.MakeType(ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"), 0))
	types.RegisterValue(__typeForListOfD, builderForListOfD, readerForListOfD)
}
开发者ID:arv,项目名称:noms-old,代码行数:4,代码来源:struct_with_imports.noms.go


示例16: init

func init() {
	__typeForMapOfBoolToString = types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.BoolKind), types.MakePrimitiveType(types.StringKind))
	types.RegisterValue(__typeForMapOfBoolToString, builderForMapOfBoolToString, readerForMapOfBoolToString)
}
开发者ID:arv,项目名称:noms-old,代码行数:4,代码来源:map.noms.go


示例17: TestCSVExporter

// FIXME: run with pipe
func (s *testSuite) TestCSVExporter() {
	storeName := "store"
	setName := "csv"
	header := []string{"a", "b", "c"}
	payload := [][]string{
		[]string{"5", "7", "100"},
		[]string{"4", "10", "255"},
		[]string{"512", "12", "55"},
	}
	structName := "SomeStruct"

	// Setup data store
	cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false)
	ds := dataset.NewDataset(datas.NewDataStore(cs), setName)

	// Build Struct fields based on header
	f := make([]types.Field, 0, len(header))
	for _, key := range header {
		f = append(f, types.Field{
			Name: key,
			T:    types.MakePrimitiveType(types.StringKind),
		})
	}

	typeDef := types.MakeStructType(structName, f, types.Choices{})
	pkg := types.NewPackage([]types.Type{typeDef}, []ref.Ref{})
	pkgRef := types.RegisterPackage(&pkg)
	typeRef := types.MakeType(pkgRef, 0)
	structFields := typeDef.Desc.(types.StructDesc).Fields

	// Build data rows
	structs := make([]types.Value, len(payload))
	for i, row := range payload {
		fields := make(map[string]types.Value)
		for j, v := range row {
			fields[structFields[j].Name] = types.NewString(v)
		}
		structs[i] = types.NewStruct(typeRef, typeDef, fields)
	}

	listType := types.MakeCompoundType(types.ListKind, typeRef)
	ds.Commit(types.NewTypedList(listType, structs...))
	ds.Store().Close()

	// Run exporter
	out := s.Run(main, []string{"-store", storeName, "-ds", setName})

	// Verify output
	csvReader := csv.NewReader(strings.NewReader(out))

	row, err := csvReader.Read()
	d.Chk.NoError(err)
	s.Equal(header, row)

	for i := 0; i < len(payload); i++ {
		row, err := csvReader.Read()
		d.Chk.NoError(err)
		s.Equal(payload[i], row)
	}

	row, err = csvReader.Read()
	s.Equal(io.EOF, err)
}
开发者ID:arv,项目名称:noms-old,代码行数:64,代码来源:exporter_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.MakePrimitiveType函数代码示例发布时间:2022-05-24
下一篇:
Golang types.EnsureRef函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap