mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-25 09:14:48 -07:00
stats test, add/remove torrent handlers, init batter driver
This commit is contained in:
52
storage/batter/batter.go
Normal file
52
storage/batter/batter.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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")
|
||||
}
|
||||
return &Conn{db}
|
||||
}
|
||||
|
||||
type Conn struct {
|
||||
*sql.DB
|
||||
}
|
||||
|
||||
func (c *Conn) UpdateTorrents(t []models.Torrent) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) UpdateUsers(u []models.User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
storage.Register("batter", &driver{})
|
||||
}
|
||||
Reference in New Issue
Block a user