This HTTP Go client for Webitel is generated from Webitel's OpenAPI specification using swagger for Go.
Once bingo & swagger are installed (see Dependencies), generate the client for all Webitel APIs, with the following make
command:
make generate-client
This runs the Swagger generation command.
To generate the client for a specific Webitel API, find the name of its tag and model in the Webitel OpenAPI specification. Then, set those as environment variables and run the command to generate it:
export API_TAG=CalendarService
export MODEL=engineCalendar
make generate-client
In order to generate the client, go-swagger
uses default templates. These templates can be customised to add custom configuration that are applied each time the client is generated.
For more information, check out the go-swagger
docs on how to use custom templates. The default template definitions for the client can be found in go-swagger/generator/templates/client/.
In this project, the custom templates can be found in templates/
. They are provided to the generation command through the flag --template-dir=templates
.
The custom templates provide added functionality for things such as authentication, TLS/SSL, retries, and custom error handling.
The client has the following friendly configuration options:
import goapi "github.com/webitel/webitel-openapi-client-go/client"
cfg := &goapi.TransportConfig{
// Host is the doman name or IP address of the host that serves the API.
Host: "dev.webitel.com",
// BasePath is the URL prefix for all API paths, relative to the host root.
BasePath: "/api",
// Schemes are the transfer protocols used by the API (http or https).
Schemes: []string{"http"},
// APIKey is an optional API key or service account token.
APIKey: os.Getenv("WEBITEL_ACCESS_TOKEN"),
// TLSConfig provides an optional configuration for a TLS client
TLSConfig: &tls.Config{},
// NumRetries contains the optional number of attempted retries
NumRetries: 3,
// RetryTimeout sets an optional time to wait before retrying a request
RetryTimeout: 0,
// RetryStatusCodes contains the optional list of status codes to retry
// Use "x" as a wildcard for a single digit (default: [429, 5xx])
RetryStatusCodes: []string{"420", "5xx"},
// HTTPHeaders contains an optional map of HTTP headers to add to each request
HTTPHeaders: map[string]string{},
}
client := goapi.NewHTTPClientWithConfig(strfmt.Default, cfg)
Checkout how the Webitel Terraform Provider initialises and uses the client here.
The goswagger
documentation have more information about how to build a client.