Documentation ¶
Index ¶
- Variables
- func NewEchoMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, ...) echo.MiddlewareFunc
- func NewGinMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, ...) gin.HandlerFunc
- func NewHandlerFuncMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, ...) func(http.HandlerFunc) http.HandlerFunc
- func NewHandlerMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, ...) func(http.Handler) http.Handler
- type BoltClient
- type BoltOptions
- type GoMap
- type InvoiceOptions
- type LNDoptions
- type LNclient
- type RedisClient
- type RedisOptions
- type StorageClient
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 DefaultInvoiceOptions = InvoiceOptions{
Price: 1,
Memo: "API call",
}
DefaultInvoiceOptions provides default values for InvoiceOptions.
var DefaultLNDoptions = LNDoptions{
Address: "localhost:10009",
CertFile: "tls.cert",
MacaroonFile: "invoice.macaroon",
}
DefaultLNDoptions provides default values for LNDoptions.
var DefaultRedisOptions = RedisOptions{
Address: "localhost:6379",
}
DefaultRedisOptions is a RedisOptions object with default values. Address: "localhost:6379", Password: "", DB: 0
Functions ¶
func NewEchoMiddleware ¶ added in v0.3.0
func NewEchoMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient, skipper middleware.Skipper) echo.MiddlewareFunc
NewEchoMiddleware returns an Echo middleware in the form of an echo.MiddlewareFunc.
func NewGinMiddleware ¶
func NewGinMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) gin.HandlerFunc
NewGinMiddleware returns a Gin middleware in the form of a gin.HandlerFunc.
func NewHandlerFuncMiddleware ¶
func NewHandlerFuncMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) func(http.HandlerFunc) http.HandlerFunc
NewHandlerFuncMiddleware returns a function which you can use within an http.HandlerFunc chain.
func NewHandlerMiddleware ¶
func NewHandlerMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) func(http.Handler) http.Handler
NewHandlerMiddleware returns a function which you can use within an http.Handler chain.
Types ¶
type BoltClient ¶ added in v0.3.0
type BoltClient struct {
// contains filtered or unexported fields
}
BoltClient is a StorageClient implementation for bbolt (formerly known as Bolt / Bolt DB).
func NewBoltClient ¶ added in v0.3.0
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. This shouldn't be a problem when you use one file for one middleware, like this:
// ... boltClient, err := pay.NewBoltClient(pay.DefaultBoltOptions) // Uses file "ln-paywall.db" if err != nil { panic(err) } defer boltClient.Close() r.Use(pay.NewGinMiddleware(invoiceOptions, lndOptions, boltClient)) // ...
Also 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) SetUsed ¶ added in v0.3.0
func (c BoltClient) SetUsed(preimage string) error
SetUsed stores the information that a preimage has been used for a payment.
type BoltOptions ¶ added in v0.3.0
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 ¶ added in v0.2.0
type GoMap struct {
// contains filtered or unexported fields
}
GoMap is a StorageClient implementation for a simple Go sync.Map.
type InvoiceOptions ¶
type InvoiceOptions struct { // Amount of Satoshis you want to have paid for one API call. // Values below 1 are automatically changed to the default value. // Optional (1 by default). Price int64 // Note to be shown on the invoice, // for example: "API call to api.example.com". // Optional ("" by default). Memo string }
InvoiceOptions are the options for an invoice.
type LNDoptions ¶
type LNDoptions struct { // Address of your LND node, including the port. // Optional ("localhost:10009" by default). Address string // Path to the "tls.cert" file that your LND node uses. // Optional ("tls.cert" by default). CertFile string // Path to the "invoice.macaroon" file that your LND node uses. // Optional ("invoice.macaroon" by default). MacaroonFile string }
LNDoptions are the options for the connection to the lnd node.
type LNclient ¶ added in v0.3.0
type LNclient interface { GenerateInvoice(int64, string) (string, error) CheckInvoice(string) (bool, error) }
LNclient is an abstraction of a client that connects to a Lightning Network node implementation (like lnd, c-lightning and eclair) and provides the methods required by the paywall.
type RedisClient ¶ added in v0.2.0
type RedisClient struct {
// contains filtered or unexported fields
}
RedisClient is a StorageClient implementation for Redis.
func NewRedisClient ¶ added in v0.2.0
func NewRedisClient(redisOptions RedisOptions) RedisClient
NewRedisClient creates a new RedisClient.
func (RedisClient) SetUsed ¶ added in v0.2.0
func (c RedisClient) SetUsed(preimage string) error
SetUsed stores the information that a preimage has been used for a payment.
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.
type StorageClient ¶ added in v0.2.0
StorageClient is an abstraction for different storage client implementations. A storage client must only be able to check if a preimage was already used for a payment bofore and to store a preimage that was used before.