turnage / graw

Golang Reddit API Wrapper
MIT License
288 stars 49 forks source link

Add custom http.Client support (#66) (2b1f1db) breaks Scripts #70

Closed iwinulose closed 4 years ago

iwinulose commented 4 years ago

Commit 2b1f1dbe5d3dace5d810436b12d1a215ad79af7d breaks trivial script implementations.

E.g.

package main

import (
    "fmt"

    "github.com/turnage/graw/reddit"
)

const (
    UserAgent = "darwin:grawtest:0.0.1 (by /u/iwinulose)"
)

func main() {
    script, err := reddit.NewScript(UserAgent, 0)
    if err != nil {
        fmt.Println("Unable to create script:", err)
        return
    }

    h, err := script.Listing("/u/iwinulose", "")
    if err != nil {
        fmt.Println("Listing err", err)
        return
    }
    for _, p := range h.Posts {
        fmt.Println("Got post", p.Title)
    }
}

$ go run test.go panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x72018f]

goroutine 1 [running]: github.com/turnage/graw/reddit.(agentForwarder).RoundTrip(0xc00000e280, 0xc000148100, 0xc00000e280, 0x0, 0x0) /home/charlesduyk/go/src/github.com/turnage/graw/reddit/agentforwarder.go:17 +0xcf net/http.send(0xc000148000, 0x8587a0, 0xc00000e280, 0x0, 0x0, 0x0, 0xc000010040, 0xffffffffffffffff, 0x1, 0x0) /usr/local/go/src/net/http/client.go:252 +0x43e net/http.(Client).send(0xc00007cea0, 0xc000148000, 0x0, 0x0, 0x0, 0xc000010040, 0x0, 0x1, 0x7ff6b0dca400) /usr/local/go/src/net/http/client.go:176 +0xfa net/http.(Client).do(0xc00007cea0, 0xc000148000, 0x0, 0x0, 0x0) /usr/local/go/src/net/http/client.go:699 +0x44a net/http.(Client).Do(...) /usr/local/go/src/net/http/client.go:567 github.com/turnage/graw/reddit.(baseClient).Do(0xc000010030, 0xc000148000, 0x0, 0x0, 0x0, 0x0, 0x0) /home/charlesduyk/go/src/github.com/turnage/graw/reddit/client.go:36 +0x7c github.com/turnage/graw/reddit.(reaperImpl).reap(0xc000146000, 0x7d8aa8, 0xc, 0xc00007ced0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /home/charlesduyk/go/src/github.com/turnage/graw/reddit/reaper.go:68 +0x17e github.com/turnage/graw/reddit.(*scanner).Listing(0xc000012d50, 0x7d8aa8, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /home/charlesduyk/go/src/github.com/turnage/graw/reddit/scanner.go:42 +0x1a2 main.main() /home/charlesduyk/versionControl/dedup.git/cmd/dedup/dedup.go:20 +0x135

Checkout 2b1f1dbe5d3dace5d810436b12d1a215ad79af7d^ to return to a working state.