Problem: hubBackend database is dependent on memoryBackend
Solution: remove the dependency between on the database in memoryBackend
This commit is contained in:
parent
edb816f35b
commit
5d5ee63d68
|
@ -59,7 +59,12 @@ func NewApp(options AppOptions) (*App, error) {
|
||||||
app.backend.hubIncomingBackend.baseURL = options.BaseURL
|
app.backend.hubIncomingBackend.baseURL = options.BaseURL
|
||||||
app.backend.hubIncomingBackend.backend = app.backend
|
app.backend.hubIncomingBackend.backend = app.backend
|
||||||
|
|
||||||
app.hubBackend = &hubIncomingBackend{backend: app.backend, baseURL: options.BaseURL, pool: options.pool}
|
app.hubBackend = &hubIncomingBackend{
|
||||||
|
backend: app.backend,
|
||||||
|
baseURL: options.BaseURL,
|
||||||
|
pool: options.pool,
|
||||||
|
database: options.database,
|
||||||
|
}
|
||||||
app.backend.hubIncomingBackend = *app.hubBackend
|
app.backend.hubIncomingBackend = *app.hubBackend
|
||||||
|
|
||||||
http.Handle("/micropub", µpubHandler{
|
http.Handle("/micropub", µpubHandler{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -28,9 +29,10 @@ type HubBackend interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type hubIncomingBackend struct {
|
type hubIncomingBackend struct {
|
||||||
backend *memoryBackend
|
backend *memoryBackend
|
||||||
baseURL string
|
baseURL string
|
||||||
pool *redis.Pool
|
pool *redis.Pool
|
||||||
|
database *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feed contains information about the feed subscriptions
|
// Feed contains information about the feed subscriptions
|
||||||
|
@ -53,7 +55,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hubIncomingBackend) GetSecret(id int64) string {
|
func (h *hubIncomingBackend) GetSecret(id int64) string {
|
||||||
db := h.backend.database
|
db := h.database
|
||||||
var secret string
|
var secret string
|
||||||
err := db.QueryRow(
|
err := db.QueryRow(
|
||||||
`select "subscription_secret" from "subscriptions" where "id" = $1`,
|
`select "subscription_secret" from "subscriptions" where "id" = $1`,
|
||||||
|
@ -67,7 +69,7 @@ func (h *hubIncomingBackend) GetSecret(id int64) string {
|
||||||
|
|
||||||
func (h *hubIncomingBackend) CreateFeed(topic string) (int64, error) {
|
func (h *hubIncomingBackend) CreateFeed(topic string) (int64, error) {
|
||||||
log.Println("CreateFeed", topic)
|
log.Println("CreateFeed", topic)
|
||||||
db := h.backend.database
|
db := h.database
|
||||||
|
|
||||||
secret := util.RandStringBytes(32)
|
secret := util.RandStringBytes(32)
|
||||||
urlSecret := util.RandStringBytes(32)
|
urlSecret := util.RandStringBytes(32)
|
||||||
|
@ -115,7 +117,7 @@ VALUES ($1, $2, $3, $4, DEFAULT) RETURNING "id"`, topic, secret, urlSecret, 60*6
|
||||||
func (h *hubIncomingBackend) UpdateFeed(subscriptionID int64, contentType string, body io.Reader) error {
|
func (h *hubIncomingBackend) UpdateFeed(subscriptionID int64, contentType string, body io.Reader) error {
|
||||||
log.Println("UpdateFeed", subscriptionID)
|
log.Println("UpdateFeed", subscriptionID)
|
||||||
|
|
||||||
db := h.backend.database
|
db := h.database
|
||||||
var (
|
var (
|
||||||
topic string
|
topic string
|
||||||
channel string
|
channel string
|
||||||
|
@ -149,7 +151,7 @@ func (h *hubIncomingBackend) UpdateFeed(subscriptionID int64, contentType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hubIncomingBackend) FeedSetLeaseSeconds(subscriptionID int64, leaseSeconds int64) error {
|
func (h *hubIncomingBackend) FeedSetLeaseSeconds(subscriptionID int64, leaseSeconds int64) error {
|
||||||
db := h.backend.database
|
db := h.database
|
||||||
_, err := db.Exec(`
|
_, err := db.Exec(`
|
||||||
update subscriptions
|
update subscriptions
|
||||||
set lease_seconds = $1,
|
set lease_seconds = $1,
|
||||||
|
@ -161,7 +163,7 @@ where id = $3
|
||||||
|
|
||||||
// Feeds returns a list of subscribed feeds
|
// Feeds returns a list of subscribed feeds
|
||||||
func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
|
func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
|
||||||
db := h.backend.database
|
db := h.database
|
||||||
var feeds []Feed
|
var feeds []Feed
|
||||||
|
|
||||||
rows, err := db.Query(`
|
rows, err := db.Query(`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user