Documentation ¶
Index ¶
- Constants
- func ConvertJSONObjectList(entity *framework.EntityConfig, objects []map[string]any, opts ...JSONOption) ([]framework.Object, error)
- func HTTPError(statusCode int, retryAfterHeader string) (adapterErr *framework.Error)
- func ParseDateTime(dateTimeFormats []DateTimeFormatWithTimeZone, localTimeZoneOffset int, ...) (dateTime time.Time, err error)
- type DateTimeFormatWithTimeZone
- type JSONOption
Constants ¶
const ( SGNLUnixSec = "SGNLUnixSec" SGNLGeneralizedTime = "SGNLGeneralizedTime" )
Variables ¶
This section is empty.
Functions ¶
func ConvertJSONObjectList ¶
func ConvertJSONObjectList(entity *framework.EntityConfig, objects []map[string]any, opts ...JSONOption) ([]framework.Object, error)
ConvertJSONObjectList parses and converts a list of JSON objects received from the given requested entity.
func HTTPError ¶
HTTPError returns a detailed error if the given HTTP response status code indicates that the HTTP request failed, and nil otherwise.
func ParseDateTime ¶
func ParseDateTime(dateTimeFormats []DateTimeFormatWithTimeZone, localTimeZoneOffset int, dateTimeStr string) (dateTime time.Time, err error)
ParseDateTime parses a timestamp against a set of predefined formats.
Types ¶
type DateTimeFormatWithTimeZone ¶ added in v0.2.0
type DateTimeFormatWithTimeZone struct { // Format must be a valid time format accepted by time.Parse. Format string // HasTimeZone indicates whether the above time format supports specifying a time zone. // If it does, this should be set to true. // If it does not, this can be set to false to use the specified localTimeZoneOffset // as a time zone in the resulting date time. If this value is false and // localTimeZoneOffset is not set, the resulting date time will be set to UTC. HasTimeZone bool }
DateTimeFormatWithTimeZone represents a valid date time format to try parsing date-time attribute values from strings.
type JSONOption ¶
type JSONOption interface {
// contains filtered or unexported methods
}
JSONOption configures how JSON objects are parsed.
func WithComplexAttributeNameDelimiter
deprecated
func WithComplexAttributeNameDelimiter(delimiter string) JSONOption
WithComplexAttributeNameDelimiter sets the delimiter between nested objects names in attribute external IDs.
If non-empty, and an attribute's external ID includes this delimiter, the attribute is parsed as an attribute of a single-valued complex object.
For instance, if set to ".", and the JSON object to parse is:
{ "attr1": { "attr2": { "attr3": "the value" } } }
then the value returned for the attribute with external ID "attr1.attr2.attr3" is "the value".
If empty (default), single-valued complex object parsing is disabled.
Deprecated: This option is replaced with WithJSONPathAttributeNames.
func WithDateTimeFormats ¶
func WithDateTimeFormats(formats ...DateTimeFormatWithTimeZone) JSONOption
WithDateTimeFormats sets the time formats to use to try parsing date-time attribute values from strings. The formats must be ordered by decreasing likelihood of matching. Each format must be a valid time format accepted by time.Parse.
func WithJSONPathAttributeNames ¶ added in v0.5.0
func WithJSONPathAttributeNames() JSONOption
WithJSONPathAttributeNames enables attribute external IDs specified as JSONPath to match attributes in nested objects.
If enabled, and an attribute's external ID starts with '$', it is used as a JSONPath to match an attribute of a single- or multi-valued complex object.
If the attribute is configured with a list type: if one or more values matched, then the resulting value is the list of matched values, otherwise (no value matched), then the resulting value is null.
If the attribute is configured with a non-list type: if exactly one value matched, then the resulting value is that value, otherwise, if no value matched then the resulting value is null, otherwise (the JSONPath matched more than one value), an error is returned.
func WithLocalTimeZoneOffset ¶ added in v0.2.0
func WithLocalTimeZoneOffset(offset int) JSONOption
WithLocalTimeZoneOffset sets the local time zone offset to use as a default when parsing date-time attribute values from strings for formats lacking support for specifying a time zone.