Skip to content

joeybrown/automerge-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

automerge-go

automerge-go provides the ability to interact with automerge documents. It is a featureful wrapper around automerge-rs that uses wazero to run the automerge engine as an embedded WASM module, requiring no C compiler or platform-specific libraries — pure Go.

For package documentation, see the Go documentation at https://pkg.go.dev/github.com/automerge/automerge-go.

Installation

go get github.com/automerge/automerge-go

No C compiler, shared libraries, or platform-specific build steps are required. The automerge engine is compiled to WebAssembly and embedded in the Go binary via //go:embed.

Usage

package main

import (
	"fmt"
	"github.com/automerge/automerge-go"
)

func main() {
	doc := automerge.New()
	doc.RootMap().Set("hello", "world")
	doc.Commit("first change")

	bytes := doc.Save()

	doc2, _ := automerge.Load(bytes)
	val, _ := automerge.As[string](doc2.RootMap().Get("hello"))
	fmt.Println(val) // "world"
}

Architecture

Each *Doc gets its own isolated WASM module instance. The WASM module is compiled once and cached, so creating additional documents is fast (~33μs). All operations on a document are serialized via a mutex, making *Doc safe for concurrent use from multiple goroutines.

Building the WASM module from source

The pre-built automerge.wasm is embedded in the package. To rebuild it from the Rust source:

make generate

Requires Rust with the wasm32-wasip1 target:

rustup target add wasm32-wasip1

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 70.2%
  • Rust 29.7%
  • Makefile 0.1%