title: Golang Gphoto2 slow response
body: <p>I'm having a somewhat strange issue with a Go program I wrote that I think may be related to the C library that I'm calling.  The longer the program runs the longer the response time becomes for retrieving a picture.  I'm not what would even be considered a passable C programmer and I'm still new to load C from Go.  I wrote a simple REST interface around a gphoto2 library that allow me to remotely trigger a camera and retrieve the photo.  Ideally I'm going to use it to create a timelapse so I need it to run very long term.  Here's the wrapper:</p>
  
  <pre><code>camera := new(gphoto2go.Camera)
  err := camera.Init()
  if err &gt; 0 {
      log.Println(err)
  }
  r := gin.Default()
  r.GET("/ping", func(c *gin.Context) {
      c.JSON(200, gin.H{
          "message": "pong",
      })
  })
  
  r.GET("/shot", func(c *gin.Context) {
      //camera.Interrupt()
      cameraFilePath, err := camera.TriggerCaptureToFile()
      if err == 0 {
  
          cameraFileReader := camera.FileReader(cameraFilePath.Folder, cameraFilePath.Name)
          defer cameraFileReader.Close()
          buf := new(bytes.Buffer)
          buf.ReadFrom(cameraFileReader)
  
          //camera.DeleteFile(cameraFilePath.Folder, cameraFilePath.Name)
          encodedImage := base64.StdEncoding.EncodeToString(buf.Bytes())
          c.JSON(200, gin.H{
              "image": encodedImage,
          })
          buf.Reset()
          //c.Data(200, "image/jpeg", buf.Bytes())
  
      } else {
          log.Println(gphoto2go.CameraResultToString(err))
          c.Error(errors.New(gphoto2go.CameraResultToString(err)))
          c.JSON(http.StatusInternalServerError, gphoto2go.CameraResultToString(err))
          return
      }
  
  })
  r.Run()
  </code></pre>
  
  <p>Here's the C function from libgphoto2-dev that it's calling:</p>
  
  <pre><code>func (c *Camera) TriggerCaptureToFile() (CameraFilePath, int) {
  var path CameraFilePath
  var _path C.CameraFilePath
  err := C.gp_camera_capture(c.camera, CAPTURE_IMAGE, &amp;_path, c.context)
  path.Name = C.GoString(&amp;_path.name[0])
  path.Folder = C.GoString(&amp;_path.folder[0])
  log.Println(path.Name)
  log.Println(path.Folder)
  return path, int(err)
  </code></pre>
  
  <p>}</p>
  
  <p>Finally, here's the output.  When I first start the program it takes just a few seconds to retrieve the picture, after a couple of hours it's north of 2 mintues.</p>
  
  <pre><code>Response Status: 200 OK
  2017/05/28 15:50:35 
  Response Time: 3.217692348s
  2017/05/28 15:50:35 
  
  
  Response Status: 200 OK
  2017/05/28 19:27:04 
  Response Time: 2m5.010491487s
  2017/05/28 19:27:04 
  </code></pre>