rfyiamcool/grpcall

grpcall.SetProtoFiles()不生效

karldoenitz opened this issue · 0 comments

grpcall.SetProtoFiles("本地绝对路径", "proto文件名")
grpcall.SetMode(grpcall.ProtoFilesMode)
err := grpcall.InitDescSource()
if err != nil {
	panic(err.Error())
}
grpcEnter.Init()

报错:panic: runtime error: invalid memory address or nil pointer dereference
代码执行到core.go的第61行崩溃了。
看了一下,传入的DescriptorSource是个nil,跟进看了一下代码,问题出在enter.go的158行,用一个空值覆盖了原先已经解析出来的值,把这一行删掉就行了,ext:

// enter.go 158行
func (d *DescSourceEntry) InitDescSource() error {
	var err error
	var desc DescriptorSource

	switch descSourceController.descMode {
	case ProtoSetMode:
		// parse proto by protoset

		if descSourceController.protoset.IsEmpty() {
			return errors.New("protoset null")
		}

		for _, f := range descSourceController.protoset {
			ok := pathExists(f)
			if !ok {
				return errors.New("protoset file not exist")
			}
		}

		desc, err = DescriptorSourceFromProtoSets(descSourceController.protoset...)
		if err != nil {
			return errors.New("Failed to process proto descriptor sets")
		}

		descSourceController.descSource = desc

	case ProtoFilesMode:
		// parse proto by protoFiles
		descSourceController.descSource, err = DescriptorSourceFromProtoFiles(
			descSourceController.importPaths,
			descSourceController.protoFiles...,
		)
		if err != nil {
			return errors.New("Failed to process proto source files")
		}

		// descSourceController.descSource = desc 删掉这一行就好了

	default:
		return errors.New("only eq ProtoSetMode and ProtoFilesMode")
	}

	return nil
}