Documentation
¶
Overview ¶
Package types provides values used by generated Databricks SDK models, including typed field masks and Protocol Buffer-compatible timestamps and durations.
Index ¶
Examples ¶
Constants ¶
const ( // MaxDurationSeconds is the largest valid Duration seconds value, inclusive. MaxDurationSeconds = int64(315_576_000_000) // MinDurationSeconds is the smallest valid Duration seconds value, inclusive. MinDurationSeconds = -MaxDurationSeconds // MaxDurationNanos is the largest valid Duration nanoseconds value, inclusive. MaxDurationNanos = int32(999_999_999) // MinDurationNanos is the smallest valid Duration nanoseconds value, inclusive. MinDurationNanos = -MaxDurationNanos )
const ( // MinTimestampSeconds is 0001-01-01T00:00:00Z in Unix seconds, the // smallest valid Time seconds value. MinTimestampSeconds = int64(-62_135_596_800) // MaxTimestampSeconds is 9999-12-31T23:59:59Z in Unix seconds, the // largest valid Time seconds value. MaxTimestampSeconds = int64(253_402_300_799) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Duration ¶
type Duration struct {
// Seconds is the signed whole-second component.
Seconds int64
// Nanos is the signed fractional-second component in nanoseconds.
Nanos int32
}
Duration is a signed, fixed-length span of time with nanosecond precision. It models the google.protobuf.Duration well-known type without the range loss of time.Duration.
The zero value represents a duration of zero. Seconds must be between -315,576,000,000 and +315,576,000,000, inclusive. Nanos must be between -999,999,999 and +999,999,999, inclusive, and must have the same sign as Seconds when both are non-zero. Duration.CheckValid checks these invariants.
Its representation, range, and normalization rules follow the google.protobuf.Duration definition.
func NewFromDuration ¶
NewFromDuration constructs a valid Duration from a standard-library duration.
Example ¶
package main
import (
"fmt"
"time"
"github.com/databricks/sdk-go/core/types"
)
func main() {
requestTimeout := types.NewFromDuration(15 * time.Minute)
fmt.Println(requestTimeout)
}
Output: 900s
func (*Duration) Add ¶
Add returns the sum of d and other with the nanoseconds normalized. Add expects each non-nil operand to satisfy Duration.CheckValid and does not validate either operand. It does not clamp the result to the Duration range; callers can continue arithmetic and use CheckValid on the final result. Add returns nil when d is nil. A nil other is treated as zero.
func (*Duration) AsDuration ¶
AsDuration converts d to a standard-library duration. It returns the nearest time.Duration boundary when d is outside the standard library's range. A nil receiver converts to zero.
func (*Duration) CheckValid ¶
CheckValid returns an error unless d satisfies the Protocol Buffers Duration range and normalization rules. A nil Duration is invalid.
func (Duration) MarshalJSON ¶
MarshalJSON encodes d as a ProtoJSON Duration, using zero, three, six, or nine fractional digits as needed to represent its nanoseconds exactly. It returns an error when d does not satisfy Duration.CheckValid.
See the ProtoJSON well-known type mapping.
func (*Duration) String ¶
String returns a formatted representation of d as signed seconds with an "s" suffix. It returns "<nil>" for a nil receiver. Invalid field combinations are rendered as their component values.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON decodes the SDK's accepted subset of ProtoJSON Duration inputs. It accepts the form -?(0|[1-9][0-9]*)(\.[0-9]{1,9})?s. It intentionally rejects non-canonical extensions such as a leading plus sign or a missing digit on either side of the decimal point. The JSON value must be a string; null is rejected. If decoding fails, d is unchanged.
See the ProtoJSON well-known type mapping.
type FieldMask ¶
type FieldMask[T any] struct { // contains filtered or unexported fields }
FieldMask represents normalized wire paths for fields of T. T is expected to be a generated SDK model. Custom types that reproduce the generator's reflection metadata may work but are not supported.
func NewFieldMask ¶
NewFieldMask validates paths against the fields of T and returns their sorted, deduplicated, and parent-subsumed representation. The path "*" represents full replacement and subsumes all other valid paths.
func (FieldMask[T]) MarshalJSON ¶
MarshalJSON encodes the normalized field mask as a JSON string.
func (*FieldMask[T]) UnmarshalJSON ¶
UnmarshalJSON decodes and validates a comma-separated field mask without changing the receiver when validation fails.
type Time ¶
type Time struct {
// Seconds is the number of whole seconds since the Unix epoch.
Seconds int64
// Nanos is the non-negative fractional-second component in nanoseconds.
Nanos int32
}
Time is an instant with nanosecond precision. It models the google.protobuf.Timestamp well-known type.
The zero value represents the Unix epoch, 1970-01-01T00:00:00Z. Seconds is limited to instants from 0001-01-01T00:00:00Z through 9999-12-31T23:59:59Z, inclusive. Nanos must be between 0 and 999,999,999, inclusive. Time.CheckValid checks these invariants.
Its representation and range follow the google.protobuf.Timestamp definition.
Example (ComparisonUsingStandardLibrary) ¶
package main
import (
"fmt"
"time"
"github.com/databricks/sdk-go/core/types"
)
func main() {
updatedAt := types.NewFromTime(time.Date(2024, time.January, 15, 10, 30, 0, 0, time.UTC))
expiresAt := types.NewFromTime(time.Date(2024, time.January, 15, 11, 30, 0, 0, time.UTC))
fmt.Println(updatedAt.AsTime().Before(expiresAt.AsTime()))
}
Output: true
Example (ElapsedUsingStandardLibrary) ¶
package main
import (
"fmt"
"time"
"github.com/databricks/sdk-go/core/types"
)
func main() {
startedAt := types.NewFromTime(time.Date(2024, time.January, 15, 10, 30, 0, 0, time.UTC))
finishedAt := types.NewFromTime(time.Date(2024, time.January, 15, 10, 32, 30, 0, time.UTC))
fmt.Println(finishedAt.AsTime().Sub(startedAt.AsTime()))
}
Output: 2m30s
func NewFromTime ¶
NewFromTime constructs a Time from a standard-library time. Go can represent years outside the Protocol Buffers Timestamp range, so callers converting such values must use Time.CheckValid before sending them to an API.
Example ¶
package main
import (
"fmt"
"time"
"github.com/databricks/sdk-go/core/types"
)
func main() {
requestStartTime := types.NewFromTime(time.Date(
2024, time.January, 15, 11, 30, 0, 0,
time.FixedZone("UTC+1", 60*60),
))
fmt.Println(requestStartTime)
}
Output: 2024-01-15T10:30:00Z
func (*Time) Add ¶
Add returns t with d added and the nanoseconds normalized. Add expects each non-nil operand to satisfy its CheckValid method and does not validate either operand. It does not clamp the result to the Time range; callers can continue arithmetic and use Time.CheckValid on the final result. Add returns nil when t is nil. A nil d is treated as zero.
Example ¶
package main
import (
"fmt"
"time"
"github.com/databricks/sdk-go/core/types"
)
func main() {
createdAt := types.NewFromTime(time.Date(2024, time.January, 15, 10, 30, 0, 0, time.UTC))
ttl := &types.Duration{Seconds: 3_600, Nanos: 500_000_000}
expiresAt := createdAt.Add(ttl)
fmt.Println(expiresAt)
}
Output: 2024-01-15T11:30:00.500Z
func (*Time) AsTime ¶
AsTime converts t to a standard-library time in UTC. It uses time.Unix normalization for invalid field combinations rather than validating them. A nil receiver converts to the Unix epoch.
func (*Time) CheckValid ¶
CheckValid returns an error unless t satisfies the Protocol Buffers Timestamp range and normalization rules. A nil Time is invalid.
func (Time) MarshalJSON ¶
MarshalJSON encodes t as a ProtoJSON Timestamp in UTC with a Z suffix, using zero, three, six, or nine fractional digits as needed to represent its nanoseconds exactly. It returns an error when t does not satisfy Time.CheckValid.
See the ProtoJSON well-known type mapping.
func (*Time) String ¶
String returns an RFC 3339 representation of t in UTC. It returns "<nil>" for a nil receiver. Invalid field combinations are rendered as their component values.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON decodes a ProtoJSON Timestamp. It accepts UTC or numeric timezone offsets and between zero and nine fractional digits. In accordance with the protobuf Timestamp JSON form, fractional seconds use a period; the comma separator permitted by the broader RFC 3339 grammar is rejected. The JSON value must be a string; null is rejected. If decoding fails, t is unchanged.
See the ProtoJSON well-known type mapping.