-
报错内容
golang: panic: protobuf tag not enough fields in AwardMailData.state: goroutine 69 [running]: github.com/gogo/protobuf/proto.(*unmarshalInfo).computeUnmarshalInfo(0xc0004e0500) D:/go/pkg/mod/github.com/gogo/protobuf@v1.3.2/proto/table_unmarshal.go:341 +0x2154 github.com/gogo/protobuf/proto.(*unmarshalInfo).unmarshal(0xc0004e0500, {0xc0006927d0}, {0xc000309bd0, 0x3, 0x8}) D:/go/pkg/mod/github.com/gogo/protobuf@v1.3.2/proto/table_unmarshal.go:138 +0x85 github.com/gogo/protobuf/proto.(*InternalMessageInfo).Unmarshal(0xc000510940, {0x148a830, 0xc0006927d0}, {0xc000309bd0, 0x3, 0x8}) D:/go/pkg/mod/github.com/gogo/protobuf@v1.3.2/proto/table_unmarshal.go:63 +0x165 github.com/gogo/protobuf/proto.(*Buffer).Unmarshal(0xc000410ba0, {0x148a830, 0xc0006927d0}) D:/go/pkg/mod/github.com/gogo/protobuf@v1.3.2/proto/decode.go:424 +0x417
-
pb文件引用情况
- pb文件(api.pb.go)
`
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.10
// protoc v5.28.0--rc3
// source: client_api.proto
package client_api
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
`
- 引用模块文件(handle.go)
`
package handler
import (
"context"
pb "games/api"
"games/app/mail/internal/service"
"github.com/gogo/protobuf/proto"
"github.com/redis/go-redis/v9"
)
`
-
报错原因
解析pb文件库和生成库不一致
-
生成库: "google.golang.org/protobuf/runtime/protoimpl"
-
解析库: "github.com/gogo/protobuf/proto"
-
解决
解析库替换为: "google.golang.org/protobuf/proto"
