All Projects → imdario → Mergo

imdario / Mergo

Licence: bsd-3-clause
Written by Dario Castañé.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Mergo

mergedeep
A deep merge function for 🐍.
Stars: ✭ 73 (-95.96%)
Mutual labels:  mapping, merge
Uav Mapper
UAV-Mapper is a lightweight UAV Image Processing System, Visual SFM reconstruction or Aerial Triangulation, Fast Ortho-Mosaic, Plannar Mosaic, Fast Digital Surface Map (DSM) and 3d reconstruction for UAVs.
Stars: ✭ 106 (-94.14%)
Mutual labels:  mapping
Obaddon
A repository of community-built prefabs and other enhancements for Oblige 7.70
Stars: ✭ 81 (-95.52%)
Mutual labels:  mapping
Mapster
A fast, fun and stimulating object to object Mapper
Stars: ✭ 1,375 (-23.95%)
Mutual labels:  mapping
Covid Charts
A collection of JavaScript-based data visualization tools and data for depicting spread of the COVID-19
Stars: ✭ 88 (-95.13%)
Mutual labels:  mapping
Lychee
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.
Stars: ✭ 102 (-94.36%)
Mutual labels:  mapping
Tadbit
TADbit is a complete Python library to deal with all steps to analyze, model and explore 3C-based data. With TADbit the user can map FASTQ files to obtain raw interaction binned matrices (Hi-C like matrices), normalize and correct interaction matrices, identify and compare the so-called Topologically Associating Domains (TADs), build 3D models from the interaction matrices, and finally, extract structural properties from the models. TADbit is complemented by TADkit for visualizing 3D models
Stars: ✭ 78 (-95.69%)
Mutual labels:  mapping
Turtlebot exploration 3d
Autonomous Exploration package for a Turtulebot equiped with RGBD Sensor(Kinect, Xtion)
Stars: ✭ 109 (-93.97%)
Mutual labels:  mapping
Gdl
GDL - GNU Data Language
Stars: ✭ 104 (-94.25%)
Mutual labels:  mapping
Evo
Python package for the evaluation of odometry and SLAM
Stars: ✭ 1,373 (-24.06%)
Mutual labels:  mapping
Eao Slam
[IROS 2020] EAO-SLAM: Monocular Semi-Dense Object SLAM Based on Ensemble Data Association
Stars: ✭ 95 (-94.75%)
Mutual labels:  mapping
Leaflet Tilefilter
Change the appearance of Leaflet map tiles on the fly using a variety of canvas or CSS3 image filters. It's like Instagram for Leaflet map tiles.
Stars: ✭ 90 (-95.02%)
Mutual labels:  mapping
Lt Gee
Google Earth Engine implementation of the LandTrendr spectral-temporal segmentation algorithm. For documentation see:
Stars: ✭ 103 (-94.3%)
Mutual labels:  mapping
Mrpt slam
ROS wrappers for SLAM algorithms in MRPT
Stars: ✭ 84 (-95.35%)
Mutual labels:  mapping
Simple Tiles
Simple tile generation for maps.
Stars: ✭ 106 (-94.14%)
Mutual labels:  mapping
Examples
Self-contained examples for the legacy Maps API for JavaScript.
Stars: ✭ 78 (-95.69%)
Mutual labels:  mapping
Bughunter
Tools for Bug Hunting
Stars: ✭ 95 (-94.75%)
Mutual labels:  mapping
Rtabmap
RTAB-Map library and standalone application
Stars: ✭ 1,376 (-23.89%)
Mutual labels:  mapping
Pdfsam
PDFsam, a desktop application to extract pages, split, merge, mix and rotate PDF files
Stars: ✭ 1,829 (+1.16%)
Mutual labels:  merge
Door Slam
Distributed, Online, and Outlier Resilient SLAM for Robotic Teams
Stars: ✭ 107 (-94.08%)
Mutual labels:  mapping

Mergo

GoDoc GitHub release GoCard Build Status Coverage Status Sourcegraph FOSSA Status

GoCenter Kudos

A helper to merge structs and maps in Golang. Useful for configuration default values, avoiding messy if-statements.

Mergo merges same-type structs and maps by setting default values in zero-value fields. Mergo won't merge unexported (private) fields. It will do recursively any exported one. It also won't merge structs inside maps (because they are not addressable using Go reflection).

Also a lovely comune (municipality) in the Province of Ancona in the Italian region of Marche.

Status

It is ready for production use. It is used in several projects by Docker, Google, The Linux Foundation, VMWare, Shopify, etc.

Important note

Please keep in mind that a problematic PR broke 0.3.9. I reverted it in 0.3.10, and I consider it stable but not bug-free. Also, this version adds support for go modules.

Keep in mind that in 0.3.2, Mergo changed Merge()and Map() signatures to support transformers. I added an optional/variadic argument so that it won't break the existing code.

If you were using Mergo before April 6th, 2015, please check your project works as intended after updating your local copy with go get -u github.com/imdario/mergo. I apologize for any issue caused by its previous behavior and any future bug that Mergo could cause in existing projects after the change (release 0.2.0).

Donations

If Mergo is useful to you, consider buying me a coffee, a beer, or making a monthly donation to allow me to keep building great free software. 😍

Buy Me a Coffee at ko-fi.com Beerpay Beerpay Donate using Liberapay

Mergo in the wild

Install

go get github.com/imdario/mergo

// use in your .go code
import (
    "github.com/imdario/mergo"
)

Usage

You can only merge same-type structs with exported fields initialized as zero value of their type and same-types maps. Mergo won't merge unexported (private) fields but will do recursively any exported one. It won't merge empty structs value as they are zero values too. Also, maps will be merged recursively except for structs inside maps (because they are not addressable using Go reflection).

if err := mergo.Merge(&dst, src); err != nil {
    // ...
}

Also, you can merge overwriting values using the transformer WithOverride.

if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
    // ...
}

Additionally, you can map a map[string]interface{} to a struct (and otherwise, from struct to map), following the same restrictions as in Merge(). Keys are capitalized to find each corresponding exported field.

if err := mergo.Map(&dst, srcMap); err != nil {
    // ...
}

Warning: if you map a struct to map, it won't do it recursively. Don't expect Mergo to map struct members of your struct as map[string]interface{}. They will be just assigned as values.

Here is a nice example:

package main

import (
	"fmt"
	"github.com/imdario/mergo"
)

type Foo struct {
	A string
	B int64
}

func main() {
	src := Foo{
		A: "one",
		B: 2,
	}
	dest := Foo{
		A: "two",
	}
	mergo.Merge(&dest, src)
	fmt.Println(dest)
	// Will print
	// {two 2}
}

Note: if test are failing due missing package, please execute:

go get gopkg.in/yaml.v2

Transformers

Transformers allow to merge specific types differently than in the default behavior. In other words, now you can customize how some types are merged. For example, time.Time is a struct; it doesn't have zero value but IsZero can return true because it has fields with zero value. How can we merge a non-zero time.Time?

package main

import (
	"fmt"
	"github.com/imdario/mergo"
        "reflect"
        "time"
)

type timeTransformer struct {
}

func (t timeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
	if typ == reflect.TypeOf(time.Time{}) {
		return func(dst, src reflect.Value) error {
			if dst.CanSet() {
				isZero := dst.MethodByName("IsZero")
				result := isZero.Call([]reflect.Value{})
				if result[0].Bool() {
					dst.Set(src)
				}
			}
			return nil
		}
	}
	return nil
}

type Snapshot struct {
	Time time.Time
	// ...
}

func main() {
	src := Snapshot{time.Now()}
	dest := Snapshot{}
	mergo.Merge(&dest, src, mergo.WithTransformers(timeTransformer{}))
	fmt.Println(dest)
	// Will print
	// { 2018-01-12 01:15:00 +0000 UTC m=+0.000000001 }
}

Contact me

If I can help you, you have an idea or you are using Mergo in your projects, don't hesitate to drop me a line (or a pull request): @im_dario

About

Written by Dario Castañé.

License

BSD 3-Clause license, as Go language.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].