douzhao9608 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条回答 默认 最新

  • doupai8095 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.

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

报告相同问题?