merge

package
v0.0.0-...-7d797cb Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

merge is a package with support functionality for grpcConst this helps add default values from one object to many objects the code skips a lot of reflection because much can be assumed at initiation There may be some issues with this package, it is meant for mapping structs compiled via protoc/gRPC.

A Merger will not "merge" fields that are private.

usage:

var objectWithDefaultValues = ...
aMerger := merger.NewMerger(&objectWithDefaultValues)
for _, item := range myItems {
	err := aMerger.SetFields(&item)
	... item will receive non-zero/non-nil fields from objectWithDefaultValues
}

or:

aReducer := merge.NewReducer(&objectWithDefaultValues)
for _, item := range myItems {
	err := aReducer.aReducer.RemoveFields(&item)
	... item will have fields removed by comparing with the default values from objectWithDefaultValues
}

Limitation: Merging an interface{} has limitations! You might get unwanted behavior when reducing any reflect.[Map, Interface, Slice, Array, Func, Invalid] proto.Merge merges unknownFields, this does not! proto.Merge merges slices, this does not!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Merger

type Merger interface {
	SetFields(interface{}) error
}

Merger can SetFields to a receiver given values given by a donor at instance initiation via NewMerger

func NewMerger

func NewMerger(donor interface{}) Merger

NewMerger initiates the Merger, populating the []reflectTree for future merging of pointer targets panics if the donor is not a pointer

func NewProtoMerger

func NewProtoMerger(donor interface{}) Merger

NewProtoMerger returns an instance of a Merger using proto.Merge to merge Messages

type Reducer

type Reducer interface {
	RemoveFields(interface{}) error
}

Reducer can RemoveFields of a given object given values given by a reference at instance initiation via NewReducer the reducer removes fields that are equal the reference

func NewReducer

func NewReducer(reference interface{}) Reducer

NewReducer initiates a merger and returns its Reducer

type ValueWrapper

type ValueWrapper struct {
	Value      reflect.Value
	GetValue   getterFunction
	HasNoValue emptyCheckerFunction
}

Jump to

Keyboard shortcuts

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