versioned

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Example
Output:

"2.0.0"{"first_name":"John","last_name":"Smith"}

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotVersioned error is raised if the underlying reader has no version
	ErrNotVersioned = fmt.Errorf("no version information")
)

Functions

func IsNotVersioned

func IsNotVersioned(err error) bool

IsNotVersioned checks if error is caused by a 'not versioned' stream

func NewWriter

func NewWriter(w io.Writer, version Version) (io.Writer, error)

NewWriter creates a versioned writer that marks data with the Provided version.

func WriteFile

func WriteFile(filename string, version Version, data []byte, perm os.FileMode) error

WriteFile versioned data to file

Types

type Range

type Range = semver.Range

Range type

func MustParseRange

func MustParseRange(s string) Range

MustParseRange parses range

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses a range

type Reader

type Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

Reader is a versioned reader The Versioned Reader is a reader that can load the version of the data from a stream without assuming anything regarding the underlying encoding of your data object

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader creates a new versioned reader from a stream. It fails if the reader can not read the version from the stream. On success, the reader will have a version, and then can be used to load the data.

Example
Output:

data version is: 1.0.1
data is: my data goes here

func NewVersionedReader

func NewVersionedReader(version Version, r io.Reader) *Reader

NewVersionedReader creates a versioned reader from an un-versioned reader. It's usually used to unify the data migration work flow in case the older data file didn't have a version stamp example:

 reader, err := NewReader(file)
 if IsNotVersioned(err) {
     file.Seek(0, 0) // this is important to make u reading from start
     reader = NewVersionedReader(MustParse("0.0.0"), file)
 } else err != nil {
   // probably io error
}

func (*Reader) Version

func (r *Reader) Version() Version

Version return the version of the data

type Version

type Version = semver.Version

Version type

func MustParse

func MustParse(s string) Version

MustParse version

func Parse

func Parse(s string) (Version, error)

Parse version string

func ReadFile

func ReadFile(path string) (Version, []byte, error)

ReadFile content

Jump to

Keyboard shortcuts

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