Interacting with the Salesforce APIs can be tricky if your favorite language doesn't have modules or packages available to handle the complexity. Of course, you can build one from scratch. However, chances you'll hit a couple of roadblocks along the way.
A couple of weeks ago, I started working on a package to interact with the Salesforce APIs in Go, currently available on Github. My main motivations were to use it for my personal projects, to leverage existing packages such as golang.org/x/oauth2 (since all the other packages seem to rebuild this part of the logic) and to improve my understanding of both the Salesforce APIs and Go.
Here's a quick example on how to execute an SOQL query using the package.
First of, you will have to create an http client implementing the OAuth2 specification. To achieve this, github.com/jpmonette/force is leveraging the oauth2 package built by Google.
28 c.Query("SELECT Id, Name FROM Account LIMIT 10", &data)
29
30 fmt.Println("Total size: " + data.TotalSize)
31 fmt.Println("First ID: " + data.Records[0].Id)
32
33}
34
35// QueryReponse is used to Unmarshal the SOQL query response
36type QueryReponse struct {
37 TotalSize int `json:"totalSize"`
38 Records []struct {
39 ID string `json:"Id"`
40 Name string `json:"Name"`
41 Attributes struct {
42 Type string `json:"type"`
43 URL string `json:"url"`
44 } `json:"attributes"`
45 } `json:"records"`
46}
Now - if you go get github.com/jpmonette/force and go run main.go, the console should output something similar to:
1~ » go run main.go
2Total size: 10
3First ID: 001b000002T9ak4
1~ » go run main.go
2Total size: 10
3First ID: 001b000002T9ak4
Notes: For simplicity, error checking has been omitted in the example.
Please note that this package is inspired by the go-github package. Since it is a work in progress, you are more than welcomed to send pull requests to support additional features.
∎