go get github.com/chargehound/chargehound-go
This library currently requires go >= 1.17.
Every resource is accessed via the Client
instance:
ch := chargehound.New("{{your_api_key}}", nil)
Go requests use defined structs to represent parameters.
params := chargehound.UpdateDisputeParams{
ID: "dp_123",
Template: "unrecognized",
Fields: map[string]interface{}{
"customer_name": "Susie Chargeback",
},
}
dispute, err := ch.Disputes.Submit(¶ms)
Responses from the API are automatically parsed from JSON and returned as Go structs.
Responses also include the HTTP status code on the response object as the status field.
dispute, err := ch.Disputes.Retrieve("dp_123")
fmt.Println("{}", dispute.State)
// "needs_response"
fmt.Println("{}", dispute.Response.Status)
// 200
The Go library returns adapted structs rather than JSON from API calls.
If you're using the library in a Google App Engine environment, you can pass a custom http client along with each request. OptHTTPClient
is defined on all param structs.
import (
"net/http"
"google.golang.org/appengine"
"google.golang.org/appengine/urlfetch"
"github.com/chargehound/chargehound-go"
)
ch := chargehound.New("{{your_api_key}}", nil)
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
httpClient := urlfetch.Client(c)
params := chargehound.ListDisputeParams{
OptHTTPClient: &httpClient
}
disputes, err := ch.Disputes.List(¶ms)
}
Clone the latest source and run the tests:
$ git clone git@github.com:chargehound/chargehound-go.git
$ go test
Be sure to run gofmt on any code you plan on checking in.
gofmt -s -w .
To deploy a new version of the SDK, perform the following steps:
- Update the CHANGELOG to describe what features have been added.
- Bump the version number in
chargehound.go
. - Create a tag for the version.
git tag -a v{version} -m {message}
- Push the tag to origin.
git push origin v{version}