reflect

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package reflect provides reflection-based conversion utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertViaJSON

func ConvertViaJSON(src, dst any) error

ConvertViaJSON converts between proto and struct using JSON as intermediate format. Deprecated: Use ProtoToStruct or StructToProto for better performance.

func CopyProtoFields

func CopyProtoFields(src, dst protoreflect.Message) error

CopyProtoFields copies fields from one proto message to another.

func CreateDynamicMessage

func CreateDynamicMessage(md protoreflect.MessageDescriptor) *dynamicpb.Message

CreateDynamicMessage creates a new dynamic protobuf message from a descriptor.

func DurationPBToDuration

func DurationPBToDuration(d *durationpb.Duration) time.Duration

DurationPBToDuration converts google.protobuf.Duration to time.Duration

func DurationToDurationPB

func DurationToDurationPB(d time.Duration) *durationpb.Duration

DurationToDurationPB converts time.Duration to google.protobuf.Duration

func IsZeroValue

func IsZeroValue(v reflect.Value) bool

IsZeroValue checks if a reflect.Value is the zero value for its type.

func JSONToStruct

func JSONToStruct(data []byte, v any) error

JSONToStruct converts JSON bytes to a Go struct.

func ProtoToStruct

func ProtoToStruct(msg protoreflect.Message, target any) error

ProtoToStruct converts a protobuf message to a Go struct using reflection.

func StructToJSON

func StructToJSON(v any) ([]byte, error)

StructToJSON converts a Go struct to JSON bytes.

func StructToProto

func StructToProto(src any, msg protoreflect.Message) error

StructToProto converts a Go struct to a protobuf message using reflection.

func TimeToTimestamp

func TimeToTimestamp(t time.Time) *timestamppb.Timestamp

TimeToTimestamp converts time.Time to google.protobuf.Timestamp

func TimestampToTime

func TimestampToTime(ts *timestamppb.Timestamp) time.Time

TimestampToTime converts google.protobuf.Timestamp to time.Time

Types

This section is empty.

Jump to

Keyboard shortcuts

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