In order to move from versions 1.x
to version 2.0.0
, there are some breaking changes that need to be accounted for. This guide will address overall changes happening to all service packages, and then call out important changes to individual packages.
In order to import the v2
version of the Go module, the import path for the SDK must be updated to the following schema:
import "github.com/watson-developer-cloud/go-sdk/v2/{service}"
Where {service}
represents the service you are attempting to import, i.e. assistantv1
.
For all packages, we now import the go-sdk-core/v5
module as a dependency. This replaces go-sdk-core
. Any code that previously imported the Go Core should replace their existing imports with:
"github.com/IBM/go-sdk-core/v5/core"
For all packages, the Version
property on the service struct is now a *String
. It had previously been a String
which was provided as a literal. The Go SDK Core has a convenience method to provide this string pointer:
service, err = assistantv1.NewAssistantV1(&assistantv1.AssistantV1Options{
Version: core.StringPtr("2020-04-01"),
ServiceName: "assistant",
})
In the 1.x
version of the SDK, setter methods were provided for almost all model structs for dealing with data from the service. Version 2.0.0
makes significant breaking changes in how setters are handled for these structs.
Specifically, now the only structs that have setters for their properties are structs with the naming convention {ServiceOperation}Options
. These are called Options Models
and are typically the top level struct that is passed into a function. These structs have setter methods exposed that allow the individual properties within them to be set.
For lower level models underneath these options models, they had setter methods for each individual property. As this bloated the code surface and provided little value compared to setting the property directly, we have decided in version 2.0.0
to remove these setters.
If your code editor calls out that a setter method you are using has been removed, the appropriate way to update is to set the property directly.
Version 2.0.0
of the Go SDK now includes an alternate version of each operation belonging to the service, named <operation>WithContext
. This alternate function allows you to pass in a context.Context
parameter while invoking the operation. The context.Context
parameter can be used to specify a timeout, or cancel an in-flight request. Details about context.Context
can be found here.
All service structs can be configured to retry HTTP methods in the event of an error.
You can customize the retry logic to suit your purposes. The function EnableRetries(maxRetries int, mayTretryInterval time.Duration)
allows you to configure the retry strategy that you would like to enable for the functions called by the service.
You can also disable retries by using the DisableRetries()
method exposed on the service struct.
- In the
Message()
function, the MessageInput{}'sText
property is now a*string
.
- In the
Message()
function, the MessageInput{}'sText
property is now a*string
. This can be constructed via thecore.StringPtr("{message}")
convenience method. - The
Message()
function'sMessageContext{}
struct has a propertySkills
that now accepts amap[string]assistantv2.MessageContextSkill{}
type
- The
VoiceModel
naming convention has been replaced byCustomModel
for all models and functions. For example,CreateVoiceModel
in the1.x
branch is nowCreateCustomModel
in version2.0.0
.