easy_raft

package module
v0.0.0-...-7362746 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

easy-raft

A simple wrapper for HashiCorp's Raft implementation in Go.

Overview

easy-raft provides a straightforward interface to integrate Raft consensus into your Go applications, leveraging HashiCorp's robust Raft library.

Ratio

It is not easy to use HashiCorp's Raft library without knowing many details related to Raft consensus algorithm spec. This wrapper is taking away any such overhead providing simple Raft node setup and access to it interface.

Features

  • Simplified setup and management of Raft nodes
  • Easy integration into existing Go projects
  • Example usage provided in the example directory

Getting Started

Prerequisites
  • Go 1.21 or later
Installation
go get github.com/filinvadim/easy-raft
Usage
package main

import (
	"github.com/filinvadim/easy-raft"
)

func main() {
    // Initialize and start your Raft node
    node, err := easyraft.NewEasyRaft(
        ctx,
        "localhost:6969",
        logger,
        logStore,
        stableStore,
        snapshotStore,
        transport,
        ) // Set your own configuration parameters 
    
    // Handle error
    
    defer node.Shutdown()
    
    raft := node.Raft()
    raft.Apply([]byte("some cmd"), time.Second*5) 	// Your application logic here
}

For a complete example, refer to the example directory in the repository.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the Apache License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEasyRaft

func NewEasyRaft(
	ctx context.Context,
	addr string,
	logger Logger,
	logStore LogStore,
	stableStore StableStore,
	snapshotStore SnapshotStore,
	transport Transporter,
	validators ...ConsensusValidatorFunc,
) (_ *raftService, err error)

func NewEasyRaftInMemory

func NewEasyRaftInMemory(
	ctx context.Context,
	addr string,
	logger Logger,
	validators ...ConsensusValidatorFunc,
) (*raftService, error)

NewEasyRaftInMemory is not going to network - for testing purposes

Types

type ConsensusValidatorFunc

type ConsensusValidatorFunc func(k, v string) error

type KVState

type KVState map[string]string

type LogStore

type LogStore = raft.LogStore

type Logger

type Logger = hclog.Logger

type Raft

type Raft = raft.Raft

type ServerID

type ServerID = raft.ServerID

type SnapshotStore

type SnapshotStore = raft.SnapshotStore

type StableStore

type StableStore = raft.StableStore

type Transporter

type Transporter = raft.Transport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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