Last active
December 14, 2015 08:18
-
-
Save discordianfish/5056444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"log" | |
"github.com/mreiferson/go-httpclient" | |
"net/http" | |
"os" | |
"time" | |
) | |
// http PUT to given url | |
func put(url string, data []byte, timeout time.Duration) (response *http.Response, err error) { | |
client := httpclient.New() | |
client.ConnectTimeout = timeout | |
client.ReadWriteTimeout = timeout | |
request, err := http.NewRequest("PUT", url, bytes.NewReader(data)) | |
if err != nil { | |
return | |
} | |
fmt.Printf("fireing req\n") | |
response, err = client.Do(request) | |
fmt.Printf("returned\n") | |
return | |
} | |
func main() { | |
url := os.Args[1] | |
data := "hello world" | |
timeout, err := time.ParseDuration("10s") | |
if err != nil { | |
log.Fatalf("Can't parse timeout") | |
} | |
put(url, []byte(data), timeout) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fireing req
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0x4371e2]
goroutine 1 [running]:
net/http.(_Client).doFollowingRedirects(0x0, 0xc2000bb0d0, 0x698d90, 0x0, 0x0, ...)
/home/fish/dev-3rd/go/src/pkg/net/http/client.go:237 +0x62
net/http.(_Client).Do(0x0, 0xc2000bb0d0, 0x3, 0x0, 0x0, ...)
/home/fish/dev-3rd/go/src/pkg/net/http/client.go:128 +0x155
github.com/mreiferson/go-httpclient.(*HttpClient).Do(0xc2000af0c0, 0xc2000bb0d0, 0x0, 0x0, 0x0, ...)
/home/fish/dev/go/src/github.com/mreiferson/go-httpclient/httpclient.go:231 +0x132
main.put(0x7fffb1e3c4f2, 0x15, 0xc2000935c0, 0xb, 0xb, ...)
/home/fish/dev/NEW/putter.go:26 +0x1dc
main.main()
/home/fish/dev/NEW/putter.go:39 +0x107
goroutine 0 [syscall]:
exit status 2