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.

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

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解