monotone

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 10 Imported by: 0

README

Monotone Client for Go

Monotone Client is wrapper native Monotone API using the awesome purego library to call C.

Installing

go get -u github.com/oskoi/monotone-go

Example

package main

import (
	"errors"
	"fmt"
	"io"
	"log"
	"math"

	"github.com/oskoi/monotone-go"
)

func main() {
	db := monotone.New()
	err := db.Open("./example_repo")
	handleErr(err, "open")
	defer db.Close()

	// write one million events using batches
	batch := make([]*monotone.Event, 200)
	for j := range batch {
		batch[j] = &monotone.Event{Id: math.MaxUint64}
	}
	for range 5000 {
		err = db.Write(batch)
		handleErr(err, "write")
	}

	// read all events, starting from zero
	key := monotone.Event{}
	cur, err := db.Cursor(key)
	handleErr(err, "cursor")

	total := 0
	for {
		events, err := cur.Read(200)
		total += len(events)
		if err != nil {
			if errors.Is(err, io.EOF) {
				break
			}
		}
	}

	fmt.Println("total:", total)

	// show statistics
	bs, err := db.Execute("show storages")
	handleErr(err, "execute")

	fmt.Println(string(bs))
}

func handleErr(err error, msg string) {
	if err != nil {
		log.Fatalf("%s: %v", msg, err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("closed")

Functions

This section is empty.

Types

type Cursor

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

func (*Cursor) Key

func (c *Cursor) Key() *Event

func (*Cursor) Read

func (c *Cursor) Read(n int) ([]*Event, error)

type Event

type Event struct {
	Id    uint64 `json:"id,omitempty"`
	Key   []byte `json:"key,omitempty"`
	Value []byte `json:"value,omitempty"`
}

type Monotone

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

func New

func New() *Monotone

func (*Monotone) Close

func (m *Monotone) Close()

func (*Monotone) Cursor

func (m *Monotone) Cursor(key Event) (*Cursor, error)

func (*Monotone) Delete

func (m *Monotone) Delete(batch []*Event) error

func (*Monotone) Error

func (m *Monotone) Error() error

func (*Monotone) Execute

func (m *Monotone) Execute(command string) ([]byte, error)

func (*Monotone) Open

func (m *Monotone) Open(s string) error

func (*Monotone) Read added in v0.1.1

func (m *Monotone) Read(key Event, n int) ([]*Event, error)

func (*Monotone) Write

func (m *Monotone) Write(batch []*Event) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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