我在尝试使用 godynamo 管理 dynamodb 实例时遇到了问题。
我的代码旨在采用 gob 编码的字节数组并将其放入 dynamodb。
func (c *checkPointManager) CommitGraph(pop *Population) {
var blob, err = pop.GobEncodeColorGraphs()
fitness := pop.GetTotalFitness()
if err != nil {
log.Fatal(err)
}
put1 := put.NewPutItem()
put1.TableName = "CheckPoint"
put1.Item["fitnessScore"] = &attributevalue.AttributeValue{N: string(fitness)}
put1.Item["population"] = &attributevalue.AttributeValue{N: string(1)}
put1.Item["graph"] = &attributevalue.AttributeValue{B: string(blob)}
body, code, err := put1.EndpointReq()
if err != nil || code != http.StatusOK {
log.Fatalf("put failed %d %v %s\n", code, err, body)
}
fmt.Printf("values checkpointed: %d\n %v\n %s\n", code, err, body)
}
但是,每次运行此代码时,都会出现以下错误。无法转换为 Blob:Base64 编码长度应为 4 字节的倍数,但发现:25
Godynamo 不处理确保二进制数组专门转换为 base64 的问题吗?我有一个简单的方法来处理这个问题吗?