types

package
v0.0.1-dev.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
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
)
View Source
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

func NewFromDuration(duration time.Duration) *Duration

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

func (d *Duration) Add(other *Duration) *Duration

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

func (d *Duration) AsDuration() time.Duration

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

func (d *Duration) CheckValid() error

CheckValid returns an error unless d satisfies the Protocol Buffers Duration range and normalization rules. A nil Duration is invalid.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

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

func (d *Duration) String() 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

func (d *Duration) UnmarshalJSON(data []byte) error

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

func NewFieldMask[T any](paths ...string) (*FieldMask[T], error)

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

func (m FieldMask[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the normalized field mask as a JSON string.

func (FieldMask[T]) String

func (m FieldMask[T]) String() string

String returns the normalized wire paths separated by commas.

func (*FieldMask[T]) UnmarshalJSON

func (m *FieldMask[T]) UnmarshalJSON(data []byte) error

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

func NewFromTime(value time.Time) *Time

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

func (t *Time) Add(d *Duration) *Time

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

func (t *Time) AsTime() time.Time

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

func (t *Time) CheckValid() error

CheckValid returns an error unless t satisfies the Protocol Buffers Timestamp range and normalization rules. A nil Time is invalid.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

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

func (t *Time) String() 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

func (t *Time) UnmarshalJSON(data []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL