mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-26 01:34:46 -07:00
Make the batter driver follow the updated storage interface
This commit is contained in:
1
main.go
1
main.go
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/pushrax/chihaya/server"
|
"github.com/pushrax/chihaya/server"
|
||||||
|
|
||||||
_ "github.com/pushrax/chihaya/cache/redis"
|
_ "github.com/pushrax/chihaya/cache/redis"
|
||||||
|
_ "github.com/pushrax/chihaya/storage/batter"
|
||||||
_ "github.com/pushrax/chihaya/storage/gazelle"
|
_ "github.com/pushrax/chihaya/storage/gazelle"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/pushrax/chihaya/config"
|
"github.com/pushrax/chihaya/config"
|
||||||
|
|
||||||
_ "github.com/pushrax/chihaya/cache/redis"
|
_ "github.com/pushrax/chihaya/cache/redis"
|
||||||
_ "github.com/pushrax/chihaya/storage/gazelle"
|
_ "github.com/pushrax/chihaya/storage/batter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestServer() (*Server, error) {
|
func newTestServer() (*Server, error) {
|
||||||
|
|||||||
57
storage/batter/batter.go
Normal file
57
storage/batter/batter.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2013 The Chihaya Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the BSD 2-Clause license,
|
||||||
|
// which can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package batter provides a driver for a BitTorrent tracker to interface
|
||||||
|
// with the postgres database used by batter (github.com/wafflesfm/batter).
|
||||||
|
package batter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pushrax/chihaya/config"
|
||||||
|
"github.com/pushrax/chihaya/models"
|
||||||
|
"github.com/pushrax/chihaya/storage"
|
||||||
|
|
||||||
|
_ "github.com/bmizerany/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
type driver struct{}
|
||||||
|
|
||||||
|
func (d *driver) New(conf *config.DataStore) storage.Conn {
|
||||||
|
dsn := fmt.Sprintf(
|
||||||
|
"host=%s user=%s password=%s dbname=%s",
|
||||||
|
conf.Host,
|
||||||
|
conf.Port,
|
||||||
|
conf.Username,
|
||||||
|
conf.Password,
|
||||||
|
conf.Schema,
|
||||||
|
)
|
||||||
|
db, err := sql.Open("postgres", dsn)
|
||||||
|
if err != nil {
|
||||||
|
panic("batter: failed to open connection to postgres")
|
||||||
|
}
|
||||||
|
|
||||||
|
if conf.MaxIdleConns != 0 {
|
||||||
|
db.SetMaxIdleConns(conf.MaxIdleConns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Conn{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Conn struct {
|
||||||
|
*sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conn) Start() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
storage.Register("batter", &driver{})
|
||||||
|
}
|
||||||
@@ -33,7 +33,10 @@ func (d *driver) New(conf *config.DataStore) storage.Conn {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("gazelle: failed to open connection to MySQL")
|
panic("gazelle: failed to open connection to MySQL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.MaxIdleConns != 0 {
|
||||||
db.SetMaxIdleConns(conf.MaxIdleConns)
|
db.SetMaxIdleConns(conf.MaxIdleConns)
|
||||||
|
}
|
||||||
|
|
||||||
conn := &Conn{DB: db}
|
conn := &Conn{DB: db}
|
||||||
|
|
||||||
@@ -92,10 +95,6 @@ func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) RecordSnatch(peer *models.Peer) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
storage.Register("gazelle", &driver{})
|
storage.Register("gazelle", &driver{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,5 +52,4 @@ type Conn interface {
|
|||||||
Start() error
|
Start() error
|
||||||
Close() error
|
Close() error
|
||||||
RecordAnnounce(delta *models.AnnounceDelta) error
|
RecordAnnounce(delta *models.AnnounceDelta) error
|
||||||
RecordSnatch(peer *models.Peer) error
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user