Create stubs and limit page size
This commit is contained in:
15
storage/account.go
Normal file
15
storage/account.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package storage
|
||||
|
||||
import "errors"
|
||||
|
||||
type Account struct {
|
||||
ID string `json:"_id"`
|
||||
}
|
||||
|
||||
func (s *Storage) Accounts(token string) ([]Account, error) {
|
||||
return nil, errors.New("not impl")
|
||||
}
|
||||
|
||||
func (s *Storage) PrimaryAccounts(token string) ([]Account, error) {
|
||||
return nil, errors.New("not impl")
|
||||
}
|
||||
17
storage/balance.go
Normal file
17
storage/balance.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package storage
|
||||
|
||||
import "errors"
|
||||
|
||||
type Balance struct {
|
||||
ID string `json:"id"`
|
||||
At int64 `json:"at"`
|
||||
Is float32 `json:"is"`
|
||||
}
|
||||
|
||||
func (s *Storage) CurrentBalances(accounts ...Account) ([]Balance, error) {
|
||||
return nil, errors.New("not impl")
|
||||
}
|
||||
|
||||
func (s *Storage) BalancesOverTime(from, to int64, accounts ...Account) ([]Balance, error) {
|
||||
return nil, errors.New("not impl")
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
type Mongo struct {
|
||||
client *mongo.Client
|
||||
ns string
|
||||
page int
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -44,7 +45,7 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
func NewMongo(ns, addr string) (*Mongo, error) {
|
||||
func NewMongo(page int, ns, addr string) (*Mongo, error) {
|
||||
ctx, can := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer can()
|
||||
|
||||
@@ -82,7 +83,7 @@ func (m *Mongo) Find(c *mongo.Collection, where interface{}, next func() interfa
|
||||
ctx, can := context.WithCancel(context.TODO())
|
||||
defer can()
|
||||
|
||||
cur, err := c.Find(ctx, where, options.Find())
|
||||
cur, err := c.Find(ctx, where, options.Find().SetLimit(int64(m.page)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func testMongoNew(t *testing.T) *Mongo {
|
||||
b := make([]byte, 5)
|
||||
rand.Read(b)
|
||||
m, err := NewMongo(base64.URLEncoding.EncodeToString(b), "mongodb://localhost:27017")
|
||||
m, err := NewMongo(10, base64.URLEncoding.EncodeToString(b), "mongodb://localhost:27017")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type Storage struct {
|
||||
}
|
||||
|
||||
func New() (*Storage, error) {
|
||||
mongo, err := NewMongo(config.StoreNS, fmt.Sprintf("mongodb://%s", strings.TrimPrefix(config.StoreAddr, "mongodb://")))
|
||||
mongo, err := NewMongo(config.Page, config.StoreNS, fmt.Sprintf("mongodb://%s", strings.TrimPrefix(config.StoreAddr, "mongodb://")))
|
||||
return &Storage{
|
||||
mongo: mongo,
|
||||
}, err
|
||||
|
||||
15
storage/transaction.go
Normal file
15
storage/transaction.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package storage
|
||||
|
||||
import "errors"
|
||||
|
||||
type Transaction struct {
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Category string `json:"category"`
|
||||
Amount float32 `json:"amount"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
func (s *Storage) Transactions(from, to int64, accounts ...Account) ([]Transaction, error) {
|
||||
return nil, errors.New("not impl")
|
||||
}
|
||||
Reference in New Issue
Block a user