snapshot

package module
v0.0.0-...-9ad8f5e Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: MIT Imports: 1 Imported by: 1

README

snapshot

Travis CI

Sometimes you need to experiment.

package main

import (
  "fmt"
  "github.com/jhunt/go-snapshot"
)

type Thing struct {
  Name  string
  Value int
  On    bool
}

int main() {
  thing := Thing{
    Name:  "widget",
    Value: 4,
    On:    true,
  }

  sn, _ := snapshot.Take(&thing)

  ok := TrySomethingCrazy(&thing)
  if (ok) {
    fmt.Printf("something crazy worked!  %s = %d (on is %v)\n",
               thing.Name, thing,Value, thing.On)
    return
  }

  sn.Revert()

  ok = TrySomethingEvenCrazier(&thing)
  if (ok) {
    fmt.Printf("something EVEN CRAZIER worked!  %s = %d (on is %v)\n",
               thing.Name, thing,Value, thing.On)
    return
  }

  sn.Revert()
  fmt.Printf("nothing worked!  %s = %d (on is %v)\n",
             thing.Name, thing,Value, thing.On)
}

snapshot lets you take a point-in-time, deep-copy of an arbitrary value, be it a string, boolean, number, struct, etc., and be able to return to that point in time at some point in the future.

Contributing

This code is licensed MIT. Enjoy.

If you find a bug, please raise a Github Issue first, before submitting a PR.

When you do work up a patch, keep in mind that we have a fairly extensive test suite in snapshot_test.go. I don't care all that much about code coverage, but we do have >90% C0 code coverage on the current tests suite, and I'd like to keep it that way.

(That's not to say we've caught 90% of the bugs, but it's better than nothin')

Happy Hacking!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Snapshot

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

func Take

func Take(thing interface{}) (Snapshot, error)

func (Snapshot) Revert

func (ss Snapshot) Revert() error

Jump to

Keyboard shortcuts

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