Categorygithub.com/polytomic/polytomic-go
modulepackage
1.9.3
Repository: https://github.com/polytomic/polytomic-go.git
Documentation: pkg.go.dev

# README

Polytomic Go Library

go shield

The Polytomic Go library provides convenient access to the Polytomic API from Go.

Requirements

This module requires Go version >= 1.13.

Installation

Run the following command to use the Polytomic Go library in your module:

go get github.com/polytomic/polytomic-go

Usage

import (
  polytomic "github.com/polytomic/polytomic-go"
  polytomicgoclient "github.com/polytomic/polytomic-go/client"
  "github.com/polytomic/polytomic-go/option"
)

client := polytomicgoclient.NewClient(
  option.WithToken("<YOUR_AUTH_TOKEN>"),
)

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "acme",
  },
)

Timeouts

Setting a timeout for each individual request is as simple as using the standard context library. Setting a one second timeout for an individual API call looks like the following:

ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "acme",
  },
)

Request Options

A variety of request options are included to adapt the behavior of the library, which includes configuring authorization tokens, or providing your own instrumented *http.Client. Both of these options are shown below:

client := polytomicgoclient.NewClient(
  option.WithToken("<YOUR_AUTH_TOKEN>"),
  option.WithHTTPClient(
    &http.Client{
      Timeout: 5 * time.Second,
    },
  ),
)

These request options can either be specified on the client so that they're applied on every request (shown above), or for an individual request like so:

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "acme",
  },
)

Providing your own *http.Client is recommended. Otherwise, the http.DefaultClient will be used, and your client will wait indefinitely for a response (unless the per-request, context-based timeout is used).

Automatic Retries

The Polytomic Go client is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 409 (Conflict)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

You can use the option.WithMaxAttempts option to configure the maximum retry limit to your liking. For example, if you want to disable retries for the client entirely, you can set this value to 1 like so:

client := polytomicgoclient.NewClient(
  option.WithMaxAttempts(1),
)

This can be done for an individual request, too:

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "acme",
  },
  option.WithMaxAttempts(1),
)

Errors

Structured error types are returned from API calls that return non-success status codes. For example, you can check if the error was due to an unauthorized error (i.e. status code 401) with the following:

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "invalid organization name",
  },
)
if err != nil {
  if unauthorizedErr, ok := err.(*polytomic.UnauthorizedError);
    // Do something with the unauthorized error ...
  }
  return err
}

These errors are also compatible with the errors.Is and errors.As APIs, so you can access the error like so:

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "invalid organization name",
  },
)
if err != nil {
  var unauthorizedErr *polytomic.UnauthorizedError
  if errors.As(err, unauthorizedErr) {
    // Do something with the unauthorized error ...
  }
  return err
}

If you'd like to wrap the errors with additional information and still retain the ability to access the type with errors.Is and errors.As, you can use the %w directive:

response, err := client.Organization.Create(
  context.TODO(),
  &polytomic.V2CreateOrganizationRequestSchema{
    Name: "invalid organization name",
  },
)
if err != nil {
  return fmt.Errorf("failed to create organization: %w", err)
}

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README.md are always very welcome!

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Bool returns a pointer to the given bool value.
Byte returns a pointer to the given byte value.
Complex128 returns a pointer to the given complex128 value.
Complex64 returns a pointer to the given complex64 value.
Float32 returns a pointer to the given float32 value.
Float64 returns a pointer to the given float64 value.
Int returns a pointer to the given int value.
Int16 returns a pointer to the given int16 value.
Int32 returns a pointer to the given int32 value.
Int64 returns a pointer to the given int64 value.
Int8 returns a pointer to the given int8 value.
MustParseDate attempts to parse the given string as a date time.Time, and panics upon failure.
MustParseDateTime attempts to parse the given string as a datetime time.Time, and panics upon failure.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Rune returns a pointer to the given rune value.
String returns a pointer to the given string value.
Time returns a pointer to the given time.Time value.
Uint returns a pointer to the given uint value.
Uint16 returns a pointer to the given uint16 value.
Uint32 returns a pointer to the given uint32 value.
Uint64 returns a pointer to the given uint64 value.
Uint8 returns a pointer to the given uint8 value.
Uintptr returns a pointer to the given uintptr value.
UUID returns a pointer to the given uuid.UUID value.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Environments defines all of the API environments.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Bad Request.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Either `field` or `field_id` must be provided.
Forbidden.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Internal Server Error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Not Found.
No description provided by the author
No description provided by the author
No description provided by the author
Either `field` or `field_id` must be provided.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Unauthorized.
Unprocessable Entity.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Similar to a model configuration, this configures the enricher.
A map of parent model Source Name to child model Source Name.
No description provided by the author
A map of `fieldSource` -> `fieldName: fieldValue`.
No description provided by the author
No description provided by the author