diff

package module
v0.0.0-...-c28b97f Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2017 License: MIT Imports: 4 Imported by: 0

README

go-diff [WIP] Build Status

using structs

package main

import (
    "github.com/magicshui/go-diff"
    "log"
)
func main(){
    type M map[string]interface{}
    var a = M{
        "int_n": 123, "int_c": 123,
        "str_n": "hello", "str_c": "hello",

        "array_n": []string{"1231"}, "array_c": []string{"12313"},
    }
    var b = M{
        "int_n": 123, "int_c": 1231,
        "str_n": "hello", "str_c": "hello world",

        "array_n": []string{"1231"}, "array_c": []interface{}{"12313", 123},
    }

    for k, v := range DiffMaps(a, b).ChangedItems() {
        log.Printf("Key: %s , Value: %t", k, v.Changed)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	// contains filtered or unexported fields
}

func DiffMaps

func DiffMaps(n, o map[string]interface{}) *Diff

func DiffStructs

func DiffStructs(n, o map[string]interface{}) *Diff

func NewDiff

func NewDiff() Diff

func (*Diff) AddItem

func (d *Diff) AddItem(item DiffItem)

func (*Diff) ChangedItems

func (d *Diff) ChangedItems() map[string]DiffItem

func (*Diff) DiffMaps

func (d *Diff) DiffMaps(newMap, orgMap map[string]interface{}, prefix ...string)

func (*Diff) DiffStructs

func (d *Diff) DiffStructs(newStruct, orgStruct interface{}, prefix ...string)

func (*Diff) HadChanged

func (d *Diff) HadChanged(path ...string) (changed bool, err error)

type DiffItem

type DiffItem struct {
	Name     string
	Path     string
	OrgValue interface{}
	NewValue interface{}
	Changed  bool
}

func (DiffItem) Get

func (d DiffItem) Get() (nw, od interface{})

Jump to

Keyboard shortcuts

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