badgerstorage

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 5 Imported by: 0

README

certmagic-badgerstorage

Package badgerstorage implements a certmagic.Storage on top of a Badger database.

It's an alternative to the default file-system storage used by CertMagic.

Install

go get oya.to/certmagic-badgerstorage

Usage

package main

import (
	"github.com/caddyserver/certmagic"
	"github.com/dgraph-io/badger/v2"
	"log"
	"oya.to/certmagic-badgerstorage"
)

func main() {
	// setup the badger DB
	db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
	if err != nil {
		log.Fatalf("Cannot open badger memory DB: %s", err)
	}

	// set the default CertMagic storage to replace the file-system based on.
	certmagic.Default.Storage = badgerstorage.New(db)

	// setup the rest of your CertMagic stuff...
}

Documentation

Overview

Package badgerstorage implements certmagic.Storage on top of a Badger database.

It's an alternative to the default file-system storage used by CertMagic.

Example
// setup the badger DB
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
if err != nil {
	log.Fatalf("Cannot open badger memory DB: %s", err)
}

// set the default CertMagic storage to replace the file-system based on.
certmagic.Default.Storage = New(db)

// setup the rest of your CertMagic stuff...
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

type Storage struct {
	// DB is the underlying badger database
	DB *badger.DB
	// contains filtered or unexported fields
}

Storage implements certmagic.Storage

func New

func New(db *badger.DB) *Storage

New return a new Storage using db to store persisted data.

func (*Storage) Delete

func (sto *Storage) Delete(key string) error

Delete implements certmagic.Storage.Delete

func (*Storage) Exists

func (sto *Storage) Exists(key string) bool

Exists implements certmagic.Storage.Exists

func (*Storage) List

func (sto *Storage) List(prefix string, recursive bool) ([]string, error)

List implements certmagic.Storage.List

func (*Storage) Load

func (sto *Storage) Load(key string) ([]byte, error)

Load implements certmagic.Storage.Load

func (*Storage) Lock

func (sto *Storage) Lock(key string) error

Lock implements certmagic.Storage.Lock

func (*Storage) Stat

func (sto *Storage) Stat(key string) (certmagic.KeyInfo, error)

Stat implements certmagic.Storage.Stat

func (*Storage) Store

func (sto *Storage) Store(key string, value []byte) error

Store implements certmagic.Storage.Store

func (*Storage) Unlock

func (sto *Storage) Unlock(key string) error

Unlock implements certmagic.Storage.Unlock

Jump to

Keyboard shortcuts

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