Documentation ¶
Overview ¶
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 ¶
Constants ¶
This section is empty.
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
Functions ¶
This section is empty.
Types ¶
type BoltClient ¶
type BoltClient struct {
// contains filtered or unexported fields
}
BoltClient is a StorageClient implementation for bbolt (formerly known as Bolt / Bolt DB).
func NewBoltClient ¶
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (c BoltClient) Set(k string, v interface{}) error
Set stores the given object for the given key.
type BoltOptions ¶
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 ¶
type GoMap struct {
// contains filtered or unexported fields
}
GoMap is a StorageClient implementation for a simple Go sync.Map.
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
RedisClient is a StorageClient implementation for Redis.
func NewRedisClient ¶
func NewRedisClient(redisOptions RedisOptions) RedisClient
NewRedisClient creates a new RedisClient.
func (RedisClient) Get ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (c RedisClient) Set(k string, v interface{}) error
Set stores the given object for the given key.
type RedisOptions ¶
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.