Skip to content

Add example about get response body outside the callback function #92

Description

@typenoob
package main

import (
    "bytes"
    "fmt"
    curl "github.com/andelf/go-curl"
)

func main() {
    easy := curl.EasyInit()
    defer easy.Cleanup()

    easy.Setopt(curl.OPT_URL, "https://www.baidu.com/")

    buf = new(bytes.Buffer)

    // OPTIONAL - make a callback function
    fooTest := func (ptr []byte, userdata interface{}) bool {
        buf.Write(ptr)
        return true
    }

    easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)

    if err := easy.Perform(); err != nil {
        fmt.Printf("ERROR: %v\n", err)
    } else {
       println("DEBUG: size=>", buf.Len())
       println("DEBUG: content=>", buf.String())
    }
}

What do you think? Can this helps others?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions