https://github.com/trendhim/commercetools-go-sdk-legacy
Go SDK for commercetools
https://github.com/trendhim/commercetools-go-sdk-legacy
client sdk
Last synced: 5 months ago
JSON representation
Go SDK for commercetools
- Host: GitHub
- URL: https://github.com/trendhim/commercetools-go-sdk-legacy
- Owner: trendhim
- License: mit
- Fork: true (labd/commercetools-go-sdk)
- Created: 2021-07-03T10:38:42.000Z (almost 5 years ago)
- Default Branch: v0
- Last Pushed: 2024-02-09T22:34:49.000Z (over 2 years ago)
- Last Synced: 2024-06-21T15:30:56.269Z (about 2 years ago)
- Topics: client, sdk
- Language: Go
- Homepage:
- Size: 739 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Legacy SDK with Trendhim specific changes
It's not maintained, and only here to simplify our own migration towards the latest labd release.
# commercetools-go-sdk
[](https://github.com/labd/commercetools-go-sdk/workflows/)
[](https://codecov.io/gh/LabD/commercetools-go-sdk)
[](https://goreportcard.com/report/github.com/labd/commercetools-go-sdk)
[](https://godoc.org/github.com/labd/commercetools-go-sdk)
The Commercetools Go SDK is automatically generated based on the official [API specifications](https://github.com/commercetools/commercetools-api-reference)
of Commercetools. It should therefore be nearly feature complete.
The SDK was initially created for enabling the creation of the
[Terraform Provider for Commercetools](https://github.com/labd/terraform-provider-commercetools)
That provider enables you to use infrastructure-as-code principles with Commercetools.
## Using the SDK
```go
package main
import (
"context"
"fmt"
"log"
"math/rand"
"time"
"github.com/labd/commercetools-go-sdk/commercetools"
)
func main() {
// Create the new client. When an empty value is passed it will use the CTP_*
// environment variables to get the value. The HTTPClient arg is optional,
// and when empty will automatically be created using the env values.
client, err := commercetools.NewClient(&commercetools.ClientConfig{
ProjectKey: "",
Endpoints: commercetools.NewClientEndpoints("europe-west1", "gcp"),
Credentials: &commercetools.ClientCredentials{
ClientID: "",
ClientSecret: "",
Scopes: []string{""},
},
})
ctx := context.Background()
// Get or Createa product type
productTypeDraft := commercetools.ProductTypeDraft{
Name: "a-product-type",
Key: "a-product-type",
}
productType, err := client.ProductTypeGetWithKey(ctx, productTypeDraft.Key)
if productType == nil {
productType, err = client.ProductTypeCreate(ctx, &productTypeDraft)
if err != nil {
log.Println(err)
}
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
randomID := r.Int()
productDraft := &commercetools.ProductDraft{
Key: fmt.Sprintf("test-product-%d", randomID),
Name: &commercetools.LocalizedString{
"nl": "Een test product",
"en": "A test product",
},
ProductType: &commercetools.ProductTypeResourceIdentifier{
ID: productType.ID,
},
Slug: &commercetools.LocalizedString{
"nl": fmt.Sprintf("een-test-product-%d", randomID),
"en": fmt.Sprintf("a-test-product-%d", randomID),
},
}
// The last argument is optional for reference expansion
product, err := client.ProductCreate(
ctx, productDraft, commercetools.WithReferenceExpansion("taxCategory"))
if err != nil {
log.Fatal(err)
}
log.Print(product)
}
```
## Generating code
To generate code do the following steps:
- `pip install pyyaml`
- install yq (f.e. `brew install yq` on macOS)
- `git clone https://github.com/commercetools/commercetools-api-reference.git` in the folder on the same level as the commercetools-go-sdk folder
- `make generate`
### TODO for code generating the services:
- CustomObject service implementation
- Implement all traits (f.e. priceSelecting)