duanrenzou1619 2018-01-18 22:02
浏览 24
已采纳

AWS Firehose and Go问题

I am trying to send a simple file to Firehose in Go and keep getting:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4015b7]

goroutine 1 [running]:
panic(0x8b9260, 0xc82000a0e0)
    /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
main.main()
    /home/ubuntu/go/src/github.com/user/proj/txtParser.go:68 +0x5b7
exit status 2

below is the small script

package main

import (
"fmt"
"github.com/aws/aws-sdk-go/service/firehose"
"github.com/aws/aws-sdk-go/aws/session"
"io/ioutil"
"log"   
)

func main() {

  sess := session.Must(session.NewSession())

  svc := firehose.New(sess)

  firehoseData, err := ioutil.ReadFile("/tmp/adsDat1")

  if err != nil {
    log.Fatal(err)
  }

  var rec *firehose.Record

  var recInput *firehose.PutRecordInput

  rec.SetData(firehoseData)
  recInput.SetDeliveryStreamName("test-ads-txt")
  recInput.SetRecord(rec)

  res, err1 := svc.PutRecord(recInput)

  if err1 != nil {
   log.Fatal(err1)
  }
  fmt.Println(res)
}

Any ideas on what is going on I am sure it is something quite simple but I have been staring at this for too long and can't seem to figure it out.

  • 写回答

1条回答 默认 最新

  • doubiantiao4994 2018-01-19 19:00
    关注

    Figured it out, I declared my variable using a pointer of the type instead of declaring my variable with the type. See how it should be below

     var rec firehose.Record
    
     var recInput firehose.PutRecordInput
    

    also added the address into these instead of the variable

     recInput.SetRecord(&rec)
    
     res, err1 := svc.PutRecord(&recInput)
    

    and it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用