Create stubs and limit page size
parent
eec859ed48
commit
117ad922e2
|
|
@ -12,6 +12,7 @@ var (
|
||||||
Public string
|
Public string
|
||||||
StoreAddr string
|
StoreAddr string
|
||||||
StoreNS string
|
StoreNS string
|
||||||
|
Page int
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -24,6 +25,7 @@ func New() {
|
||||||
}
|
}
|
||||||
as := args.NewArgSet()
|
as := args.NewArgSet()
|
||||||
as.Append(args.INT, "p", "port to listen on", 52222)
|
as.Append(args.INT, "p", "port to listen on", 52222)
|
||||||
|
as.Append(args.INT, "page", "page size for requests", 20)
|
||||||
as.Append(args.STRING, "d", "dir with public files", "./public")
|
as.Append(args.STRING, "d", "dir with public files", "./public")
|
||||||
as.Append(args.STRING, "s", "mongodb address", "localhost:27017")
|
as.Append(args.STRING, "s", "mongodb address", "localhost:27017")
|
||||||
as.Append(args.STRING, "ns", "mongodb database", "cheqbooq")
|
as.Append(args.STRING, "ns", "mongodb database", "cheqbooq")
|
||||||
|
|
@ -31,6 +33,7 @@ func New() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
Port = fmt.Sprintf(":%d", as.GetInt("p"))
|
Port = fmt.Sprintf(":%d", as.GetInt("p"))
|
||||||
|
Page = as.GetInt("page")
|
||||||
Public = as.GetString("d")
|
Public = as.GetString("d")
|
||||||
StoreAddr = as.GetString("s")
|
StoreAddr = as.GetString("s")
|
||||||
StoreNS = as.GetString("ns")
|
StoreNS = as.GetString("ns")
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ package transaction
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
Account string `json:"account"`
|
From string `json:"from"`
|
||||||
|
To string `json:"to"`
|
||||||
|
Category string `json:"category"`
|
||||||
Amount float32 `json:"amount"`
|
Amount float32 `json:"amount"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
Meta json.RawMessage `json:"meta"`
|
Meta json.RawMessage `json:"meta"`
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
}
|
||||||
|
|
@ -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 {
|
type Mongo struct {
|
||||||
client *mongo.Client
|
client *mongo.Client
|
||||||
ns string
|
ns string
|
||||||
|
page int
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
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)
|
ctx, can := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
|
|
@ -82,7 +83,7 @@ func (m *Mongo) Find(c *mongo.Collection, where interface{}, next func() interfa
|
||||||
ctx, can := context.WithCancel(context.TODO())
|
ctx, can := context.WithCancel(context.TODO())
|
||||||
defer can()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func testMongoNew(t *testing.T) *Mongo {
|
func testMongoNew(t *testing.T) *Mongo {
|
||||||
b := make([]byte, 5)
|
b := make([]byte, 5)
|
||||||
rand.Read(b)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ type Storage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Storage, error) {
|
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{
|
return &Storage{
|
||||||
mongo: mongo,
|
mongo: mongo,
|
||||||
}, err
|
}, err
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue