ln-paywall: github.com/philippgille/ln-paywall/storage Index | Files

package storage

import "github.com/philippgille/ln-paywall/storage"

Package storage contains storage implementations and related options.

These storage implementations satisfy the wall.StorageClient interface. You can use one of them or implement your own.

Index

Package Files

bolt.go docs.go map.go redis.go storage.go

Variables

var DefaultBoltOptions = BoltOptions{
    Path: "ln-paywall.db",
}

DefaultBoltOptions is a BoltOptions object with default values. Path: "ln-paywall.db"

var DefaultRedisOptions = RedisOptions{
    Address: "localhost:6379",
}

DefaultRedisOptions is a RedisOptions object with default values. Address: "localhost:6379", Password: "", DB: 0

type BoltClient Uses

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

BoltClient is a StorageClient implementation for bbolt (formerly known as Bolt / Bolt DB).

func NewBoltClient Uses

func NewBoltClient(boltOptions BoltOptions) (BoltClient, error)

NewBoltClient creates a new BoltClient. Note: Bolt uses an exclusive write lock on the database file so it cannot be shared by multiple processes. For preventing clients from cheating (reusing preimages across different endpoints / middlewares that use different Bolt DB files) and for the previous mentioned reason you should use only one BoltClient. For example:

// ...
storageClient, err := storage.NewBoltClient(storage.DefaultBoltOptions) // Uses file "ln-paywall.db"
if err != nil {
    panic(err)
}
cheapPaywall := wall.NewGinMiddleware(cheapInvoiceOptions, lnClient, storageClient)
expensivePaywall := wall.NewGinMiddleware(expensiveInvoiceOptions, lnClient, storageClient)
router.GET("/ping", cheapPaywall, pingHandler)
router.GET("/compute", expensivePaywall, computeHandler)
// ...

If you want to start an additional web service, this would be an additional process, so you can't use the same DB file. You should look into the other storage options in this case, for example Redis.

Don't worry about closing the Bolt DB, the middleware opens it once and uses it for the duration of its lifetime. When the web service is stopped, the DB file lock is released automatically.

func (BoltClient) Get Uses

func (c BoltClient) Get(k string, v interface{}) (bool, error)

Get retrieves the stored object for the given key and populates the fields of the object that v points to with the values of the retrieved object's values.

func (BoltClient) Set Uses

func (c BoltClient) Set(k string, v interface{}) error

Set stores the given object for the given key.

type BoltOptions Uses

type BoltOptions struct {
    // Path of the DB file.
    // Optional ("ln-paywall.db" by default).
    Path string
}

BoltOptions are the options for the BoltClient.

type GoMap Uses

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

GoMap is a StorageClient implementation for a simple Go sync.Map.

func NewGoMap Uses

func NewGoMap() GoMap

NewGoMap creates a new GoMap.

func (GoMap) Get Uses

func (m GoMap) Get(k string, v interface{}) (bool, error)

Get retrieves the stored object for the given key and populates the fields of the object that v points to with the values of the retrieved object's values.

func (GoMap) Set Uses

func (m GoMap) Set(k string, v interface{}) error

Set stores the given object for the given key.

type RedisClient Uses

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

RedisClient is a StorageClient implementation for Redis.

func NewRedisClient Uses

func NewRedisClient(redisOptions RedisOptions) RedisClient

NewRedisClient creates a new RedisClient.

func (RedisClient) Get Uses

func (c RedisClient) Get(k string, v interface{}) (bool, error)

Get retrieves the object for the given key and points the passed pointer to it.

func (RedisClient) Set Uses

func (c RedisClient) Set(k string, v interface{}) error

Set stores the given object for the given key.

type RedisOptions Uses

type RedisOptions struct {
    // Address of the Redis server, including the port.
    // Optional ("localhost:6379" by default).
    Address string
    // Password for the Redis server.
    // Optional ("" by default).
    Password string
    // DB to use.
    // Optional (0 by default).
    DB  int
}

RedisOptions are the options for the Redis DB.

Package storage imports 4 packages (graph). Updated 2018-10-24. Refresh now. Tools for package owners.