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


Golang namer.NewPublicNamer函数代码示例

本文整理汇总了Golang中k8s/io/kubernetes/cmd/libs/go2idl/namer.NewPublicNamer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPublicNamer函数的具体用法?Golang NewPublicNamer怎么用?Golang NewPublicNamer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: NameSystems

// NameSystems returns the name system used by the generators in this package.
func NameSystems() namer.NameSystems {
	return namer.NameSystems{
		"public":  namer.NewPublicNamer(0),
		"private": namer.NewPrivateNamer(0),
		"raw":     namer.NewRawNamer("", nil),
	}
}
开发者ID:Rushit,项目名称:kubernetes,代码行数:8,代码来源:sets.go

示例2: NameSystems

// NameSystems returns the name system used by the generators in this package.
func NameSystems() namer.NameSystems {
	pluralExceptions := map[string]string{
		"Endpoints":       "Endpoints",
		"ComponentStatus": "ComponentStatus",
	}
	return namer.NameSystems{
		"public":        namer.NewPublicNamer(0),
		"private":       namer.NewPrivateNamer(0),
		"raw":           namer.NewRawNamer("", nil),
		"publicPlural":  namer.NewPublicPluralNamer(pluralExceptions),
		"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
	}
}
开发者ID:slaws,项目名称:kubernetes,代码行数:14,代码来源:client-generator.go

示例3: NameSystems

// NameSystems returns the name system used by the generators in this package.
func NameSystems() namer.NameSystems {
	pluralExceptions := map[string]string{
		"Endpoints": "Endpoints",

		"SecurityContextConstraints": "SecurityContextConstraints",
	}
	return namer.NameSystems{
		"public":             namer.NewPublicNamer(0),
		"private":            namer.NewPrivateNamer(0),
		"raw":                namer.NewRawNamer("", nil),
		"publicPlural":       namer.NewPublicPluralNamer(pluralExceptions),
		"privatePlural":      namer.NewPrivatePluralNamer(pluralExceptions),
		"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
	}
}
开发者ID:pweil-,项目名称:origin,代码行数:16,代码来源:client_generator.go

示例4: construct

func construct(t *testing.T, files map[string]string) *generator.Context {
	b := parser.New()
	for name, src := range files {
		if err := b.AddFile(name, []byte(src)); err != nil {
			t.Fatal(err)
		}
	}
	c, err := generator.NewContext(b, namer.NameSystems{
		"public":  namer.NewPublicNamer(0),
		"private": namer.NewPrivateNamer(0),
	}, "public")
	if err != nil {
		t.Fatal(err)
	}
	return c
}
开发者ID:thed00de,项目名称:hypernetes,代码行数:16,代码来源:snippet_writer_test.go

示例5: construct

func construct(t *testing.T, files map[string]string) *generator.Context {
	b := parser.New()
	dir, err := ioutil.TempDir("", "snippet_writer_test")
	if err != nil {
		t.Fatal(err)
	}
	for name, src := range files {
		if err := b.AddFile(filepath.Join(dir, name), name, []byte(src)); err != nil {
			t.Fatal(err)
		}
	}
	c, err := generator.NewContext(b, namer.NameSystems{
		"public":  namer.NewPublicNamer(0),
		"private": namer.NewPrivateNamer(0),
	}, "public")
	if err != nil {
		t.Fatal(err)
	}
	return c
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:20,代码来源:snippet_writer_test.go

示例6: TestStructParse

func TestStructParse(t *testing.T) {
	var structTest = map[string]string{
		"base/foo/proto/foo.go": `
package foo

// Blah is a test.
// A test, I tell you.
type Blah struct {
	// A is the first field.
	A int64 ` + "`" + `json:"a"` + "`" + `

	// B is the second field.
	// Multiline comments work.
	B string ` + "`" + `json:"b"` + "`" + `
}
`,
	}

	_, u, o := construct(t, structTest, namer.NewPublicNamer(0))
	t.Logf("%#v", o)
	blahT := u.Get(types.Name{Package: "base/foo/proto", Name: "Blah"})
	if blahT == nil {
		t.Fatal("type not found")
	}
	if e, a := types.Struct, blahT.Kind; e != a {
		t.Errorf("struct kind wrong, wanted %v, got %v", e, a)
	}
	if e, a := "Blah is a test.\nA test, I tell you.\n", blahT.CommentLines; e != a {
		t.Errorf("struct comment wrong, wanted %v, got %v", e, a)
	}
	m := types.Member{
		Name:         "B",
		Embedded:     false,
		CommentLines: "B is the second field.\nMultiline comments work.\n",
		Tags:         `json:"b"`,
		Type:         types.String,
	}
	if e, a := m, blahT.Members[1]; !reflect.DeepEqual(e, a) {
		t.Errorf("wanted, got:\n%#v\n%#v", e, a)
	}
}
开发者ID:robertabbott,项目名称:kubernetes,代码行数:41,代码来源:parse_test.go

示例7: TestParseSecondClosestCommentLines

func TestParseSecondClosestCommentLines(t *testing.T) {
	const fileName = "base/foo/proto/foo.go"
	testCases := []struct {
		testFile map[string]string
		expected string
	}{
		{
			map[string]string{fileName: `package foo
// Blah's SecondClosestCommentLines.
// Another line.

// Blah is a test.
// A test, I tell you.
type Blah struct {
	a int
}
`},
			"Blah's SecondClosestCommentLines.\nAnother line.\n",
		},
		{
			map[string]string{fileName: `package foo
// Blah's SecondClosestCommentLines.
// Another line.

type Blah struct {
	a int
}
`},
			"Blah's SecondClosestCommentLines.\nAnother line.\n",
		},
	}
	for _, test := range testCases {
		_, u, o := construct(t, test.testFile, namer.NewPublicNamer(0))
		t.Logf("%#v", o)
		blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"})
		if e, a := test.expected, blahT.SecondClosestCommentLines; e != a {
			t.Errorf("struct second closest comment wrong, wanted %v, got %v", e, a)
		}
	}
}
开发者ID:Rushit,项目名称:kubernetes,代码行数:40,代码来源:parse_test.go

示例8: TestBuilder

func TestBuilder(t *testing.T) {
	var testFiles = map[string]string{
		"base/foo/proto/foo.go": `
package foo

import (
	"base/common/proto"
)

type Blah struct {
	common.Object
	Count int64
	Frobbers map[string]*Frobber
	Baz []Object
	Nickname *string
	NumberIsAFavorite map[int]bool
}

type Frobber struct {
	Name string
	Amount int64
}

type Object struct {
	common.Object
}

func AFunc(obj1 common.Object, obj2 Object) Frobber {
}

`,
		"base/common/proto/common.go": `
package common

type Object struct {
	ID int64
}
`,
	}

	var tmplText = `
package o
{{define "Struct"}}type {{Name .}} interface { {{range $m := .Members}}{{$n := Name $m.Type}}
	{{if $m.Embedded}}{{$n}}{{else}}{{$m.Name}}() {{$n}}{{if $m.Type.Elem}}{{else}}
	Set{{$m.Name}}({{$n}}){{end}}{{end}}{{end}}
}

{{end}}
{{define "Func"}}{{$s := .Signature}}func {{Raw .}}( {{range $s.Parameters}}{{Raw .}} {{end}}) {{range $s.Results}}{{Raw .}} {{end}}{}

{{end}}
{{range $t := .}}{{if eq $t.Kind "Struct"}}{{template "Struct" $t}}{{end}}{{end}}
{{range $t := .}}{{if eq $t.Kind "Func"}}{{template "Func" $t}}{{end}}{{end}}`

	var expect = `
package o


type CommonObject interface { 
	ID() Int64
	SetID(Int64)
}

type FooBlah interface { 
	CommonObject
	Count() Int64
	SetCount(Int64)
	Frobbers() MapStringToPointerFooFrobber
	Baz() SliceFooObject
	Nickname() PointerString
	NumberIsAFavorite() MapIntToBool
}

type FooFrobber interface { 
	Name() String
	SetName(String)
	Amount() Int64
	SetAmount(Int64)
}

type FooObject interface { 
	CommonObject
}


func proto.AFunc( proto.Object proto.Object ) proto.Frobber {}

`
	testNamer := namer.NewPublicNamer(1, "proto")
	rawNamer := namer.NewRawNamer("o", nil)
	_, u, o := construct(t, testFiles, testNamer)
	t.Logf("\n%v\n\n", o)
	tmpl := template.Must(
		template.New("").
			Funcs(
				map[string]interface{}{
					"Name": testNamer.Name,
					"Raw":  rawNamer.Name,
				}).
			Parse(tmplText),
//.........这里部分代码省略.........
开发者ID:robertabbott,项目名称:kubernetes,代码行数:101,代码来源:parse_test.go

示例9: TestTypeKindParse


//.........这里部分代码省略.........
			names: []string{"Test", "ETest", "test", "eTest", "e.Test"},
		},
		{
			Package: "f", Name: "Test", k: types.Slice,
			names: []string{"Test", "FTest", "test", "fTest", "f.Test"},
		},
		{
			Package: "g", Name: "Test", k: types.Func,
			names: []string{"Test", "GTest", "test", "gTest", "g.Test"},
		},
		{
			Package: "g", Name: "Interface", k: types.Interface,
			names: []string{"Interface", "GInterface", "interface", "gInterface", "g.Interface"},
		},
		{
			Package: "", Name: "string", k: types.Builtin,
			names: []string{"String", "String", "string", "string", "string"},
		},
		{
			Package: "", Name: "int", k: types.Builtin,
			names: []string{"Int", "Int", "int", "int", "int"},
		},
		{
			Package: "", Name: "struct{a int}", k: types.Struct,
			names: []string{"StructInt", "StructInt", "structInt", "structInt", "struct{a int}"},
		},
		{
			Package: "", Name: "struct{a a.Test; b b.Test}", k: types.Struct,
			names: []string{"StructTestTest", "StructATestBTest", "structTestTest", "structATestBTest", "struct{a a.Test; b b.Test}"},
		},
		{
			Package: "", Name: "map[int]string", k: types.Map,
			names: []string{"MapIntToString", "MapIntToString", "mapIntToString", "mapIntToString", "map[int]string"},
		},
		{
			Package: "", Name: "map[a.Test]b.Test", k: types.Map,
			names: []string{"MapTestToTest", "MapATestToBTest", "mapTestToTest", "mapATestToBTest", "map[a.Test]b.Test"},
		},
		{
			Package: "", Name: "[]string", k: types.Slice,
			names: []string{"SliceString", "SliceString", "sliceString", "sliceString", "[]string"},
		},
		{
			Package: "", Name: "[]a.Test", k: types.Slice,
			names: []string{"SliceTest", "SliceATest", "sliceTest", "sliceATest", "[]a.Test"},
		},
		{
			Package: "", Name: "*string", k: types.Pointer,
			names: []string{"PointerString", "PointerString", "pointerString", "pointerString", "*string"},
		},
		{
			Package: "", Name: "*a.Test", k: types.Pointer,
			names: []string{"PointerTest", "PointerATest", "pointerTest", "pointerATest", "*a.Test"},
		},
	}

	namers := []namer.Namer{
		namer.NewPublicNamer(0),
		namer.NewPublicNamer(1),
		namer.NewPrivateNamer(0),
		namer.NewPrivateNamer(1),
		namer.NewRawNamer("", nil),
	}

	for nameIndex, namer := range namers {
		_, u, _ := construct(t, testFiles, namer)
		t.Logf("Found types:\n")
		for pkgName, pkg := range u {
			for typeName, cur := range pkg.Types {
				t.Logf("%q-%q: %s %s", pkgName, typeName, cur.Name, cur.Kind)
			}
		}
		t.Logf("\n\n")

		for _, item := range assertions {
			n := types.Name{Package: item.Package, Name: item.Name}
			thisType := u.Get(n)
			if thisType == nil {
				t.Errorf("type %s not found", n)
				continue
			}
			if e, a := item.k, thisType.Kind; e != a {
				t.Errorf("%v-%s: type kind wrong, wanted %v, got %v (%#v)", nameIndex, n, e, a, thisType)
			}
			if e, a := item.names[nameIndex], namer.Name(thisType); e != a {
				t.Errorf("%v-%s: Expected %q, got %q", nameIndex, n, e, a)
			}
		}

		// Also do some one-off checks
		gtest := u.Get(types.Name{Package: "g", Name: "Test"})
		if e, a := 1, len(gtest.Methods); e != a {
			t.Errorf("expected %v but found %v methods: %#v", e, a, gtest)
		}
		iface := u.Get(types.Name{Package: "g", Name: "Interface"})
		if e, a := 1, len(iface.Methods); e != a {
			t.Errorf("expected %v but found %v methods: %#v", e, a, iface)
		}
	}
}
开发者ID:robertabbott,项目名称:kubernetes,代码行数:101,代码来源:parse_test.go

示例10: Run

func Run(g *Generator) {
	if g.Common.VerifyOnly {
		g.OnlyIDL = true
		g.Clean = false
	}

	b := parser.New()
	b.AddBuildTags("proto")

	omitTypes := map[types.Name]struct{}{}
	for _, t := range strings.Split(g.DropEmbeddedFields, ",") {
		name := types.Name{}
		if i := strings.LastIndex(t, "."); i != -1 {
			name.Package, name.Name = t[:i], t[i+1:]
		} else {
			name.Name = t
		}
		if len(name.Name) == 0 {
			log.Fatalf("--drop-embedded-types requires names in the form of [GOPACKAGE.]TYPENAME: %v", t)
		}
		omitTypes[name] = struct{}{}
	}

	boilerplate, err := g.Common.LoadGoBoilerplate()
	if err != nil {
		log.Fatalf("Failed loading boilerplate: %v", err)
	}

	protobufNames := NewProtobufNamer()
	outputPackages := generator.Packages{}
	for _, d := range strings.Split(g.Packages, ",") {
		generateAllTypes, outputPackage := true, true
		switch {
		case strings.HasPrefix(d, "+"):
			d = d[1:]
			generateAllTypes = false
		case strings.HasPrefix(d, "-"):
			d = d[1:]
			outputPackage = false
		}
		name := protoSafePackage(d)
		parts := strings.SplitN(d, "=", 2)
		if len(parts) > 1 {
			d = parts[0]
			name = parts[1]
		}
		p := newProtobufPackage(d, name, generateAllTypes, omitTypes)
		header := append([]byte{}, boilerplate...)
		header = append(header, p.HeaderText...)
		p.HeaderText = header
		protobufNames.Add(p)
		if outputPackage {
			outputPackages = append(outputPackages, p)
		}
	}

	if !g.Common.VerifyOnly {
		for _, p := range outputPackages {
			if err := p.(*protobufPackage).Clean(g.OutputBase); err != nil {
				log.Fatalf("Unable to clean package %s: %v", p.Name(), err)
			}
		}
	}

	if g.Clean {
		return
	}

	for _, p := range protobufNames.List() {
		if err := b.AddDir(p.Path()); err != nil {
			log.Fatalf("Unable to add directory %q: %v", p.Path(), err)
		}
	}

	c, err := generator.NewContext(
		b,
		namer.NameSystems{
			"public": namer.NewPublicNamer(3),
			"proto":  protobufNames,
		},
		"public",
	)
	c.Verify = g.Common.VerifyOnly
	c.FileTypes["protoidl"] = NewProtoFile()

	if err != nil {
		log.Fatalf("Failed making a context: %v", err)
	}

	if err := protobufNames.AssignTypesToPackages(c); err != nil {
		log.Fatalf("Failed to identify Common types: %v", err)
	}

	if err := c.ExecutePackages(g.OutputBase, outputPackages); err != nil {
		log.Fatalf("Failed executing generator: %v", err)
	}

	if g.OnlyIDL {
		return
	}
//.........这里部分代码省略.........
开发者ID:Clarifai,项目名称:kubernetes,代码行数:101,代码来源:cmd.go


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