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


Golang Descriptor.GetName方法代码示例

本文整理汇总了Golang中limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.GetName方法的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor.GetName方法的具体用法?Golang Descriptor.GetName怎么用?Golang Descriptor.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor的用法示例。


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

示例1: generateTests

func (g *validation) generateTests(msg *generator.Descriptor, field *pb.FieldDescriptorProto, fieldName string, idx int, patterns map[string]string) {

	if limbo.IsRequiredProperty(field) {
		g.generateRequiredTest(msg, field, fieldName)
	}

	if n, ok := limbo.GetMinItems(field); ok {
		g.generateMinItemsTest(msg, field, fieldName, int(n))
	}

	if n, ok := limbo.GetMaxItems(field); ok {
		g.generateMaxItemsTest(msg, field, fieldName, int(n))
	}

	if pattern, ok := limbo.GetPattern(field); ok {
		patternVar := fmt.Sprintf("valPattern_%s_%d", msg.GetName(), idx)
		patterns[patternVar] = pattern
		g.generatePatternTest(msg, field, fieldName, pattern, patternVar)
	}

	if n, ok := limbo.GetMinLength(field); ok {
		g.generateMinLengthTest(msg, field, fieldName, int(n))
	}

	if n, ok := limbo.GetMaxLength(field); ok {
		g.generateMaxLengthTest(msg, field, fieldName, int(n))
	}

	if field.GetType() == pb.FieldDescriptorProto_TYPE_MESSAGE {
		g.generateSubMessageTest(msg, field, fieldName)
	}

}
开发者ID:limbo-services,项目名称:core,代码行数:33,代码来源:validation.go

示例2: setMessage

func (g *svcauth) setMessage(inputType *generator.Descriptor, path, input, output string, inputIsNullable bool) {
	var (
		goPath           string
		outputIsNullable bool
	)

	goPath = input
	if inputIsNullable {
		g.P(`if `, goPath, `== nil {`)
		g.P(goPath, `= &`, g.gen.TypeName(inputType), `{}`)
		g.P(`}`)
	}

	for path != "" {

		// split path
		part := path
		idx := strings.IndexByte(path, '.')
		if idx >= 0 {
			part = path[:idx]
			path = path[idx+1:]
		} else {
			path = ""
		}

		// Get Field
		field := inputType.GetFieldDescriptor(part)
		if field == nil {
			g.gen.Fail("unknown field", part, "in message", inputType.GetName())
		}
		if !field.IsMessage() {
			g.gen.Fail("expected a message")
		}

		// Append code
		fieldGoName := g.gen.GetFieldName(inputType, field)
		goPath += "." + fieldGoName

		inputType = g.messages[strings.TrimPrefix(field.GetTypeName(), ".")]

		if gogoproto.IsNullable(field) && path != "" {
			g.P(`if `, goPath, `== nil {`)
			g.P(goPath, `= &`, g.gen.TypeName(inputType), `{}`)
			g.P(`}`)
		}

		if gogoproto.IsNullable(field) {
			outputIsNullable = true
		} else {
			outputIsNullable = false
		}
	}

	if outputIsNullable {
		g.P(goPath, ` = `, output)
	} else {
		g.P(goPath, ` = &`, output)
	}
}
开发者ID:limbo-services,项目名称:core,代码行数:59,代码来源:svcauth.go

示例3: generateStmt

func (g *gensql) generateStmt(file *generator.FileDescriptor, message *generator.Descriptor) {
	model := limbo.GetModel(message)

	g.P(`type `, message.Name, `StmtBuilder interface {`)
	g.P(`Prepare(scanner string, query string) `, message.Name, `Stmt`)
	g.P(`PrepareExecer(query string) `, message.Name, `Execer`)
	g.P(`Err() error`)
	g.P(`}`)

	g.P(`type `, message.Name, `Stmt interface {`)
	g.P(`QueryRow(ctx `, g.contextPkg.Use(), `.Context, args ... interface{}) (`, message.Name, `Row)`)
	g.P(`Query(ctx `, g.contextPkg.Use(), `.Context, args ... interface{}) (`, message.Name, `Rows, error)`)
	g.P(`SelectSlice(ctx `, g.contextPkg.Use(), `.Context, dst []*`, message.Name, `, args ... interface{}) ([]*`, message.Name, `, error)`)
	g.P(`SelectMessageSlice(ctx `, g.contextPkg.Use(), `.Context, dst []interface{}, args ... interface{}) ([]interface{}, error)`)
	g.P(`ForTx(tx *`, g.sqlPkg.Use(), `.Tx) `, message.Name, `Stmt`)
	g.P(`}`)

	g.P(`type `, message.Name, `Execer interface {`)
	g.P(`Exec(ctx `, g.contextPkg.Use(), `.Context, args ... interface{}) (`, g.sqlPkg.Use(), `.Result, error)`)
	g.P(`ForTx(tx *`, g.sqlPkg.Use(), `.Tx) `, message.Name, `Execer`)
	g.P(`}`)

	g.P(`type `, message.Name, `Row interface {`)
	g.P(`Scan(out *`, message.Name, `)  error`)
	g.P(`}`)

	g.P(`type `, message.Name, `Rows interface {`)
	g.P(`Close() error`)
	g.P(`Next() bool`)
	g.P(`Err() error`)
	g.P(`Scan(out *`, message.Name, `)  error`)
	g.P(`}`)

	g.P(`type `, unexport(*message.Name), `StmtBuilder struct {`)
	g.P(`db *`, g.sqlPkg.Use(), `.DB`)
	g.P(`err error`)
	g.P(`}`)

	g.P(`type `, unexport(*message.Name), `Stmt struct {`)
	g.P(`stmt *`, g.sqlPkg.Use(), `.Stmt`)
	g.P(`scanner func(func(...interface{}) error, *`, message.Name, `) error`)
	g.P(`query string`)
	g.P(`}`)

	g.P(`type `, unexport(*message.Name), `Execer struct {`)
	g.P(`stmt *`, g.sqlPkg.Use(), `.Stmt`)
	g.P(`query string`)
	g.P(`}`)

	g.P(`type `, unexport(*message.Name), `Row struct {`)
	g.P(`row *`, g.sqlPkg.Use(), `.Row`)
	g.P(`span *`, g.tracePkg.Use(), `.Span`)
	g.P(`scanner func(func(...interface{}) error, *`, message.Name, `) error`)
	g.P(`}`)

	g.P(`type `, unexport(*message.Name), `Rows struct {`)
	g.P(`*`, g.sqlPkg.Use(), `.Rows`)
	g.P(`span *`, g.tracePkg.Use(), `.Span`)
	g.P(`scanner func(func(...interface{}) error, *`, message.Name, `) error`)
	g.P(`}`)

	g.P(`func New`, message.Name, `StmtBuilder(db *`, g.sqlPkg.Use(), `.DB) `, message.Name, `StmtBuilder {`)
	g.P(`return &`, unexport(*message.Name), `StmtBuilder{db: db}`)
	g.P(`}`)

	g.P(`func (b *`, unexport(*message.Name), `StmtBuilder) Prepare(scanner string, query string) (`, message.Name, `Stmt) {`)
	g.P(`if b.err != nil { return nil }`)
	g.P(`var scannerFunc func(func(...interface{}) error, *`, message.Name, `) error`)
	g.P(`switch scanner {`)
	for _, scanner := range model.Scanner {
		scannerFuncName := `scan_` + message.GetName()
		if scanner.Name != "" {
			scannerFuncName += `_` + scanner.Name
		}

		g.P(`case `, strconv.Quote(scanner.Name), `:`)
		g.P(`query = `, scannerFuncName, `SQL + " " + query`)
		g.P(`scannerFunc = `, scannerFuncName)
	}
	g.P(`default:`)
	g.P(`if b.err == nil { b.err = fmt.Errorf("unknown scanner: %s", scanner) }`)
	g.P(`}`)
	g.P(`query = `, g.runtimePkg.Use(), `.CleanSQL(query)`)
	g.P(`stmt, err := b.db.Prepare(query)`)
	g.P(`if err != nil { if b.err == nil { b.err = err } }`)
	g.P(`return &`, unexport(*message.Name), `Stmt{stmt: stmt, query:query, scanner: scannerFunc}`)
	g.P(`}`)

	g.P(`func (b *`, unexport(*message.Name), `StmtBuilder) PrepareExecer( query string) (`, message.Name, `Execer) {`)
	g.P(`if b.err != nil { return nil }`)
	g.P(`query = `, g.runtimePkg.Use(), `.CleanSQL(query)`)
	g.P(`stmt, err := b.db.Prepare(query)`)
	g.P(`if err != nil { if b.err == nil { b.err = err } }`)
	g.P(`return &`, unexport(*message.Name), `Execer{stmt: stmt, query: query}`)
	g.P(`}`)

	g.P(`func (b *`, unexport(*message.Name), `StmtBuilder) Err() (error) {`)
	g.P(`return b.err`)
	g.P(`}`)

//.........这里部分代码省略.........
开发者ID:limbo-services,项目名称:core,代码行数:101,代码来源:sql.go

示例4: generateScanner

func (g *gensql) generateScanner(file *generator.FileDescriptor, message *generator.Descriptor, scanner *limbo.ScannerDescriptor) {
	scannerFuncName := `scan_` + message.GetName()
	if scanner.Name != "" {
		scannerFuncName += `_` + scanner.Name
	}

	joins := map[string]int{}

	g.P(``)
	g.P(`const `, scannerFuncName, `SQL = `, strconv.Quote(g.generateQueryPrefix(message, scanner)))
	g.P(`func `, scannerFuncName, `(scanFunc func(...interface{})error, dst *`, message.Name, `) error {`)
	g.P(`var (`)
	for i, column := range scanner.Column {
		m := g.models[column.MessageType]
		field := m.GetFieldDescriptor(lastField(column.FieldName))

		if field.IsRepeated() {
			g.P(`b`, i, ` []byte`)
			continue
		}

		switch field.GetType() {
		case pb.FieldDescriptorProto_TYPE_BOOL:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullBool`)
		case pb.FieldDescriptorProto_TYPE_DOUBLE:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullFloat64`)
		case pb.FieldDescriptorProto_TYPE_FLOAT:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullFloat64`)
		case pb.FieldDescriptorProto_TYPE_FIXED32,
			pb.FieldDescriptorProto_TYPE_UINT32:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullInt64`)
		case pb.FieldDescriptorProto_TYPE_FIXED64,
			pb.FieldDescriptorProto_TYPE_UINT64:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullInt64`)
		case pb.FieldDescriptorProto_TYPE_SFIXED32,
			pb.FieldDescriptorProto_TYPE_INT32,
			pb.FieldDescriptorProto_TYPE_SINT32:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullInt64`)
		case pb.FieldDescriptorProto_TYPE_SFIXED64,
			pb.FieldDescriptorProto_TYPE_INT64,
			pb.FieldDescriptorProto_TYPE_SINT64:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullInt64`)
		case pb.FieldDescriptorProto_TYPE_BYTES:
			g.P(`b`, i, ` []byte`)
		case pb.FieldDescriptorProto_TYPE_STRING:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullString`)
		case pb.FieldDescriptorProto_TYPE_ENUM:
			g.P(`b`, i, ` `, g.sqlPkg.Use(), `.NullInt64`)
		case pb.FieldDescriptorProto_TYPE_MESSAGE:
			if field.GetTypeName() == ".google.protobuf.Timestamp" {
				g.P(`b`, i, ` `, g.mysqlPkg.Use(), `.NullTime`)
			} else if limbo.IsGoSQLValuer(g.objectNamed(field.GetTypeName()).(*generator.Descriptor)) {
				g.P(`b`, i, ` Null`, g.typeName(field.GetTypeName()))
			} else {
				g.P(`b`, i, ` []byte`)
				g.P(`m`, i, ` `, g.typeName(field.GetTypeName()))
			}
		default:
			panic("unsuported type: " + field.GetType().String())
		}
	}
	for i, join := range scanner.Join {
		m := g.models[join.MessageType]
		field := m.GetFieldDescriptor(lastField(join.FieldName))
		joins[join.FieldName] = i
		g.P(`j`, i, ` `, g.typeName(field.GetTypeName()))
		g.P(`j`, i, `Valid bool`)
	}
	g.P(`)`)
	g.P(`err := scanFunc(`)
	for i := range scanner.Column {
		g.P(`&b`, i, `,`)
	}
	g.P(`)`)
	g.P(`if err!=nil { return err }`)
	for i, column := range scanner.Column {
		var (
			m     = g.models[column.MessageType]
			field = m.GetFieldDescriptor(lastField(column.FieldName))
			valid string
			dst   = "dst"
		)

		if column.JoinedWith != "" {
			dst = fmt.Sprintf("j%d", joins[column.JoinedWith])
		}

		if field.IsRepeated() {
			valid = fmt.Sprintf(`b%d != nil`, i)
		} else {
			switch field.GetType() {
			case pb.FieldDescriptorProto_TYPE_MESSAGE:
				if field.GetTypeName() == ".google.protobuf.Timestamp" {
					valid = fmt.Sprintf(`b%d.Valid`, i)
				} else if limbo.IsGoSQLValuer(g.objectNamed(field.GetTypeName()).(*generator.Descriptor)) {
					valid = fmt.Sprintf(`b%d.Valid`, i)
				} else {
					valid = fmt.Sprintf(`b%d != nil`, i)
				}
			case pb.FieldDescriptorProto_TYPE_BYTES:
//.........这里部分代码省略.........
开发者ID:limbo-services,项目名称:core,代码行数:101,代码来源:sql.go

示例5: populateMessage

func (g *gensql) populateMessage(file *generator.FileDescriptor, msg *generator.Descriptor) {
	model := limbo.GetModel(msg)
	model.MessageType = "." + file.GetPackage() + "." + msg.GetName()

	{ // default scanner
		var found bool
		for _, scanner := range model.Scanner {
			if scanner.Name == "" {
				found = true
				break
			}
		}
		if !found {
			model.Scanner = append(model.Scanner, &limbo.ScannerDescriptor{Fields: "*"})
		}
	}

	for _, scanner := range model.Scanner {
		scanner.MessageType = "." + file.GetPackage() + "." + msg.GetName()
	}

	for _, field := range msg.GetField() {
		if column := limbo.GetColumn(field); column != nil {
			column.MessageType = "." + file.GetPackage() + "." + msg.GetName()
			column.FieldName = field.GetName()
			if column.Name == "" {
				column.Name = field.GetName()
			}

			model.Column = append(model.Column, column)
		}

		if join := limbo.GetJoin(field); join != nil {
			if field.GetType() != pb.FieldDescriptorProto_TYPE_MESSAGE {
				g.gen.Fail(field.GetName(), "in", msg.GetName(), "must be a message")
			}

			join.MessageType = "." + file.GetPackage() + "." + msg.GetName()
			join.FieldName = field.GetName()
			join.ForeignMessageType = field.GetTypeName()

			if join.Name == "" {
				join.Name = field.GetName()
			}

			if join.Key == "" {
				join.Key = field.GetName() + "_id"
			}

			if join.ForeignKey == "" {
				join.ForeignKey = "id"
			}

			model.Join = append(model.Join, join)
		}
	}

	sort.Sort(limbo.SortedColumnDescriptors(model.Column))
	sort.Sort(limbo.SortedJoinDescriptors(model.Join))
	sort.Sort(limbo.SortedScannerDescriptors(model.Scanner))
}
开发者ID:limbo-services,项目名称:core,代码行数:61,代码来源:sql.go

示例6: getMessage

func (g *svcauth) getMessage(inputType *generator.Descriptor, path, input, output string, inputIsNullable bool) {
	var (
		checks     []string
		goPath     string
		isNullable = inputIsNullable
	)

	if path == "." {
		g.P(output, ` = `, input)
		return
	}

	goPath = input
	if inputIsNullable {
		checks = append(checks, input+" != nil")
	}

	for path != "" {

		// split path
		part := path
		idx := strings.IndexByte(path, '.')
		if idx >= 0 {
			part = path[:idx]
			path = path[idx+1:]
		} else {
			path = ""
		}

		// Get Field
		field := inputType.GetFieldDescriptor(part)
		if field == nil {
			g.gen.Fail("unknown field", strconv.Quote(part), "in message", inputType.GetName())
		}
		if !field.IsMessage() {
			g.gen.Fail("expected a message")
		}

		// Append code
		fieldGoName := g.gen.GetFieldName(inputType, field)
		goPath += "." + fieldGoName
		if gogoproto.IsNullable(field) {
			checks = append(checks, goPath+" != nil")
			isNullable = true
		} else {
			isNullable = false
		}

		inputType = g.messages[strings.TrimPrefix(field.GetTypeName(), ".")]
	}

	if len(checks) > 0 {
		g.P(`if `, strings.Join(checks, " && "), `{`)
		if isNullable {
			g.P(output, ` = `, goPath)
		} else {
			g.P(output, ` = &`, goPath)
		}
		g.P(`}`)
	} else {
		if isNullable {
			g.P(output, ` = `, goPath)
		} else {
			g.P(output, ` = &`, goPath)
		}
	}
}
开发者ID:limbo-services,项目名称:core,代码行数:67,代码来源:svcauth.go


注:本文中的limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.GetName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。