Golang Fetch
MIT License
Simple fetch made in Go to simplify the life of programmer.
Go’s http package doesn’t specify request timeouts by default, allowing services to hijack your goroutines. Always specify a custom http.Client when connecting to outside services.
Default
go get github.com/rodkranz/fetch
dep ensure --add github.com/rodkranz/fetch
import (
"github.com/rodkranz/fetch"
)
To run the project test
go test -v --cover
client := fetch.NewDefault()
response, err := client.Get("http://www.google.com/", nil)
opt := fetch.Options{
Header: http.Header{
"Content-Type": []string{"application/json"},
"User-Agent": []string{"XPTO-Agent-user"},
},
}
f := fetch.New(&opt)
rsp, err := f.GetWithContext(context.Background(), "http://www.google.com", nil)
login := map[string]interface{}{
"username": "rodkranz",
"password": "loremIpsum",
}
response, err := fetch.NewDefault().
IsJSON().
Post("http://www.google.com/", fetch.NewReader(login))