ccc

package module
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 15 Imported by: 9

README

ccc

Utility types and functions created and maintained by the CCC team.

Documentation

Overview

Package ccc contains utility types and functions

Index

Constants

This section is empty.

Variables

View Source
var NilUUID = UUID{}

NilUUID represents the nil value of UUID

Functions

func BatchIter2 added in v0.2.14

func BatchIter2[T any](iter2 iter.Seq2[T, error], size int) iter.Seq[iter.Seq2[T, error]]

BatchIter2 takes an iter.Seq2 and returns an iter.Seq of iter.Seq2, where each inner iter.Seq2 yields a batch of T of the specified size.

BatchIter2 returns a single-use iterator, but can take in a reusable iterator.

The inner batch iterator must be ranged over with a range loop (or iter.Pull) before the next outer iterator can be accessed. It is acceptable to break early from a range loop, in which case the remaining items will be returned by the next outer iterator. If the inner iterator is not propery ranged over, the outer iterator will panic.

If the provided size is not a positive integer, the returned iterator will yield a single error.

Example:

for batch := range BatchIter2(myIter, 10) {
	// Do some operation between batches such as start a new db transaction

	for resource, err := range batch {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(resource)
	}
}

func Must added in v0.2.1

func Must[T any](value T, err error) T

Must is a helper function to avoid the need to check for errors.

func NextIter added in v0.2.14

func NextIter[T any](r NextIterator[T]) iter.Seq2[T, error]

NextIter returns a reusable iter.Seq2 iterator from anything that implements the NextIterator interface.

func Ptr

func Ptr[T any](t T) *T

Ptr returns a pointer to the given value t.

func ReadIter added in v0.2.14

func ReadIter[T any](r ReadIterator[T]) iter.Seq2[T, error]

ReadIter returns a reusable iter.Seq2 iterator from anything that implements the ReadIterator interface.

func StartTrace deprecated added in v0.2.15

func StartTrace(ctx context.Context) (context.Context, trace.Span)

StartTrace uses runtime reflection to determine the fully qualified package path and the function/method name of the caller.

The Tracer name is set to the fully qualified package path (e.g., "github.com/cccteam/ccc"). The Span name is set to the short function name (e.g., "Struct.Method()").

Deprecated: Use github.com/cccteam/ccc/tracer.Start instead

Types

type Duration added in v0.2.8

type Duration struct {
	time.Duration
}

Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years. This custom type provides support for marshaling to and from text, json, and Spanner.

func NewDuration added in v0.2.9

func NewDuration(d time.Duration) Duration

NewDuration returns a Duration from a time.Duration

func NewDurationFromString added in v0.2.9

func NewDurationFromString(s string) (Duration, error)

NewDurationFromString parses a Duration from a string representation in the same manner as time.ParseDuration(), but with the added step of removing any whitespace from the string.

func (*Duration) DecodeSpanner added in v0.2.8

func (d *Duration) DecodeSpanner(val any) error

DecodeSpanner implements the spanner.Decoder interface

func (Duration) EncodeSpanner added in v0.2.8

func (d Duration) EncodeSpanner() (any, error)

EncodeSpanner implements the spanner.Encoder interface

func (Duration) MarshalJSON added in v0.2.8

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

MarshalJSON implements json.Marshaler interface for Duration.

func (Duration) MarshalText added in v0.2.8

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

MarshalText implements the encoding.TextMarshaler interface

func (*Duration) UnmarshalJSON added in v0.2.8

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

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON for Duration.

func (*Duration) UnmarshalText added in v0.2.8

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.Unmarshaler interface

type JSONMap

type JSONMap map[string]any

JSONMap is a map that can be unmarshalled from JSON, converting all json.Number values to their appropriate int or float64 types.

func (*JSONMap) UnmarshalJSON

func (jM *JSONMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type NextIterator added in v0.2.14

type NextIterator[T any] interface {
	Next() bool
	Value() T
	Error() error
}

NextIterator implements an interface where each Next() yields the next item from the Reader, with Error() returning any problems that occur during the Next() call. This iterator will start with a Next() call. If Next() returns true, it will call Value(). This will continue until Next() returns false, at which point it will call Error() one time.

type NullDuration added in v0.2.9

type NullDuration struct {
	Duration
	Valid bool
}

NullDuration handles null values of the Duration type

func NewNullDuration added in v0.2.9

func NewNullDuration(d time.Duration) NullDuration

NewNullDuration returns a NullDuration from a time.Duration

func NewNullDurationFromString added in v0.2.9

func NewNullDurationFromString(s string) (NullDuration, error)

NewNullDurationFromString parses a NullDuration from a string representation

func (*NullDuration) DecodeSpanner added in v0.2.9

func (d *NullDuration) DecodeSpanner(val any) error

DecodeSpanner implements the spanner.Decode interface

func (NullDuration) EncodeSpanner added in v0.2.9

func (d NullDuration) EncodeSpanner() (any, error)

EncodeSpanner implements the spanner.Encode interface

func (NullDuration) MarshalJSON added in v0.2.9

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

MarshalJSON implements json.Marshaler interface for Duration.

func (NullDuration) MarshalText added in v0.2.9

func (d NullDuration) MarshalText() ([]byte, error)

MarshalText implements the encoder.TextMarshaler interface

func (*NullDuration) UnmarshalJSON added in v0.2.9

func (d *NullDuration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON for Duration.

func (*NullDuration) UnmarshalText added in v0.2.9

func (d *NullDuration) UnmarshalText(text []byte) error

UnmarshalText implements the encoder.TextUnmarshaler interface

type NullEnum added in v0.2.12

type NullEnum[T ~string | ~int | ~int64 | ~float64] struct {
	Value T
	Valid bool
}

NullEnum represents a generic enum that may be null. NullEnum implements the Spanner (DecodeSpanner, EncodeSpanner), JSON (MarshalJSON, UnmarshalJSON), and Text (MarshalText, UnmarshalText) interfaces.

func (*NullEnum[T]) DecodeSpanner added in v0.2.12

func (n *NullEnum[T]) DecodeSpanner(val any) error

DecodeSpanner implements the spanner.Decoder interface

func (NullEnum[T]) EncodeSpanner added in v0.2.12

func (n NullEnum[T]) EncodeSpanner() (any, error)

EncodeSpanner implements the spanner.Encoder interface

func (NullEnum[T]) MarshalJSON added in v0.2.12

func (n NullEnum[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface for NullEnum.

func (NullEnum[T]) MarshalText added in v0.2.12

func (n NullEnum[T]) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface

func (*NullEnum[T]) UnmarshalJSON added in v0.2.12

func (n *NullEnum[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON for NullEnum.

func (*NullEnum[T]) UnmarshalText added in v0.2.12

func (n *NullEnum[T]) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type NullUUID

type NullUUID struct {
	UUID
	Valid bool
}

NullUUID represents a UUID that may be null. NullUUID implements the Spanner (DecodeSpanner, EncodeSpanner), JSON (MarshalJSON, UnmarshalJSON), and Text (MarshalText, UnmarshalText) interfaces.

func NewNullUUID

func NewNullUUID() (NullUUID, error)

NewNullUUID returns a new NullUUID

func NullUUIDFromString

func NullUUIDFromString(s string) (NullUUID, error)

NullUUIDFromString parses a NullUUID from a string representation

func NullUUIDFromUUID

func NullUUIDFromUUID(u UUID) NullUUID

NullUUIDFromUUID returns a NullUUID from a UUID

func (*NullUUID) DecodeSpanner

func (u *NullUUID) DecodeSpanner(val any) error

DecodeSpanner implements the spanner.Decoder interface

func (NullUUID) EncodeSpanner

func (u NullUUID) EncodeSpanner() (any, error)

EncodeSpanner implements the spanner.Encoder interface

func (NullUUID) IsNil

func (u NullUUID) IsNil() bool

IsNil implements NullableValue.IsNil for NullUUID.

func (NullUUID) MarshalJSON added in v0.2.3

func (u NullUUID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface for NullUUID.

func (NullUUID) MarshalText added in v0.2.3

func (u NullUUID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface

func (*NullUUID) UnmarshalJSON added in v0.2.3

func (u *NullUUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON for NullUUID.

func (*NullUUID) UnmarshalText

func (u *NullUUID) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type ReadIterator added in v0.2.14

type ReadIterator[T any] interface {
	Read() (item T, err error)
}

ReadIterator implements an interface where each Read() yields the next item from the Reader, with err returning any problems that occur during the Read() call. The semantics of how the end of stream is signaled is left up to the implementation.

This can be used to convert the csv.Read() to an iter.Seq2 as an example.

type UUID

type UUID struct {
	uuid.UUID
}

UUID represents a UUID. UUID implements the Spanner (DecodeSpanner, EncodeSpanner), JSON (MarshalJSON, UnmarshalJSON), and Text (MarshalText, UnmarshalText) interfaces.

func NewUUID

func NewUUID() (UUID, error)

NewUUID returns a new UUID

func UUIDFromString

func UUIDFromString(s string) (UUID, error)

UUIDFromString parses a UUID from a string representation

func (*UUID) DecodeSpanner

func (u *UUID) DecodeSpanner(val any) error

DecodeSpanner implements the spanner.Decoder interface

func (UUID) EncodeSpanner

func (u UUID) EncodeSpanner() (any, error)

EncodeSpanner implements the spanner.Encoder interface

func (UUID) MarshalJSON added in v0.2.3

func (u UUID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface for UUID.

func (UUID) MarshalText added in v0.2.3

func (u UUID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface

func (*UUID) UnmarshalJSON added in v0.2.3

func (u *UUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON for UUID.

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

Directories

Path Synopsis
accesstypes module
cache module
ccclint module
columnset module
lint module
linters
otelspanname module
middleware module
patchset module
pkg module
resource module
resourceset module
securehash module
sns module
tracer module

Jump to

Keyboard shortcuts

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