pigeongo

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

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 5 Imported by: 0

README

Pigeon-Go codecov

A JSON patch module to exchange data compatible with the JS Package Pigeon.

Production ready?

No, this is a very early unfinished version. Please use with caution.

Example

package main

import (
    "fmt"
    pigeongo "github.com/pkuebler/pigeon-go"
)

func main() {
    doc := pigeongo.NewDocument([]byte(`{ "name": "Philipp" }`))

    doc.ApplyChanges(Changes{
		Diff: []Operation{
			{
				Op:    "replace",
				Path:  "/name",
				Value: rawMessage(`"Phil"`),
				Prev:  rawMessage(`"Philipp"`),
			},
		},
		Ts:  2,
		Cid: "50reifj9hyt",
		Gid: "dva96nqsdd",
	})

    // Print JSON
    fmt.Println(doc.JSON)
    // Print Warnings
    fmt.Println(doc.Warning)
}

Custom Identifier

pigeongo.NewDocument([]byte(`[{ "attrs": { "id": 123 }, "name": "Philipp" }]`), pigeongo.WithCustomIdentifier([][]string{{"id"},{"attrs", "id"}}))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJsonpatchPatch

func NewJsonpatchPatch(diff []Operation) jsonpatch.Patch

Types

type Changes

type Changes struct {
	Diff []Operation `json:"diff"`
	Ts   int64       `json:"ts"`
	Cid  string      `json:"cid"`
	Seq  int         `json:"seq"`
	Gid  string      `json:"gid"`
}

type Document

type Document struct {
	Warning string
	// contains filtered or unexported fields
}

func NewDocument

func NewDocument(raw []byte, opts ...DocumentOption) *Document

func (*Document) ApplyChanges

func (d *Document) ApplyChanges(changes Changes)

func (*Document) FastForwardChanges

func (d *Document) FastForwardChanges() error

func (*Document) History

func (d *Document) History() []Changes

func (*Document) JSON

func (d *Document) JSON() []byte

func (*Document) ReduceHistory

func (d *Document) ReduceHistory(minTs int64)

func (*Document) RewindChanges

func (d *Document) RewindChanges(ts int64, cid string) error

type DocumentOption

type DocumentOption func(*Document)

func WithIdentifiers

func WithIdentifiers(identifiers [][]string) DocumentOption

type Operation

type Operation struct {
	Op    string           `json:"op"`
	Path  string           `json:"path,omitempty"`
	From  string           `json:"from,omitempty"`
	Value *json.RawMessage `json:"value,omitempty"`
	Prev  *json.RawMessage `json:"_prev,omitempty"`
}

Jump to

Keyboard shortcuts

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