I'm bit lost with this panic when writing gRPC server in Go
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x18 pc=0x8c7892]
Here's what I am trying to do, attempting to create a slice of test data :
inputVal := make([]*pb.TableHeader, 1)
for i := range inputVal {
inputVal[i].UserDefinedAlias = "myCustomName"
inputVal[i].Type = "SomeType"
inputVal[i].Class = "TestClass"
inputVal[i].ColumnID = "Col12"
inputVal[i].IsSortable = false
inputVal = append(inputVal, inputVal[i])
}
TableHeader has this structure
type TableHeader struct {
ColumnID string `protobuf:"bytes,1,opt,name=columnID,proto3" json:"columnID,omitempty"`
UserDefinedAlias string `protobuf:"bytes,2,opt,name=userDefinedAlias,proto3" json:"userDefinedAlias,omitempty"`
IsSortable bool `protobuf:"varint,3,opt,name=isSortable,proto3" json:"isSortable,omitempty"`
Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"`
Class string `protobuf:"bytes,5,opt,name=class,proto3" json:"class,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
And trying to process that test data created above using following in an rpc service
inputForProcessing := make([]*dt.TableHeader, len(inputVal))
log.Println("reached here for actual processing ",len(inputForProcessing))
for i, v := range inputVal {
inputForProcessing[i].ColumnID = v.ColumnID
inputForProcessing[i].Class = v.Class
inputForProcessing[i].Type = v.Type
inputForProcessing[i].IsSortable = v.IsSortable
inputForProcessing[i].UserDefinedAlias = v.UserDefinedAlias
inputForProcessing = append(inputForProcessing, inputForProcessing[i])
}